现在项目有个需求,要求把ms office和txt在线播放,偶当时就想到了布丁网 然后就问……google…… 结果google告诉偶,简单的办法在windows上是可以实现的,非常简单...不过

现在项目有个需求,要求把ms office和txt在线播放,偶当时就想到了 布丁网

然后就问……google……

结果google告诉偶,简单的办法在windows上是可以实现的,非常简单...不过要用到jacob,具体大家去问Google。
由于要调用dll,在linux上偶不清楚能不能用(公司搞服务器的人说不可以),结果就被pass了……


再然后……只有这么办了……
先用 openOffice把ppt、word、excel、txt转换成pdf,然后用 swftools转换成swf,然后在线播放。

具体说明如下(windows,在linux下偶正准备测试)
1、安装相关软件,这个偶就不说了……
2、下载 jodconverter,偶用的2.2.2...然后怎么把lib放在环境变量或者项目环境偶就不说了……
3、以cmd方式启动openoffice server
Java代码   收藏代码
  1. cd opeonofiice的安装路径/program  

Java代码   收藏代码
  1. soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard  

4、看看8100被监听没
Java代码   收藏代码
  1. netstat -an  

5、写代码了……偶没有把代码集成到项目中,所以是单独的例子,不过这样还好点,不然和项目偶和太厉害了
JOD4DocToPDF
Java代码   收藏代码
  1. /** 
  2.  *  
  3.  */  
  4. package com.born.sys.util.pdf;  
  5.   
  6. import java.io.File;  
  7. import java.net.ConnectException;  
  8. import java.util.Date;  
  9.   
  10. import com.artofsolving.jodconverter.DocumentConverter;  
  11. import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;  
  12. import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;  
  13. import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;  
  14.   
  15. /** 
  16.  * <ul> 
  17.  * <li>文件名称: com.born.sys.util.pdf.JOD4DocToPDF.java</li> 
  18.  * <li>文件描述:</li> 
  19.  * <li>版权所有: 版权所有(C)2001-2006</li> 
  20.  * <li>公 司: born</li> 
  21.  * <li>内容摘要:</li> 
  22.  * <li>其他说明:</li> 
  23.  * <li>完成日期:2010-5-21</li> 
  24.  * <li>修改记录0:无</li> 
  25.  * </ul> 
  26.  *  
  27.  * @version 1.0 
  28.  * @author 许力多 
  29.  */  
  30. public class JOD4DocToPDF extends java.lang.Thread {  
  31.     private File inputFile;// 需要转换的文件  
  32.     private File outputFile;// 输出的文件  
  33.   
  34.     public JOD4DocToPDF(File inputFile, File outputFile) {  
  35.         this.inputFile = inputFile;  
  36.         this.outputFile = outputFile;  
  37.     }  
  38.   
  39.     public void docToPdf() {  
  40.         Date start = new Date();  
  41.         // connect to an OpenOffice.org instance running on port 8100  
  42.         OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);  
  43.         try {  
  44.             connection.connect();  
  45.   
  46.             // convert  
  47.             DocumentConverter converter = new OpenOfficeDocumentConverter(  
  48.                     connection);  
  49.             converter.convert(inputFile, outputFile);  
  50.         } catch (ConnectException cex) {  
  51.             cex.printStackTrace();  
  52.         } finally {  
  53.             // close the connection  
  54.             if (connection != null) {  
  55.                 connection.disconnect();  
  56.                 connection = null;  
  57.             }  
  58.         }  
  59.         long l = (start.getTime() - new Date().getTime());  
  60.         long day = l / (24 * 60 * 60 * 1000);  
  61.         long hour = (l / (60 * 60 * 1000) - day * 24);  
  62.         long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);  
  63.         long s = (l / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);  
  64.         System.out.println("生成" + outputFile.getName() + "耗费:" + min + "分" + s  
  65.                 + "秒");  
  66.     }  
  67.   
  68.     /** 
  69.      * 由于服务是线程不安全的,所以……需要启动线程 
  70.      */  
  71.     public void run() {  
  72.         this.docToPdf();  
  73.   
  74.     }  
  75.   
  76.     public File getInputFile() {  
  77.         return inputFile;  
  78.     }  
  79.   
  80.     public void setInputFile(File inputFile) {  
  81.         this.inputFile = inputFile;  
  82.     }  
  83.   
  84.     public File getOutputFile() {  
  85.         return outputFile;  
  86.     }  
  87.   
  88.     public void setOutputFile(File outputFile) {  
  89.         this.outputFile = outputFile;  
  90.     }  
  91.   
  92.     /** 
  93.      * @param args 
  94.      */  
  95.     public static void main(String[] args) {  
  96.         JOD4DocToPDF tools = new JOD4DocToPDF(new File("d:/中文的ppt哦.ppt"),  
  97.                 new File("d:/被转换的pdf.pdf"));  
  98.         tools.start();  
  99.   
  100.     }  
  101.   
  102. }  

ps:其实还有很多属性的,不过偶图简单,直接用的官方例子,人懒无敌……阿门

通过Runtime来调用cmd,然后生成相关的播放文件,生成好的flash效果见 点击看效果
PdfToSwf
Java代码   收藏代码
  1. package com.born.sys.util.pdf;  
  2.   
  3. import java.io.BufferedReader;  
  4. import java.io.File;  
  5. import java.io.IOException;  
  6. import java.io.InputStreamReader;  
  7.   
  8. /** 
  9.  * <ul> 
  10.  * <li>文件名称: com.born.sys.util.pdf.PdfToSwf.java</li> 
  11.  * <li>文件描述: pdf生成swf</li> 
  12.  * <li>版权所有: 版权所有(C)2001-2006</li> 
  13.  * <li>公 司: born</li> 
  14.  * <li>内容摘要:</li> 
  15.  * <li>其他说明:</li> 
  16.  * <li>完成日期:2010-5-21</li> 
  17.  * <li>修改记录0:无</li> 
  18.  * </ul> 
  19.  *  
  20.  * @version 1.0 
  21.  * @author 许力多 
  22.  */  
  23. public class PdfToSwf {  
  24.     public int convertPDF2SWF(String sourcePath, String destPath,  
  25.             String fileName) throws IOException {  
  26.         // 目标路径不存在则建立目标路径  
  27.         File dest = new File(destPath);  
  28.         if (!dest.exists()) {  
  29.             dest.mkdirs();  
  30.         }  
  31.   
  32.         // 源文件不存在则返回  
  33.         File source = new File(sourcePath);  
  34.         if (!source.exists()) {  
  35.             return 0;  
  36.         }  
  37.   
  38.         // 调用pdf2swf命令进行转换  
  39.         // D:\tools\SWFTools>pdf2swf.exe -z -B rfxview.swf -s flashversion=9  
  40.         // d:/人员管理系  
  41.         // 统PersonalManagementSystem简介.pdf -o d:/test.swf  
  42.   
  43.         // 要把D:\\tools\\SWFTools\\放在path里面……不然使用不了播放器  
  44.   
  45.         // 先生成flash  
  46.         String[] envp = new String[1];  
  47.         envp[0] = "PATH=D:\\tools\\SWFTools\\";  
  48.         String command = "pdf2swf -z -s flashversion=9 \"" + sourcePath  
  49.                 + "\" -o \"" + destPath + fileName + "\"";  
  50.   
  51.         Process pro = Runtime.getRuntime().exec(command, envp);  
  52.         // System.out.println(command);  
  53.         BufferedReader bufferedReader = new BufferedReader(  
  54.                 new InputStreamReader(pro.getInputStream()));  
  55.         while (bufferedReader.readLine() != null) {  
  56.             String text = bufferedReader.readLine();  
  57.             System.out.println(text);  
  58.         }  
  59.         try {  
  60.             pro.waitFor();  
  61.         } catch (InterruptedException e) {  
  62.             // TODO Auto-generated catch block  
  63.             e.printStackTrace();  
  64.         }  
  65.         // 然后在套播放器  
  66.         /* 
  67.          * swfcombine -z -X 720 -Y 540 "D:\tools\SWFTools\swfs\rfxview.swf" 
  68.          * viewport="d:/人 
  69.          * 员管理系统PersonalManagementSystem简介.swf" -o "d:/人员管理系统PersonalManagemen 
  70.          * tSystem简介.swf" 
  71.          */  
  72.         command = "swfcombine -z -X 720 -Y 540 \"D:/tools/SWFTools/swfs/rfxview.swf\" viewport=\""  
  73.                 + destPath + fileName + "\" -o \"" + destPath + fileName + "\"";  
  74.         pro = Runtime.getRuntime().exec(command, envp);  
  75.         System.out.println(command);  
  76.         bufferedReader = new BufferedReader(new InputStreamReader(pro  
  77.                 .getInputStream()));  
  78.         while (bufferedReader.readLine() != null) {  
  79.             String text = bufferedReader.readLine();  
  80.             System.out.println(text);  
  81.         }  
  82.         try {  
  83.             pro.waitFor();  
  84.         } catch (InterruptedException e) {  
  85.             // TODO Auto-generated catch block  
  86.             e.printStackTrace();  
  87.         }  
  88.         return pro.exitValue();  
  89.   
  90.     }  
  91.   
  92.     public static void main(String[] args) {  
  93.         String sourcePath = "d:/PersonalManagementSystem.pdf";  
  94.         String destPath = "d:/";  
  95.         String fileName = "PersonalManagementSystem.swf";  
  96.         try {  
  97.             System.out.println(new PdfToSwf().convertPDF2SWF(sourcePath,  
  98.                     destPath, fileName));  
  99.         } catch (IOException e) {  
  100.             // TODO Auto-generated catch block  
  101.             e.printStackTrace();  
  102.         }  
  103.     }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值