Centos 7 安装 Wkhtmltopdf 实现网页快照

可使用yum安装:

yum install wkhtmltopdf

不过由于CentOS的yum库里的wkhtmltopdf版本过旧,而新版的不再依赖X server,会导致 wkhtmltopdf: cannot connect to X server 这样的报错。

卸载后使用从官网下载预编译版安装:

wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar xvfJ wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
cd wkhtmltox/bin
sudo mv ./wkhtmltopdf /usr/bin/wkhtmltopdf
sudo chmod +x /usr/bin/wkhtmltopdf

测试:

wkhtmltopdf http://www.baidu.com ./test.pdf

可能缺少libXrender.so.1依赖

image.png

此时如果生成的字符都是方块,那么安装standard PostScript fonts:

yum install urw-fonts libXext openssl-devel

如果中文不显示,则将 windows下的字体,例如simsun.ttc ,或者msyh.ttf,或者msyhbd.ttf 复制到 linux系统  /usr/share/fonts 下。

版权声明:
作者:ForDream
链接:https://ishoud.com/index.php/2021/08/24/120.html
来源:工具人
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
海报
Centos 7 安装 Wkhtmltopdf 实现网页快照
可使用yum安装: yum install wkhtmltopdf 不过由于CentOS的yum库里的wkhtmltopdf版本过旧,而新版的不再依赖X server,会导致 wkhtmltopdf: cannot connect t……
<<上一篇
下一篇>>