springboot整合libreoffice(两种方式,使用本地和远程的libreoffice);docker中同时部署应用和libreoffice

一、 背景

因为项目中需要使用word转pdf功能,因为转换速度原因,最后选用了libreoffice,原因及部署请参考
linux ubuntu环境安装libreoffice,word转pdf
远程调用的话可选docker部署,请看2.3.1

二、springboot整合libreoffice

其实springboot整合libreoffice有两种方式,一种是使用本地的libreoffice,一种是使用远程服务的libreoffice(这个好多文章中没有提到,也是自己踩的坑算是)

2.1、整合本地服务

引入pom

    <dependency>
                <groupId>org.jodconverter</groupId>
                <artifactId>jodconverter-spring-boot-starter</artifactId>
                <version>4.4.2</version>
            </dependency>
            <dependency>
                <groupId>org.jodconverter</groupId>
                <artifactId>jodconverter-local</artifactId>
                <version>4.4.2</version>
            </dependency>

yml配置

jodconverter:
  local:
    enabled: true
    #window地址:  D:\workplaces\jcxx\libreoffice 请自行补全
    #linux地址:   /opt/libreoffice24.2
    office-home: /opt/libreoffice24.2
    # 端口(线程)
    portNumbers: [8101,8102,8103]
    maxTasksPerProcess: 100
    # 任务执行的超时时间
    task-execution-timeout: 360000
    # 任务队列的超时时间
    task-queue-timeout: 360000
    # 一个进程的超时时间
    process-timeout: 360000

使用也很简单

    @Resource
    private DocumentConverter documentConverter;

   public void test() {
   
 //流转换
   documentConverter.convert(inputStream).as(DefaultDocumentFormatRegistry.DOCX).to(outStream).as(DefaultDocumentFormatRegistry.PDF).execute();
   //文件转换,sourceFile和targetFile都是File类实例
    documentConverter.convert(sourceFile).to(targetFile).as(DefaultDocumentFormatRegistry.PDF).execute();
   }

2.2、整合远程服务

说一下怎么发现的,学过springboot的应该都知道,整合其他服务时候应该都有个配置类xxxAutoConfiguration
在这里插入图片描述
于是发现了除了一个local外,还有个remote,才发现可以直接调用远程服务,发现了那就可以整合使用,如下
pom引入

  <dependency>
                <groupId>org.jodconverter</groupId>
                <artifactId>jodconverter-spring-boot-starter</artifactId>
                <version>4.4.2</version>
            </dependency>
           <dependency>
                <groupId>org.jodconve
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值