安装openOffice.org
我安装的是3.3成功
package com.chinacreator.test; import java.io.File; import java.net.ConnectException; import java.util.Date; import com.artofsolving.jodconverter.DocumentConverter; import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.List; public class JOD4DocToPDF { public void docToPdf(File inputFile, File outputFile){ Date start = new Date(); // connect to an OpenOffice.org instance running on port 8100 OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); try{ connection.connect(); // convert DocumentConverter converter = new OpenOfficeDocumentConverter(connection); converter.convert(inputFile, outputFile); }catch(ConnectException cex){ cex.printStackTrace(); }finally{ // close the connection if(connection!=null){ connection.disconnect(); connection = null; } } long l = (start.getTime()- new Date().getTime()); long day=l/(24*60*60*1000); long hour=(l/(60*60*1000)-day*24); long min=((l/(60*1000))-day*24*60-hour*60); long s=(l/1000-day*24*60*60-hour*60*60-min*60); System.out.println("生成"+outputFile.getName()+"耗费:"+min+"分"+s+"秒"); } class TestThread extends java.lang.Thread{ public File inputFile; public File outputFile; public void run(){ JOD4DocToPDF t = new JOD4DocToPDF(); t.docToPdf(inputFile, outputFile); System.out.println(outputFile.getName()+"文件已生成"); } } public void test(String path,String st){ TestThread t1 = new TestThread(); t1.inputFile = new File(path+st+".doc"); // t1.inputFile = new File(path+st+".xls"); t1.outputFile = new File(path+st+".pdf"); // // TestThread t2 = new TestThread(); // t2.inputFile = new File("d:/document2.doc"); // t2.outputFile = new File("d:/document2.pdf"); // // TestThread t3 = new TestThread(); // t3.inputFile = new File("d:/document3.doc"); // t3.outputFile = new File("d:/document3.pdf"); // t2.start(); t1.start(); // t3.start(); } public static void main(String[] args) throws Exception{ String Path="D:\\";//转换的文件路径 String str="中国2s";//转换的文件名称 try{ JOD4DocToPDF p = new JOD4DocToPDF(); //生成pdf p.test(Path,str); }catch(Exception ex) { System.out.println("error"); } System.out.println("success"); } }
补充一下 :
基本上任何文档OpenOffice 都可以打开。 支持了XML、微软的doc、Excel、ppt文件等格式。
在openoffice 打开后,可以导出为 PDF ,利用这点可以基本实现 lz的要求
1、安装OpenOffice 3
2、用以下命令启动OpenOffice服务
cd C:\Program Files\OpenOffice.org 3\program
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
补充一下 :
基本上任何文档OpenOffice 都可以打开。 支持了XML、微软的doc、Excel、ppt文件等格式。 在openoffice 打开后,可以导出为 PDF ,利用这点可以基本实现 lz的要求 1、安装OpenOffice 3 2、用以下命令启动OpenOffice服务 cd C:\Program Files\OpenOffice.org 3\program soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard |
补充一下 :
基本上任何文档OpenOffice 都可以打开。 支持了XML、微软的doc、Excel、ppt文件等格式。 在openoffice 打开后,可以导出为 PDF ,利用这点可以基本实现 lz的要求 1、安装OpenOffice 3 2、用以下命令启动OpenOffice服务 cd C:\Program Files\OpenOffice.org 3\program soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard |