相关资料

Windows安装包:LibreOffice_7.0.6_Win_x64.msi
Linux(CentOs)安装包:LibreOffice_7.0.6_Linux_x86-64_rpm.zip

安装完成后,后续将使用java代码调用软件服务来提供word格式转换


安装

windows安装:双击,点下一步…(安装路径不要含有中文)

Linux安装
解压上面资料的zip,得到两个tar压缩文件,上传至Linux

安装

# 解压
tar -zxvf LibreOffice_7.0.6_Linux_x86-64_rpm.tar.gz
tar -zxvf LibreOffice_7.0.6_Linux_x86-64_rpm_langpack_zh-CN.tar.gz# 使用yum安装rpm目录里的rpm
yum install LibreOffice_7.0.6.2_Linux_x86-64_rpm/RPMS/*.rpm -y
yum install LibreOffice_7.0.6.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS/*.rpm -y# 修改profile添加环境变量
vim /etc/profile
# 末尾追加
export LibreOffice_PATH=/opt/libreoffice7.0/program
export PATH=$LibreOffice_PATH:$PATH# 使配置文件生效
source /etc/profile# 打印安装路径(下列代码libreOfficePath填此值)
whereis libreofficesoffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard

编码调用部分

pom.xml


<libreoffice.version>6.4.7</libreoffice.version><dependency><groupId>org.artofsolving.jodconverter</groupId><artifactId>jodconverter-core</artifactId><version>3.0-beta-4</version><scope>system</scope><systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/jodconverter-3.0-beta-4.jar</systemPath>
</dependency>
<dependency><groupId>org.libreoffice</groupId><artifactId>ridl</artifactId><version>${libreoffice.version}</version>
</dependency>
<dependency><groupId>org.libreoffice</groupId><artifactId>juh</artifactId><version>${libreoffice.version}</version>
</dependency>
<dependency><groupId>org.libreoffice</groupId><artifactId>jurt</artifactId><version>${libreoffice.version}</version>
</dependency>
<dependency><groupId>org.libreoffice</groupId><artifactId>unoil</artifactId><version>${libreoffice.version}</version>
</dependency>

utils

import lombok.extern.slf4j.Slf4j;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.ExternalOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeManager;import java.io.File;/*** @author 954L* @create 2021/6/1 13:44*/
@Slf4j
public class WordUtils {private static String libreOfficePath;static {try {String osName = System.getProperty("os.name").toLowerCase();libreOfficePath = osName.contains("windows") ? "E:\\libreOffice\\install": "/usr/bin/libreoffice7.0";} catch (Exception e) {log.error("初始化libreOfficePath出错", e);}}public static void main(String[] args) {String wordNameRealPath = "D:\\download\\1.docx";String pdfNameRealPath = "D:\\download\\1.pdf";docToPdfLibre(wordNameRealPath, pdfNameRealPath);System.out.println("转换完成!");}public static void docToPdfLibre(String docxPath, String pdfPath) {OfficeManager officeManager = getOfficeManager();try {// 转换OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);File inputFile = new File(docxPath);File outputFile = new File(pdfPath);converter.convert(inputFile, outputFile);} finally {officeManager.stop();}}private static OfficeManager getOfficeManager() {OfficeManager officeManager = null;try {System.out.println("尝试连接已启动的服务...");ExternalOfficeManagerConfiguration externalProcessOfficeManager = new ExternalOfficeManagerConfiguration();externalProcessOfficeManager.setConnectOnStart(true);externalProcessOfficeManager.setPortNumber(8100);officeManager = externalProcessOfficeManager.buildOfficeManager();officeManager.start();System.out.println("转换服务启动成功!");} catch (Exception e) {System.out.println("启动新服务!");DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();configuration.setOfficeHome(new File(libreOfficePath));configuration.setPortNumber(8100);// 设置任务执行超时时间configuration.setTaskExecutionTimeout(1000 * 60 * 5L);// 设置任务队列超时时间configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);officeManager = configuration.buildOfficeManager();officeManager.start();System.out.println("服务启动成功!");}return officeManager;}}

使用LibreOffice在线word转换pdf相关推荐

  1. html5把word转为pDF,在线word转pdf 如何将word转换成pdf

    日常办公常接触到pdf.word文件,在打印或发送文件时也有需要word转成稳定性较好的pdf,那 一起来看看是如何将word转换成pdf的吧.打开安装好的word to pdf软件,如下图,界面很简 ...

  2. 免费!在线WORD转PDF的方法分享

    为什么一般会把WORD文档转成PDF呢?那是因为PDF便于查阅,兼容性.占用内存大小都比Word更好.所以大部分文件格式会使用PDF格式传输,今天就和大家分享一个在线WORD转PDF的方法,并且是有免 ...

  3. JAVA 使用 com.aspose.words将word转换PDF等

    因为公司前端需要在线查看word和PDF,后台上传需求将word等文件转换为PDF,原本使用的是liboffice进行转换,后来部署到服务器端之后,发现并不是很适合,由此找到com.aspose.wo ...

  4. PHP使用LibreOffice实现word转pdf

    PHP使用LibreOffice实现word转pdf 一.windows下的安装及使用 1. 下载并安装<LibreOffice 便携版> 2. 通过cmd命令实现文档转换 3.php调用 ...

  5. 借助 libreoffice,word 转 pdf 体验

    libreoffice 官网 https://zh-cn.libreoffice.org/ 软件下载镜像: https://mirrors.cloud.tencent.com/libreoffice/ ...

  6. Linux系统Word转换PDF,文档字体乱码不显示问题解决。

    1.问题 在Windows系统中,使用Java将Word文档转换为PDF格式时,结果文档内容正常:但是在Linux系统中,转出来PDF文档出现乱码或###符号等. 2.问题原因 这个问题是由于Linu ...

  7. 关于poi操作word,word转换pdf预览,这边文章就够了

    最近公司一个项目中需要导出一个简历word版,对于实习生的我开始是无从下手的,后来通过搜索发现可以使用poi来操作. 话不多说,先引入依赖 <dependency><groupId& ...

  8. Java WORD转换PDF 并添加水印 (附赠jar提取链接)

    Java WORD转换PDF 并添加水印 直接上代码 实现功能 docx文档转换为PDF 转换之后排版不混乱 使用工具(Jar包) aspose-words-15.8.0-jdk16.jar(用于PD ...

  9. Java使用aopse实现word转换pdf

    Java使用aopse实现word转换pdf 需要引用aspose包,引入操作我写了一个博客,地址如下 https://blog.csdn.net/weixin_46713508/article/de ...

最新文章

  1. 人类基因测序被重新定义,时间减半创世界纪录
  2. mysql having实例_Mysql必读mysql group by having 实例代码
  3. ArcGis10安装步骤
  4. ActiveMQ消息中间件的作用以及应用场景
  5. .NET c# Color对象的使用介绍(转)
  6. 没有Javax的Jakarta EE:这次世界也不会结束
  7. 剑指offer_03
  8. PHP7.2的安装与配置(win7)
  9. HexorBase 登陆、执行语句、数据库帐号密码破解
  10. 程序员必修课:为什么非要用 Python 做数据分析?Excel 不好吗?
  11. Matlab二维图导入ansys,(原创教程)利用Matlab对ANSYS数据进行后处理.pdf
  12. 计算机辅助教学研究现状,国内计算机辅助口译教学研究的现状与思考.docx
  13. editplus使用php,EditPlus如何运行php文件
  14. ie tab 强制使用外部程序——ie view
  15. 华为光猫查看LOID密码
  16. Java打印正反等边三角形
  17. EEGLAB工具箱的下载与安装
  18. Swift 数组遍历 ForEach .enumerated() makeIterator() indices
  19. Codeforces-Round#548(Div.2)-C-Edgy Trees-快速幂
  20. 有没有比图灵机能力更强的计算模型?

热门文章

  1. Pinyin4jUtil 验证姓名与拼音是否一致,自持多音字。
  2. CodeMix使用教程:Emmet
  3. linux是不是在根目录下安装的软件其它用户就可以使用,[转载]Linux下非root用户如何安装软件...
  4. 武汉理工大学 操作系统复习
  5. python rgb 图像_在Python中显示RGB图像的不同平面
  6. 陈dy学姐教师招聘经验
  7. D6 PRO充电器使用方法
  8. 推荐一个轻便好用的随时记录的便签类app
  9. use case的翻译
  10. C++中LIstNode尾插法建立单链表