1.下載軟件包及依賴包
鏈接:https://pan.baidu.com/s/1CWxJngOxoi-G-tpUf5PPNg
提取碼:yeed
http://www.openoffice.org/download/
2.解壓
tar -zxvf Apache_OpenOffice_4.1.10_Linux_x86-64_install-rpm_zh-CN.tar.gz
3.安裝rpm
cd zh-CN/RPMS yum localinstall *.rpm
4.JDK安裝
將jdk包上傳至服務器解壓
tar -zxvf jdk-8u171-linux-x64.tar.gz
配置環境變量
vim /etc/profile # 以下為文件添加內容,添加到文件最后 JAVA_HOME=/opt/jdk1.8.0_171 export JAVA_HOME PATH=$JAVA_HOME/bin:$PATH export PATH # 加載環境變量 source /etc/profile # 驗證jdk java -version
5.安裝完成直接啟動Openoffice服務
默認安裝位置為/opt下
臨時啟動
/opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
殺掉openoffice進程
# 查看進程號 ps -ef | grep openoffice kill -9 進程號
6.查看服務是否啟動
netstat -nltp|grep 8100
7.安裝jodconverter
將jodconverter-2.2.2.zip上傳至服務器解壓
unzip jodconverter-2.2.2.zip
8.添加系統常用字體
在CentOS下面會缺少黑體和宋體的,直接找到windows下面的字體目錄把黑體、宋體等常見字體復制到目錄:/opt/openoffice4/share/fonts/truetype 重啟生效
win10系統字體路徑:C:\Windows\Fonts
SIMSUN.TTC宋體 SIMHEI.TTF黑體
cd /opt/openoffice4/share/fonts/truetype # 使用rz上傳或者將字體拖拽進來
9.測試
將test.doc上傳至服務器
使用命令將test.doc轉換為test.pdf后下載至桌面查看是否有亂碼,顯示正常為成功。
java -jar /opt/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar test.doc test.pdf sz test.pdf
10.常見報錯及處理方式
報錯1
/opt/openoffice4/program/soffice.bin: error while loading shared libraries: libXext.so.6: cannot open shared object file: No such file or directory
解決:如果出現這種情況,說明在/opt/openoffice4/program/下缺少libXext.so.6文件,可以去/usr/lib64 或者 /usr/lib 查看有沒有這個文件,如果有就copy到/opt/openoffice4/program/目錄里面,如果沒有再安裝
yum install libXext.x86_64
安裝完成后在那兩個目錄中找到復制到/opt/openoffice4/program/下,cp 復制命令
cp -a usr/lib64/libXext.so.6 /opt/openoffice4/program/
拷貝完成后再啟動openoffice服務
報錯2
/opt/openoffice4/program/soffice.bin: error while loading shared libraries: libfreetype.so.6: cannot open shared object file: No such file or directory
解決:同缺少libXext.so.6處理
報錯3
no suitable windowing system found, exiting
解決:
yum groupinstall "X Window System"
注意:
openoffice的啟動腳本不能追加在項目啟動腳本中,需要另行創建一份startup.sh腳本,如在項目后端目錄apps中創建一個openoffice目錄,用於存放一份startup.sh腳本,內容為
#/bin/sh nohup /opt/openoffice.org3/program/soffice.bin -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &