通过openOffice将office文件转成pdf

作者:龙谷情Sinoam 时间:2021-12-29 21:35:32 

下载安装openoffice,下载地址:http://www.openoffice.org/download/我安装的目录:

通过openOffice将office文件转成pdf

输入cmd回车

通过openOffice将office文件转成pdf

在命令窗口输入

soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" –nofirststartwizard

此时服务就开启了将以下代码放到工具类里面,直接调用即可


import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
...
...
 public File office2Pdf(String srcPath, String pdfPath) throws Exception {
   // 源文件目录
   File inputFile = new File(srcPath);
   if (!inputFile.exists()) {
     throw new Exception("程序出现问题,文件不存在");
   }
   // 输出文件目录
   File outputFile = new File(pdfPath);
   if (!outputFile.exists()) {
     outputFile.createNewFile();
   }
   // 调用openoffice服务线程
   String command = openOfficeCommand;
   Process process = Runtime.getRuntime().exec(command);

// 连接openoffice服务
   OpenOfficeConnection connection = new SocketOpenOfficeConnection(openOfficeUrl, openOfficePort);
   connection.connect();

// 转换word到pdf
   DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
   converter.convert(inputFile, outputFile);
   // 关闭连接
   connection.disconnect();
   // 关闭进程
   process.destroy();
   return outputFile;
 }
...

来源:https://www.cnblogs.com/lgqrlchinese/p/13083551.html

标签:openOffice,office,pdf
0
投稿

猜你喜欢

  • C#中SQL Command的基本用法

    2023-10-04 06:01:32
  • 谈谈HttpClient使用详解

    2022-11-03 08:19:02
  • SpringBoot整合Pulsar的实现示例

    2021-10-09 17:39:35
  • Unity3D实现分页系统

    2022-06-28 22:53:37
  • 详解如何在C#中接受或拒绝Excel中的修订

    2023-06-19 21:08:29
  • Java 十大排序算法之希尔排序刨析

    2021-11-16 09:27:31
  • Android中让按钮拥有返回键功能的方法及重写返回键功能

    2021-08-08 10:33:56
  • C#添加、读取Word脚注尾注的方法

    2022-12-24 02:12:22
  • 一篇文章带你搞定JAVA注解

    2023-03-15 05:22:23
  • Java 数据结构与算法系列精讲之KMP算法

    2023-05-06 14:55:55
  • Java求解二叉树的最近公共祖先实例代码

    2023-09-14 18:24:56
  • Android仿XListView支持下拉刷新和上划加载更多的自定义RecyclerView

    2023-04-26 12:46:02
  • java实现文件重命名

    2023-08-26 09:27:46
  • Java安全框架——Shiro的使用详解(附springboot整合Shiro的demo)

    2022-05-29 09:46:46
  • Flutter WebView 预加载实现方法(Http Server)

    2023-06-25 23:14:35
  • java实现摄像头截图功能

    2023-12-01 19:53:22
  • Mybatis中xml的动态sql实现示例

    2023-11-29 17:09:36
  • 搭建MyBatis-Plus框架并进行数据库增删改查功能

    2023-11-09 04:33:43
  • 完美解决docx4j变量替换的问题

    2021-08-19 21:00:25
  • springboot配置redis过程详解

    2022-10-13 12:41:30
  • asp之家 软件编程 m.aspxhome.com