原文地址:http://www.niu12.com/article/15php
$ sudo mv jdk-8u201-linux-x64.tar.gz /usr/local/ 解壓文件 $ sudo tar -zxvf /usr/local/jdk-8u201-linux-x64.tar.gz
$ sudo vim /etc/profile #在文件的最後添加以下內容 #Java Env export JAVA_HOME=/usr/local/jdk1.8.0_201 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin #生效環境變量 $ source /etc/profile #測試java環境 $ sudo java -version java version "1.8.0_201" Java(TM) SE Runtime Environment (build 1.8.0_201-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
$ sudo mv Apache_OpenOffice_4.1.6_Linux_x86-64_install-deb_zh-CN.tar.gz /usr/local/ #解壓文件 $ sudo tar -zxvf /usr/local/Apache_OpenOffice_4.1.6_Linux_x86-64_install-deb_zh-CN.tar.gz #這個時候會生成zh-CN文件 #重命名 $ sudo mv ./zh-CN/ ./openOffice
$ cd openOffice/DEBS/ $ sudo dpkg -i *.deb $ cd desktop-integration/ $ sudo dpkg -i openoffice4.1-debian-menus_4.1.6-9790_all.deb #這個時候openoffice安裝在/opt/openoffice4
$ cd /opt wget https://downloads.sourceforge.net/project/jodconverter/JODConverter/2.2.2/jodconverter-2.2.2.zip #解壓 $ unzip /opt/jodconverter-2.2.2.zip #進入目錄 cd /opt/jodconverter-2.2.2/lib
#進入jdk字體目錄 $ cd /usr/local/jdk1.8.0_201/jre/lib/fonts/ # 創建fallback目錄 $ mkdir fallback # 將中文字體msyh.ttf、msyhbd.ttf、simhei.ttf、simsun.ttc放到fallback目錄下 #將字體放到linux字體文件夾 $ cp /usr/local/jdk1.8.0_201/jre/lib/fonts/fallback/* /usr/share/fonts/ $ cp /usr/local/jdk1.8.0_201/jre/lib/fonts/* /usr/share/fonts/ #刷新字體緩存 fc-cache
$ soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
#將tmp目錄下的test.docx轉換成test.pdf $ sudo java -jar /opt/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar /tmp/test.docx /tmp/test.pdf
$ ps -ef|grep soffice $ kill -9 30415
#須要修改php.ini文件,由於使用了disable_function exec() #須要java的徹底路徑 <?php $command = "sudo /usr/local/jdk1.8.0_201/bin/java -jar /opt/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar /tmp/test.docx /tmp/test.pdf"; // $return_var返回值0或1,若是返回0則執行成功,返回1則執行失敗 exec($command, $output, $return_var); if ($return_var != 0) { throw new \Exception("生成PDF失敗"); }