使用LibreOffice将word转化为pdf -解决中文乱码

本文介绍了在Linux系统中如何下载安装LibreOffice,以及因缺少中文字体导致转换docx为pdf时出现中文乱码的问题。通过安装中文字体如微软雅黑,确保顺利转化不出现乱码。
摘要由CSDN通过智能技术生成

1、下载安装

linux 下载rpm包
# wget https://mirrors.cloud.tencent.com/libreoffice/libreoffice/stable/7.0.6/rpm/x86_64/LibreOffice_7.0.6_Linux_x86-64_rpm.tar.gz

# wget https://mirrors.cloud.tencent.com/libreoffice/libreoffice/stable/7.0.6/rpm/x86_64/LibreOffice_7.0.6_Linux_x86-64_rpm_langpack_zh-CN.tar.gz

# wget https://mirrors.cloud.tencent.com/libreoffice/libreoffice/stable/7.0.6/rpm/x86_64/LibreOffice_7.0.6_Linux_x86-64_rpm_helppack_zh-CN.tar.gz

2、安装

# yum install ./LibreOffice_7.0.6.2_Linux_x86-64_rpm/RPMS/*.rpm

# yum install ./LibreOffice_7.0.6.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS/*.rpm

# yum install ./LibreOffice_7.0.6.2_Linux_x86-64_rpm_helppack_zh-CN/RPMS/*.rpm

3、安装中文字体(由于linux默认没有安装中文字体 所以导出有中文的文件会导致中文乱码 )

这里安装微软雅黑

3.1查看是否安装中文字体

# fc-list :lang=zh //显示为空表示没有安装中文字体

3
Node.js 是一种在服务器端运行的 JavaScript 运行环境,可以用于实现各种各样的应用程序。而 LibreOffice 是一款免费、开源的办公软件套件,其中包括了 Writer、Calc、Impress 等应用程序,支持多种文档格式。下面是一个基于 Node.js 和 LibreOffice 的实现 WordPDF 的简单方法: 1.安装 LibreOffice:首先需要在服务器上安装 LibreOffice,可以通过命令行或者图形界面进行安装。 2.使用 Node.js 的 child_process 模块:在 Node.js 中可以通过 child_process 模块来执行系统命令,在本例中可以使用该模块执行 LibreOffice 的命令行工具来进行 WordPDF 的操作。 3.编写 Node.js 代码:可以通过 Node.js 编写一个简单的脚本来实现 WordPDF。以下是一个简单的示例代码: ```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 脚本即可进行 WordPDF 的操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值