Linux(CentOS)使用WPS进行文档转PDF

前言

环境

升级Centos7系统的GLIBC

查看现有版本

1
getconf GNU_LIBC_VERSION

如果WPS Office无法启动,可能是因为系统GLIBC版本过低。

可以通过以下步骤升级GLIBC:

1
2
3
4
5
6
7
wget https://mirrors.ustc.edu.cn/gnu/libc/glibc-2.18.tar.gz
tar -zxvf glibc-2.18.tar.gz
cd glibc-2.18
mkdir build && cd build
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
make -j4
make install

下载安装

https://www.wps.com/zh-hant/office/linux/

https://www.wps.cn/product/wpslinux#

这里下载的文件为wps-office-11.1.0.11723.XA-1.x86_64.rpm

安装

1
sudo rpm -ivh wps-office-11.1.0.11723.XA-1.x86_64.rpm

安装报错

错误:依赖检测失败:
libICE.so.6()(64bit) 被 wps-office-11.1.0.11723.XA-1.x86_64 需要
libSM.so.6()(64bit) 被 wps-office-11.1.0.11723.XA-1.x86_64 需要
libX11.so.6()(64bit) 被 wps-office-11.1.0.11723.XA-1.x86_64 需要
libXext.so.6()(64bit) 被 wps-office-11.1.0.11723.XA-1.x86_64 需要
libXrender.so.1()(64bit) 被 wps-office-11.1.0.11723.XA-1.x86_64 需要
libXss.so.1()(64bit) 被 wps-office-11.1.0.11723.XA-1.x86_64 需要
libfontconfig.so.1()(64bit) 被 wps-office-11.1.0.11723.XA-1.x86_64 需要
libpulse-mainloop-glib.so.0()(64bit) 被 wps-office-11.1.0.11723.XA-1.x86_64 需要
libxcb.so.1()(64bit) 被 wps-office-11.1.0.11723.XA-1.x86_64 需要

安装

1
yum install -y freetype fontconfig libgcc glib2 libpng mesa-libGLU libSM libXrender libXtst zlib

或者用yum安装 会自动安装依赖

1
yum localinstall wps-office-11.1.0.11723.XA-1.x86_64.rpm

12.1.0

1
yum localinstall -y wps-office-12.1.0.17900-1.x86_64.rpm

转换

1
wps --convert-to 输出格式 文件路径

或者如果你使用的是基于debian的Linux发行版,可能会是:

1
wps-office --convert-to 输出格式 文件路径

这里的 输出格式 指的是你希望转换成的文件类型,比如 pdfdocxxlsx 等。文件路径 是你希望转换的源文件路径。

比如

1
wps --convert-to pdf ./test.docx --outdir ./test.pdf

目前直接调用转换没有反应,在排查原因

字体复制到/usr/share/fonts/wps-office