OpenOffice实现word转pdf

1.pom.xml

<!-- openoffice word转pdf --><dependency><groupId>com.artofsolving</groupId><artifactId>jodconverter</artifactId><version>2.2.2</version></dependency><dependency><groupId>org.openoffice</groupId><artifactId>jurt</artifactId><version>3.0.1</version></dependency><dependency><groupId>org.openoffice</groupId><artifactId>ridl</artifactId><version>3.0.1</version></dependency><dependency><groupId>org.openoffice</groupId><artifactId>juh</artifactId><version>3.0.1</version></dependency><dependency><groupId>org.openoffice</groupId><artifactId>unoil</artifactId><version>3.0.1</version></dependency>

2.下载jodconverter2.2.2.jar
3.jodconverter2.2.2推送至maven仓库

mvn install:install-file -Dfile=本地jar包路径 -DgroupId=com.artofsolving -DartifactId=jodconverter -Dversion=2.2.2 -Dpackaging=jar

4.OpenOffice安装
5.OpenOffice服务启动cmd命令

cd C:\Program Files (x86)\OpenOffice 4\program
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard

6.文件转换工具类

package com.zimax.cqyf.admin.tests;import java.io.File;
import java.io.IOException;import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;public class DOC2PDFUtil {//使用openoffice 将word格式的文件转换为pdf格式public static void word2Pdf(String srcPath, String desPath) throws IOException {// 源文件目录File inputFile = new File(srcPath);if (!inputFile.exists()) {System.out.println("源文件不存在!");return;}// 输出文件目录File outputFile = new File(desPath);if (!outputFile.getParentFile().exists()) {outputFile.getParentFile().exists();}// 调用openoffice服务线程
//      String command = "C:\\Program Files (x86)\\OpenOffice 4\\program\\soffice -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\" -nofirststartwizard";
//      Process p = Runtime.getRuntime().exec(command);// 连接openoffice服务OpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);connection.connect();// 转换word到pdfDocumentConverter converter = new OpenOfficeDocumentConverter(connection);converter.convert(inputFile, outputFile);// 关闭连接connection.disconnect();// 关闭进程//p.destroy();System.out.println("转换完成!");}/*** 测试main方法* @param args*/public static void main(String[] args) throws IOException {word2Pdf("D:\\123.doc","D:\\123.pdf");}
}

7.转换结果

13:06:13.283 [main] DEBUG com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection - connecting
13:06:13.417 [main] INFO com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection - connected
13:06:26.158 [main] DEBUG com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection - disconnecting
13:06:26.160 [main] INFO com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection - disconnected
转换完成!

OpenOffice服务开机自启https://blog.csdn.net/sll714827/article/details/121679137
资源下载:https://download.csdn.net/download/sll714827/34874030

OpenOffice实现word转pdf相关推荐

  1. php 调用openoffice,PHP调用OpenOffice实现word转PDF的方法

    最近一直在研究PHP word文档转PDF,也在网上搜索了很多类似的资料,大多数都是通过OpenOffice进行转换的. 核心的代码如下: function MakePropertyValue($na ...

  2. 使用easyPoi导出word文档并使用openoffice把word转换为pdf格式

    easyPoi官网:http://www.wupaas.com/ 一.制作要导出的word模板(使用Word软件制作模板),把模板里的变量用{{字段名}}代替,把制作好的模版放到,如下图我放到stat ...

  3. PHP调用OpenOffice实现word转PDF

     最近一直在研究PHP word文档转PDF,也在网上搜索了很多类似的资料,大多数都是通过OpenOffice进行转换的. 核心的代码如下: function MakePropertyValue( ...

  4. java使用openOffice 实现word转pdf

    1.首先需要安装openOffice 2.下载jodconverter-2.2.2.jar package com.toutiao_efficiency.modules.documet_file.se ...

  5. openoffice将word转pdf中文乱码或消失的坑

    将windows系统下的中文字体文件(C:\Windows\Fonts),放到/usr/share/fonts下,必须重启openoffice. 转载于:https://www.cnblogs.com ...

  6. openOffice word转pdf,pdf转图片优化版

    之前写了一个版本的,不过代码繁琐而且不好用,效率有些问题.尤其pdf转图片速度太慢.下面是优化版本的代码. spriing_boot 版本信息:2.0.1.RELEASE 1.配置信息: packag ...

  7. windows/linux服务器上java使用openoffice将word文档转换为PDF(亲测可用)

    一. 前言 1. 开发过程中经常会使用java将office系列文档转换为PDF, 一般都使用微软提供的openoffice+jodconverter 实现转换文档. 2. openoffice既有w ...

  8. 使用OpenOffice插件实现RTF/WORD转PDF转多张图片或者一张图片

    这里我们使用的是OpenOffice插件,需要安装,还有相关的jar包 网盘地址: https://pan.baidu.com/s/1c6HymABx3wre-d19eB1c-w      密码: n ...

  9. Java通过openOffice实现word,excel,ppt转成pdf实现在线预览

    Java通过openOffice实现word,excel,ppt转成pdf实现在线预览 一.OpenOffice 1.1 下载地址 1.2 JodConverter 1.3 新建实体类PDFDemo ...

  10. PHP使用openoffice实现word,ppt,Excel在线转PDF浏览。windows和linux系统不同的解决方案

    一.PHP使用openoffice实现office在线转PDF介绍 最近需要在网页上实现预览上传的word文档,之前没有实现过相关功能,搜索了一下网上的资料,完整的教程较少,因此将自己实现的步骤和遇到 ...

最新文章

  1. Opencv中的FaceRecognizer类
  2. Firefox自带下载功能进行断点续传
  3. python 认证_Django 用户认证
  4. 在python中嵌入c/c++
  5. 总结和分析几种判断RecyclerView到达底部的方法
  6. Win10 注册IIs4.0的解决方案
  7. 甲醛、苯、甲苯、二甲苯对人体健康的危害
  8. 菜鸟学习笔记:Java基础篇6(数组、字符串)
  9. [BJWC2011]元素
  10. hdu 1995 汉诺塔
  11. CAngle类 角度转换类 C++
  12. Visual Basic6.0下载及安装
  13. 数学基础知识总结 —— 4. 常见函数图像
  14. sqlserver企业版秘钥_SQLserver 2012下载 (附密钥)
  15. ArcGIS模型构建器计算几何的方法
  16. 计算化学系列教程-第一章-薛定谔方程
  17. 力天创见客流统计分析系统
  18. mysql查询结果赋予变量_MySQL设置会话变量:把查询结果赋值给变量
  19. matlab求自相关频率,使用自相关求周期性
  20. 怎么关闭自动启动的屏幕键盘

热门文章

  1. 陈文灯畅谈2005考研数学复习策略
  2. java 腾讯微博模拟登陆_腾讯微博模拟登录
  3. 阿里架构师的架构设计——详解高可用架构设计
  4. Android material design 之 BottomSheet基础入门
  5. 服务器端查询客户端cookie时的拙计
  6. Qt制作QQ好友列表
  7. MongoDB 极简入门实践
  8. 互联网专家资源分享(二)
  9. L2-029 特立独行的幸福
  10. 『常识』印刷纸张尺寸对比表