项目需要一个在线浏览文档的功能,于是参照网上的代码写了一份利用Microsoft Office 2010和swftools-2013-04-09-1007.exe转换的程序
思路:调用电脑本机的office组件把ppt或者word转换为pdf文件,接着调用pdf2swf应用把pdf文件转换为swf。
参考:http://www.cnblogs.com/luckyxiaoxuan/archive/2012/06/15/2550303.html
但由于目前项目组没有windows的服务器,于是想着试试能不能搭一个在linux上能跑的程序。首先尝试过最新的OpenOffice4,程序虽然能跑,但是却仍然无法支持数学公式的转换,于是转而使用LibreOffice,完美地解决了问题,以下为记录linux环境下的配置过程。
参考:https://zh-cn.libreoffice.org/get-help/install-howto/linux/
https://help.ubuntu.com/community/SWFTools
http://www.jianshu.com/p/9d0ffad58fed
0 环境
Java: "1.7.0_79"
OS: ubuntu-15.10-server-i386.iso
libreoffice: LibreOffice_5.0.6.3_Linux_x86_deb
swftools:swftools-0.9.2.tar.gz
1. ubuntu安装libreoffice
从LibreOffice官网下载安装包LibreOffice_5.0.6_Linux_x86_deb.tar.gz并上传到ubuntu上,运行命令
tar -zxvf LibreOffice_5..6_Linux_x86_deb.tar.gz
sudo dpkg -i ./LibreOffice_5.0.6.3_Linux_x86_deb/DEBS/*.deb
最终的安装目录为 /opt/libreoffice5.0
2. ubuntu安装SWFTools
从swftools下载swftools-0.9.2.tar.gz并上传到ubuntu上,运行命令
sudo apt-get install g++
sudo apt-get install libgif-dev xpdf libfreetype6 libfreetype6-dev libjpeg62 libjpeg8 libjpeg8-dev
tar -zxvf swftools-0.9..tar.gz
cd swftools-0.9./
./configure
make
sudo make install
sudo apt-get install xpdf
3. 打包转换代码并上传
https://github.com/hivsuper/converter
4. 编写启动脚本
#! /bin/sh
export JAVA_HOME=/opt/java/jdk1.
export PATH=/opt/java/jdk1./bin
java -jar converter-0.0.-SNAPSHOT.jar
遇到的问题:
a. 安装swftools时遇到`./configure`命令运行报错,最终发现是由于没有安装g++导致
b. 由于服务器系统为server版,故默认无桌面,虽然程序在windows系统跑没有问题,但一直报错
org.artofsolving.jodconverter.office.OfficeException: could not establish connection
最后安装了桌面程序再次运行,问题解决
sudo apt-get install ubuntu-desktop
c. 运行启动脚本发现一直报错,内容如下:
::21.828 [main] INFO o.l.c.impl.SWFToolsSWFConverter - converting /home/test/pptTest1.pdf to /home/test/pptTest1.swf
::21.962 [main] INFO o.l.c.impl.SWFToolsSWFConverter - ERROR Couldn't open "/home/test/pptTest1.pdf"
::21.963 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFileCC' (/usr/share/xpdf/xpdfrc-chinese-simplified:)
::21.963 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFileCC' (/usr/share/xpdf/xpdfrc-chinese-traditional:)
::21.963 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFileCC' (/usr/share/xpdf/xpdfrc-japanese:)
::21.963 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.965 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.965 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.965 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.965 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.965 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.965 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.966 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.967 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.967 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.967 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.967 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.974 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.975 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.981 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.982 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.982 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.989 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.990 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.990 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.991 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.991 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.991 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.992 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.992 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.994 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.997 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.998 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:)
::21.999 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFontCC' (/usr/share/xpdf/xpdfrc-japanese:)
::21.999 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFontCC' (/usr/share/xpdf/xpdfrc-japanese:)
::22.000 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.000 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.000 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.005 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.005 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.006 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.008 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.017 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.017 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.018 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.018 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.021 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.025 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.037 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.038 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.038 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.039 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.040 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.045 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.045 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.046 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.046 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.047 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.047 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.047 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.048 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.064 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.064 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:)
::22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFileCC' (/usr/share/xpdf/xpdfrc-korean:)
::22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFileCC' (/usr/share/xpdf/xpdfrc-korean:)
未能找到完美的解决方案,暂时的解决方法是编辑相应文件并注释掉不能识别的命令,例如:
sudo vi /usr/share/xpdf/xpdfrc-chinese-simplified
#----- begin Chinese Simplified support package (-Apr-)
cidToUnicode Adobe-GB1 /usr/share/poppler/cidToUnicode/Adobe-GB1
unicodeMap ISO--CN /usr/share/poppler/unicodeMap/ISO--CN
unicodeMap EUC-CN /usr/share/poppler/unicodeMap/EUC-CN
unicodeMap GBK /usr/share/poppler/unicodeMap/GBK
cMapDir Adobe-GB1 /usr/share/poppler/cMap/Adobe-GB1
toUnicodeDir /usr/share/poppler/cMap/Adobe-GB1
#fontFileCC Adobe-GB1 /usr/share/fonts/truetype/wqy/wqy-zenhei.ttc
#----- end Chinese Simplified support package