使用wkhtmltopdf转pdf

xiaohai 2020-08-21 14:28:09 1539人围观 标签: 工具 
简介wkhtmltopdf 能够把多个“对象”合并生成一个pdf文档,这些“对象”可以是“页面对象”、“封面对象”、或是“目录对象”。这些对象在pdf文档中的顺序可以通过命令行参数来指定。命令行参数包括两部分,一种是针对某一特定“对象”的命令行参数,另一种是全局的命令行参数。并且全局的命令行参数只能放在全局参数区([GLOBAL OPTION])中指定。

wkhtmltopdf官网:https://wkhtmltopdf.org/index.html

官网提示 linux需要这些动态库。depends on: zlib, fontconfig, freetype, X11 libs (libX11, libXext, libXrender)

1、下载二进制包:wkhtmltox-0.12.4_linux-generic-amd64.tar.xz

下载地址:https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz

2、解压压缩包:

tar -xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz

3、安装依赖

出现:./wkhtmltopdf: error while loading shared libraries: libXrender.so.1: cannot open shared object file: No such file or directory

yum install libXrender*

出现:./wkhtmltopdf: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory

安装:yum install libfontconfig*

出现:./wkhtmltopdf: error while loading shared libraries: libXext.so.1: cannot open shared object file: No such file or directory

yum install libXext*

4、测试进入到bin目录下

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

注意:转成的pdf乱码,这里就需要处理linux安装中文字体 请搜索 linux安装中文字体