openOffice+pdf2swf+flexpaper(类百度文库) :office转pdf(Linux,window)

安装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

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值