安裝openOffice.org
我安裝的是3.3成功
Java代碼
- 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