加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

openOffice+pdf2swf+flexpaper(类百度文库) :office转pdf(Linu

发布时间:2020-12-15 07:09:20 所属栏目:百科 来源:网络整理
导读:安装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;?? impor

安装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 FilesOpenOffice.org 3program
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 FilesOpenOffice.org 3program
soffice -headless -accept="socket,port=8100;urp;" -nofirststartwizard
补充一下 :? ?基本上任何文档OpenOffice 都可以打开。 支持了XML、微软的doc、Excel、ppt文件等格式。 ?在openoffice 打开后,可以导出为 PDF ,利用这点可以基本实现 lz的要求 ?1、安装OpenOffice 3 2、用以下命令启动OpenOffice服务 cd C:Program FilesOpenOffice.org 3program soffice -headless -accept="socket,port=8100;urp;" -nofirststartwizard

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读