openOffice+pdf2swf+flexpaper(類百度文庫) :office轉pdf(Linux,window)

來源:互聯網
上載者:User

安裝openOffice.org

我安裝的是3.3成功

Java代碼  
  1. package com.chinacreator.test;  
  2.   
  3. import java.io.File;  
  4. import java.net.ConnectException;  
  5. import java.util.Date;  
  6.   
  7. import com.artofsolving.jodconverter.DocumentConverter;  
  8. import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;  
  9. import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;  
  10. import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;  
  11. import java.io.BufferedReader;  
  12.   
  13. import java.io.IOException;  
  14. import java.io.InputStream;  
  15. import java.io.InputStreamReader;  
  16. import java.util.List;  
  17.   
  18.   
  19. public class JOD4DocToPDF {  
  20.       
  21.     public void docToPdf(File inputFile, File outputFile){  
  22.         Date start = new Date();  
  23.          // connect to an OpenOffice.org instance running on port 8100  
  24.         OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);  
  25.         try{  
  26.             connection.connect();  
  27.               
  28.              // convert  
  29.             DocumentConverter converter = new OpenOfficeDocumentConverter(connection);  
  30.             converter.convert(inputFile, outputFile);  
  31.         }catch(ConnectException cex){  
  32.             cex.printStackTrace();  
  33.         }finally{  
  34.             // close the connection  
  35.             if(connection!=null){  
  36.                 connection.disconnect();  
  37.                 connection = null;  
  38.             }  
  39.         }  
  40.         long l = (start.getTime()- new Date().getTime());  
  41.         long day=l/(24*60*60*1000);  
  42.            long hour=(l/(60*60*1000)-day*24);  
  43.            long min=((l/(60*1000))-day*24*60-hour*60);  
  44.            long s=(l/1000-day*24*60*60-hour*60*60-min*60);  
  45.            System.out.println("產生"+outputFile.getName()+"耗費:"+min+"分"+s+"秒");  
  46.     }  
  47.       
  48.     class TestThread extends java.lang.Thread{  
  49.         public File inputFile;  
  50.         public File outputFile;  
  51.           
  52.         public void run(){  
  53.             JOD4DocToPDF t = new JOD4DocToPDF();  
  54.             t.docToPdf(inputFile, outputFile);  
  55.             System.out.println(outputFile.getName()+"檔案已產生");  
  56.         }  
  57.     }  
  58.       
  59.     public void test(String path,String st){  
  60.         TestThread t1 = new TestThread();  
  61.         t1.inputFile = new File(path+st+".doc");  
  62. //      t1.inputFile = new File(path+st+".xls");  
  63.         t1.outputFile = new File(path+st+".pdf");  
  64.           
  65. //        
  66. //      TestThread t2 = new TestThread();  
  67. //      t2.inputFile = new File("d:/document2.doc");  
  68. //      t2.outputFile = new File("d:/document2.pdf");  
  69. //        
  70. //      TestThread t3 = new TestThread();  
  71. //      t3.inputFile = new File("d:/document3.doc");  
  72. //      t3.outputFile = new File("d:/document3.pdf");  
  73.           
  74.           
  75. //      t2.start();  
  76.         t1.start();  
  77. //      t3.start();  
  78.     }  
  79.       
  80.     public static void main(String[] args) throws Exception{  
  81.         String Path="D:\\";//轉換的檔案路徑  
  82.         String str="中國2s";//轉換的檔案名稱  
  83.         try{  
  84.             JOD4DocToPDF p = new JOD4DocToPDF(); //產生pdf  
  85.             p.test(Path,str);  
  86.         }catch(Exception ex)  
  87.         {  
  88.             System.out.println("error");  
  89.         }  
  90.           
  91.           
  92.         System.out.println("success");  
  93.       }  
  94.   
  95. }  

 補充一下 : 
 基本上任何文檔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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.