cenos安装libreoffice+java-jodconverter word文档转pdf

下载安装包

链接:https://pan.baidu.com/s/1JbfC8LkC0cGEYR0iJ0Q_Tw
提取码:9gri

LibreOffice_6.0.3_Linux_x86-64_rpm.tar.gz 
LibreOffice_6.0.3_Linux_x86-64_rpm_sdk.tar.gz 
LibreOffice_6.0.3_Linux_x86-64_rpm_langpack_zh-CN.tar.gz

或者从:
http://mirrors.ustc.edu.cn/tdf/libreoffice/stable/6.0.4/rpm/x86_64/LibreOffice_6.0.4_Linux_x86-64_rpm.tar.gz

安装

 mkdir /opt/libreoffice
 tar -zxvf LibreOffice_6.0.3_Linux_x86-64_rpm.tar.gz -C /opt/libreoffice/
 tar -zxvf LibreOffice_6.0.3_Linux_x86-64_rpm_sdk.tar.gz -C /opt/libreoffice/ 
 tar -zxvf LibreOffice_6.0.3_Linux_x86-64_rpm_langpack_zh-CN.tar.gz -C /opt/libreoffice/

分别进入刚才三个文件解压后的目录的rpm文件夹 ,执行入下命令

cd /opt/libreoffice/LibreOffice_6.0.3_Linux_x86-64_rpm/RPMS
yum localinstall *.rpm
之后执行下面一行代码
 yum -y install cairo 

安装字体

  1. 安装fontconfig
yum -y install fontconfig

安装完成后,/usr/share目录就可以看到fonts和fontconfig两个目录。

  1. 安装ttmkfdir
yum -y install ttmkfdir
  1. 检查已有字体库
fc-list

4.复制字体

 #新建文件夹
 mkdir /usr/share/fonts/chinese

把Windows系统的字体C:\Windows\Fonts复制进去。
simsun.ttc 宋体
simhei.ttf 黑体
msyh.ttf 微软雅黑
msyhbd.ttf 微软雅黑

  1. 修改字体权限
chmod -R 644 /usr/share/fonts/chinese
  1. 汇总生成fonts.scale文件
ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir
  1. 修改字体配置文件
vim /etc/fonts/fonts.conf
 修改内容

  ....
  ....

  /usr/share/fonts/chinese
  ....

  1. 更新字体缓存
fc-cache -fv

调用方法

  1. 命令调用:
# 源文件放在 e:\tmp\123.docx 或者 /tmp/123.docx

# windows
soffice.exe --headless --invisible --convert-to pdf e:\tmp\123.docx --outdir e:\tmp

# linux
/usr/bin/libreoffice6.0 --headless --invisible --convert-to pdf /tmp/123.docx --outdir /tmp
  1. java调用

  org.jodconverter
  jodconverter-core
  4.2.0


  org.jodconverter
  jodconverter-local
  4.2.0


  org.jodconverter
  jodconverter-spring-boot-starter
  4.2.0


  org.libreoffice
  ridl
  5.4.2


#application.properties
jodconverter:
  local:
    enabled: true
    office-home: /opt/libreoffice6.1
    port-numbers: 8100,8101,8102
    max-tasks-per-process: 100

#调用:
@RestController
@RequestMapping("/doc")
public class LibreOfficeController {
   @Autowired
    private DocumentConverter documentConverter;
    @RequestMapping("/toPdf")
    public void toPdf() throws OfficeException {
     File wfile = new File("/opt/aa.docx");
        File pfile = new File("/opt/pfile.pdf");
        documentConverter.convert(wfile).to(pfile).execute();
    }

}

参考地址:https://blog.csdn.net/diyiday/article/details/79852923
https://segmentfault.com/a/1190000015129654#articleHeader6

你可能感兴趣的:(cenos安装libreoffice+java-jodconverter word文档转pdf)