LibreOffice 转pdf

这篇教程介绍了如何安装LibreOffice,包括在Windows上配置环境变量,并提供了利用jodconverter类库进行文档转换的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装部分

  • 安装LibreOffice ,有window linux 版本
    下载地址

  • window 配置环境变量 , PATH 下添加 LibreOffifce 的安装目录

  • 打开cmd ,输入 soffice,
    如果
    出现该图片说明配置成功

撸代码

想要调用libreoffice 的服务,需要使用jodconverter类库
github地址

  • maven依赖
<properties>
    <jodconverter.version>4.2.2</jodconverter.version>
</properties>
<dependencies>
   <dependency>
      <groupId>org.jodconverter</groupId>
      <artifactId>jodconverter-local</artifactId>
      <version>${jodconverter.version}</version>
   </dependency>
</dependencies>
  • 关键代码
File inputFile = new File("document.doc");
File outputFile = new File("document.pdf");

// Create an office manager using the default configuration.
// The default port is 2002. Note that when an office manager
// is installed, it will be the one used by default when
// a converter is created.
final LocalOfficeManager officeManager = LocalOfficeManager.install(); 
try {

    // Start an office process and connect to the started instance (on port 2002).
    officeManager.start();

    // Convert
    JodConverter
             .convert(inputFile)
             .to(outputFile)
             .execute();
} finally {
    // Stop the office process
    OfficeUtils.stopQuietly(officeManager);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值