项目需要一个在线浏览文档的功能,于是参照网上的代码写了一份利用Microsoft Office 2010和swftools-2013-04-09-1007.exe(下载地址:http://www.swftools.org/download.html)转换的程序。
思路:调用电脑本机的office组件把ppt或者word转换为pdf文件,接着调用pdf2swf应用把pdf文件转换为swf。
但由于目前项目组没有windows的服务器,于是想着试试能不能搭一个在linux上能跑的程序。首先尝试过最新的OpenOffice4,程序虽然能跑,但是却仍然无法支持数学公式的转换,于是转而使用LibreOffice,完美地解决了问题,以下为记录linux环境下的配置过程。
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官网(https://www.libreoffice.org/download/libreoffice-fresh/)下载安装包LibreOffice_5.0.6_Linux_x86_deb.tar.gz并上传到ubuntu上,运行命令
tar -zxvf LibreOffice_5.0.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(http://www.swftools.org/download.html)下载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.2.tar.gz
cd swftools-0.9.2/
./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.7
export PATH=/opt/java/jdk1.7/bin
java -jar converter-0.0.1-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.运行启动脚本发现一直报错,内容如下:
11:17:21.828 [main] INFO o.l.c.impl.SWFToolsSWFConverter - converting /home/test/pptTest1.pdf to /home/test/pptTest1.swf
11:17:21.962 [main] INFO o.l.c.impl.SWFToolsSWFConverter - ERROR Couldn't open "/home/test/pptTest1.pdf"
11:17:21.963 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFileCC' (/usr/share/xpdf/xpdfrc-chinese-simplified:8)
11:17:21.963 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFileCC' (/usr/share/xpdf/xpdfrc-chinese-traditional:7)
11:17:21.963 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFileCC' (/usr/share/xpdf/xpdfrc-japanese:8)
11:17:21.963 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:9)
11:17:21.965 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:10)
11:17:21.965 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:11)
11:17:21.965 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:12)
11:17:21.965 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:13)
11:17:21.965 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:14)
11:17:21.965 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:15)
11:17:21.966 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:16)
11:17:21.967 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:17)
11:17:21.967 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:18)
11:17:21.967 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:19)
11:17:21.967 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:20)
11:17:21.974 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:21)
11:17:21.975 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:22)
11:17:21.981 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:23)
11:17:21.982 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:24)
11:17:21.982 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:25)
11:17:21.989 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:26)
11:17:21.990 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:27)
11:17:21.990 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:28)
11:17:21.991 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:29)
11:17:21.991 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:30)
11:17:21.991 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:31)
11:17:21.992 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:32)
11:17:21.992 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:33)
11:17:21.994 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:34)
11:17:21.997 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:35)
11:17:21.998 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFile' (/usr/share/xpdf/xpdfrc-japanese:36)
11:17:21.999 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFontCC' (/usr/share/xpdf/xpdfrc-japanese:38)
11:17:21.999 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFontCC' (/usr/share/xpdf/xpdfrc-japanese:39)
11:17:22.000 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:40)
11:17:22.000 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:41)
11:17:22.000 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:42)
11:17:22.005 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:43)
11:17:22.005 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:44)
11:17:22.006 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:45)
11:17:22.008 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:46)
11:17:22.017 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:47)
11:17:22.017 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:48)
11:17:22.018 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:49)
11:17:22.018 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:50)
11:17:22.021 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:51)
11:17:22.025 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:52)
11:17:22.037 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:53)
11:17:22.038 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:54)
11:17:22.038 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:55)
11:17:22.039 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:56)
11:17:22.040 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:57)
11:17:22.045 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:58)
11:17:22.045 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:59)
11:17:22.046 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:60)
11:17:22.046 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:61)
11:17:22.047 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:62)
11:17:22.047 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:63)
11:17:22.047 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:64)
11:17:22.048 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:65)
11:17:22.064 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:66)
11:17:22.064 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:67)
11:17:22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:68)
11:17:22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:69)
11:17:22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:70)
11:17:22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:71)
11:17:22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:72)
11:17:22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:73)
11:17:22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:74)
11:17:22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:75)
11:17:22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'psResidentFont16' (/usr/share/xpdf/xpdfrc-japanese:76)
11:17:22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFileCC' (/usr/share/xpdf/xpdfrc-korean:6)
11:17:22.069 [main] INFO o.l.c.impl.SWFToolsSWFConverter - Error: Unknown config file command 'fontFileCC' (/usr/share/xpdf/xpdfrc-korean:7)
未能找到完美的解决方案,暂时的解决方法是编辑相应文件并注释掉不能识别的命令,例如:
sudo vi /usr/share/xpdf/xpdfrc-chinese-simplified
#----- begin Chinese Simplified support package (2010-Apr-15)
cidToUnicode Adobe-GB1 /usr/share/poppler/cidToUnicode/Adobe-GB1
unicodeMap ISO-2022-CN /usr/share/poppler/unicodeMap/ISO-2022-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