今天给我的转换服务器更新openoffice版本的时候·也顺便搜索了下jodconverter的版本·在官网上目前还是 2.2.2 版本·但是在 google 的时候发现了 code 上 有 3.0的版本·就立刻下载下来在虚拟机器上做测试,测试后发现 3.0版本 的 jodconverter 做的很不错·支持了服务器多进程,也就说明可以多线程转换了,避免了转换排队现象。
1.下载安装 openoffice 3.2,我的环境是ubuntu所以下载的是deb包,如果你是centos请下载rpm包。
ppt2pdf $> wget http://download.services.openoffice.org/files/localized/zh-CN/3.2.1/OOo_3.2.1_Linux_x86_install-deb_zh-CN.tar.gz ppt2pdf $> tar zxvf OOo_3.2.1_Linux_x86_install-deb_zh-CN.tar.gz ppt2pdf $> cd OOO320_m18_native_packed-1_zh-CN.9502 ppt2pdf $> cd DEBS ppt2pdf $> dpkg -i *.deb
2.然后下载中文字库防止乱码
ppt2pdf $> apt-get install language-pack-zh language-support-fonts-zh
3.下载jodconverter-core-3.0-beta-3-dist.zip(此步骤可滤过次步骤只是测试转换是否成功)
ppt2pdf $> wget http://jodconverter.googlecode.com/files/jodconverter-core-3.0-beta-3-dist.zip ppt2pdf $> unzip jodconverter-core-3.0-beta-3-dist.zip #然后用winscp 上传一个 ppt上来转换· ppt2pdf $> ls daodan.ppt jodconverter-core-3.0-beta-3 ppt2pdf $> java -jar jodconverter-core-3.0-SNAPSHOT/lib/jodconverter-core-3.0-SNAPSHOT.jar daodan.ppt 1.pdf Dec 29, 2010 4:39:29 PM org.artofsolving.jodconverter.office.ProcessPoolOfficeManager INFO: ProcessManager implementation is UnixProcessManager Dec 29, 2010 4:39:29 PM org.artofsolving.jodconverter.office.OfficeProcess start INFO: starting process with acceptString 'socket,host=127.0.0.1,port=2002,tcpNoDelay=1' and profileDir '/tmp/.jodconverter_socket_host-127.0.0.1_port-2002' Dec 29, 2010 4:39:30 PM org.artofsolving.jodconverter.office.OfficeProcess start INFO: started process; pid = 7108 Dec 29, 2010 4:39:30 PM org.artofsolving.jodconverter.office.OfficeConnection connect INFO: connected: 'socket,host=127.0.0.1,port=2002,tcpNoDelay=1' Dec 29, 2010 4:39:45 PM org.artofsolving.jodconverter.office.ProcessPoolOfficeManager stop INFO: stopping Dec 29, 2010 4:39:45 PM org.artofsolving.jodconverter.office.OfficeConnection$1 disposing INFO: disconnected: 'socket,host=127.0.0.1,port=2002,tcpNoDelay=1' Dec 29, 2010 4:39:45 PM org.artofsolving.jodconverter.office.ManagedOfficeProcess doEnsureProcessExited INFO: process exited with code 0 Dec 29, 2010 4:39:45 PM org.artofsolving.jodconverter.office.ProcessPoolOfficeManager stop INFO: stopped ppt2pdf $> ls 1.pdf daodan.ppt jodconverter-core-3.0-beta-3
#可以用winscp 下载下来查看。
4.下载 jodconverter-tomcat-2.2.2.zip 和 jodconverter-sample-webapp
ppt2pdf $> wget 'http://downloads.sourceforge.net/project/jodconverter/JODConverter/2.2.2/jodconverter-tomcat-2.2.2.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fjodconverter%2Ffiles%2FJODConverter%2F2.2.2%2F&ts=1293612042&use_mirror=nchc' ppt2pdf $> svn checkout http://jodconverter.googlecode.com/svn/trunk/jodconverter-sample-webapp jodconverter-sample-webapp 解压 jodconverter-tomcat-2.2.2.zip ppt2pdf $> unzip jodconverter-tomcat-2.2.2.zip #删除 2.2.2版本里的web应用程序 ppt2pdf $> rm jodconverter-tomcat-2.2.2/webapps/converter/* -rf #编译jodconverter-sample-webapp ppt2pdf $> cd jodconverter-sample-webapp/ ppt2pdf $> mvn package #复制编译出来的 web应用程序进 jodconverter-tomcat-2.2.2 ppt2pdf $> cd target/jodconverter-sample-webapp-3.0-SNAPSHOT ppt2pdf $> cp WEB-INF documentFormats.js index.jsp ../jodconverter-tomcat-2.2.2/webapps/converter/ -R
5.启动服务
ppt2pdf $> cd jodconverter-tomcat-2.2.2 ppt2pdf $> bin/startup.sh Using CATALINA_BASE: /root/jodconverter-tomcat-2.2.2 Using CATALINA_HOME: /root/jodconverter-tomcat-2.2.2 Using CATALINA_TMPDIR: /root/jodconverter-tomcat-2.2.2/temp Using JRE_HOME: /usr
6.安装 apache php php-pear
#我就用懒人模式安装了·apt-get
ppt2pdf $> apt-get install apache2 php5 php-pear
# 安装 pear 的 Net_URL2
ppt2pdf $> pear install Net_URL2-0.3.1 # 下载安装 HTTP_Request2 ppt2pdf $> wget http://download.pear.php.net/package/HTTP_Request2-0.5.2.tgz ppt2pdf $> tar zxvf HTTP_Request2-0.5.2.tgz ppt2pdf $> cd HTTP_Request2-0.5.2 ppt2pdf $> cp Request2.php /usr/share/php/HTTP/ ppt2pdf $> cp Request2 /usr/share/php/HTTP/ -R
7.创建一个convert.php转换 ppt2pdf 的例子
#打开浏览查看交互页面
#下面我们创建无交互php程序。
ppt2pdf $> cd /var/www ppt2pdf $> vim convert.php
< ?php require_once 'HTTP/Request2.php'; class DocumentConverterClient { var $url = 'http://localhost:8080/converter/converted/document.pdf'; function convert($inputFile, $outputType) { $request = new HTTP_Request2($this->url); $request->setMethod(HTTP_Request2::METHOD_POST) ->setHeader('Content-Type', 'multipart/form-data') ->addPostParameter('outputFormat', $outputType) ->setBody($inputData); $request->addUpload('inputDocument', $inputFile); return $request->send()->getBody(); } } $documentConverter = new DocumentConverterClient(); $inputFile = 'daodan.ppt'; # 要转换的 ppt|doc|pptx|docx $outputFile = 'daodan.pdf'; # 转出来的 pdf $outputType = 'pdf'; $outputData = $documentConverter->convert($inputFile, $outputType); file_put_contents($outputFile, $outputData); ?>
#把传进来的ppt 复制到 www 目录下,给 www 赋予 apache 可写权限
ppt2pdf $> cp ../daodan.ppt /var/www/ ppt2pdf $> chown www-data /var/www
8.打开浏览器测试。
#使用 winscp 下载 转好的 pdf 本地查看
PS:他的多线程,我还未测试,我是从编译的时候,发现可以多线程的,再我测试后,会发布。