ubuntu 使用libreoffice 进行word转pdf

libreoffice的安装(参考https://www.2cto.com/net/201911/818525.html

使用此镜像源获取(https://mirrors.tuna.tsinghua.edu.cn/libreoffice/libreoffice/stable

LibreOffice_6.3.4_Linux_x86-64_deb.tar.gz

LibreOffice_6.3.4_Linux_x86-64_deb_langpack_zh-CN.tar.gz

解压后执行如下命令

dpkg -i LibreOffice_6.3.4.2_Linux_x86-64_deb/DEBS/*.deb

dpkg -i LibreOffice_6.3.4.2_Linux_x86-64_deb_langpack_zh-CN/DEBS/*.deb

安装完成后检查服务器的字体是否存在,如果不存在需要把windows下C:\Windows\Fonts该目录下的字体上传到服务器的当前位置
/usr/share/fonts/Fonts/MSYHL.TTC
/usr/share/fonts/Fonts/simsun.ttc
/usr/share/fonts/Fonts/simhei.ttf
/usr/share/fonts/Fonts/MSYHBD.TTC
/usr/share/fonts/Fonts/MSYH.TTC
/usr/share/fonts/Fonts/SIMKAI.TTF
/usr/share/fonts/Fonts/SIMFANG.TTF

 

msyh.ttf(微软雅黑 常规)

msyhbd.ttf(微软雅黑 粗体)

simsun.ttc(宋体 常规)

simkai.ttf(楷体 常规)

simhei.ttf(黑体 常规)

simfang.ttf(仿宋 常规)

 

或者 这个位置(参考https://blog.csdn.net/qq_30554229/article/details/80093894

/usr/lib/rabbitmq/.config/libreoffice/4/user/fonts

 

使用如下命令进行pdf转换

libreoffice6.3 --headless --invisible --convert-to pdf /home/files/filetemp/202002181916501578628060393station.docx --outdir /data/logs/

libreoffice6.3 --convert-to pdf:writer_pdf_Export /data/logs/202002181916501578628060393station.docx --outdir /data/logs

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Node.js 是一种在服务器端运行的 JavaScript 运行环境,可以用于实现各种各样的应用程序。而 LibreOffice 是一款免费、开源的办公软件套件,其中包括了 Writer、Calc、Impress 等应用程序,支持多种文档格式。下面是一个基于 Node.js 和 LibreOffice 的实现 Word PDF 的简单方法: 1.安装 LibreOffice:首先需要在服务器上安装 LibreOffice,可以通过命令行或者图形界面进行安装。 2.使用 Node.js 的 child_process 模块:在 Node.js 中可以通过 child_process 模块来执行系统命令,在本例中可以使用该模块执行 LibreOffice 的命令行工具来进行 Word PDF 的操作。 3.编写 Node.js 代码:可以通过 Node.js 编写一个简单的脚本来实现 Word PDF。以下是一个简单的示例代码: ```javascript const { spawn } = require('child_process'); const inputFilePath = '/path/to/input.docx'; const outputFilePath = '/path/to/output.pdf'; const libreoffice = spawn('libreoffice', [ '--headless', '--convert-to', 'pdf', inputFilePath, '--outdir', outputFilePath, ]); libreoffice.stdout.on('data', (data) => { console.log(`stdout: ${data}`); }); libreoffice.stderr.on('data', (data) => { console.error(`stderr: ${data}`); }); libreoffice.on('close', (code) => { console.log(`child process exited with code ${code}`); }); ``` 以上代码中,spawn 方法会启动一个新的进程来执行 LibreOffice 命令行工具。'--headless' 参数表示以无头模式运行,'--convert-to pdf' 参数表示换成 PDF 格式,inputFilePath 参数表示输入文件的路径,'--outdir' 参数表示输出文件的路径。 4.运行 Node.js 代码:在终端中运行 Node.js 脚本即可进行 Word PDF 的操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值