office转PDF

young 630 2021-10-17

安装openoffice或libreoffice

openoffice

  1. http://www.openoffice.org/download/other.html
  2. 下载中文简体版的压缩包
tar -zxvf Apache_OpenOffice_4.1.8_Linux_x86-64_install-rpm_zh-CN.tar.gz
cd zh-CN/RPMS
rpm -Uvh *.rpm desktop-integration/openoffice4.1.8-redhat-menus-4.1.8-9803.noarch.rpm
  1. 启动
nohup  /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &

libreoffice

  1. https://zh-cn.libreoffice.org/

wget -P /tmp/office http://mirrors.ustc.edu.cn/tdf/libreoffice/stable/7.0.4/rpm/x86_64/LibreOffice_7.0.4_Linux_x86-64_rpm.tar.gz

wget -P /tmp/office http://mirrors.ustc.edu.cn/tdf/libreoffice/stable/7.0.4/rpm/x86_64/LibreOffice_7.0.4_Linux_x86-64_rpm_langpack_zh-CN.tar.gz
tar zxvf /tmp/office/LibreOffice_7.0.4_Linux_x86-64_rpm.tar.gz -C /tmp/office

tar zxvf /tmp/office/LibreOffice_7.0.4_Linux_x86-64_rpm_langpack_zh-CN.tar.gz -C /tmp/office
rpm -Uvh /tmp/office/LibreOffice_7.0.4.2_Linux_x86-64_rpm/RPMS/*.rpm

rpm -Uvh  /tmp/office/LibreOffice_7.0.4.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS/*.rpm

pom.xml

<dependency>
            <groupId>org.libreoffice</groupId>
            <artifactId>ridl</artifactId>
            <version>7.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.jodconverter</groupId>
            <artifactId>jodconverter-core</artifactId>
            <version>4.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.jodconverter</groupId>
            <artifactId>jodconverter-local</artifactId>
            <version>4.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.jodconverter</groupId>
            <artifactId>jodconverter-spring-boot-starter</artifactId>
            <version>4.3.0</version>
        </dependency>

application.yml

jodconverter:
  local:
    enabled: true
    portNumbers: 8100
    # libreoffice
    office-home: /opt/libreoffice7.0
    # openoffice : /opt/openoffice4

调用方法

import org.jodconverter.DocumentConverter;

@Resource
private DocumentConverter documentConverter;

documentConverter.convert(sourceFile).to(targetFile).execute();