Linux CentOS7 安装wkhtmltopdf工具

  wkhtmltopdf是一款将html文件转换成pdf格式的优秀的文件内容转换工具。它使用QT作为渲染引擎,目前它的RELEASE版尚不支持flex布局的Html5代码转换。使用flex的嵌套元素将会像没有style修饰的块级元素似的被转换。但是它的测试版使用较新的Qt引擎,可以部分支持flex效果。

安装步骤:

1. 官网下载wkhtmltopdf测试版本0.13.0的rpm包——https://wkhtmltopdf.org/downloads.html

2. 使用yum安装环境,(我用的是webtatic的yum源,依赖包挺全的,之前装的php70w也是通过它)

  (1)yum install icu.x86_64

  (2)yum install xorg-x11-fonts-75dpi.noarch

  (3)yum install xorg-x11-fonts-Type1.noarch

  (4)yum install xorg-x11-server-Xvfb ——(官网里对测试版安装时的提示:Builds for OS X will be made available as soon as support for it is added in the build script, which is an ongoing process. Please note that the above linux builds are not headless, and will require running under xvfb.否则运行‘wkhtmltopdf’转换命令时会报错‘QXcbConnection: Could not connect to display Aborted (core dumped)’)

3. 安装wkhtmltopdf包

4. 使用‘xvfb-run wkhtmltopdf html文件 pdf文件’就可以完成转换。

 

最后flex布局的H5代码转换后,某些特性依然没有转换过来,比如'align-item'、使用flex项目属性的内联元素依然不具备width属性。

posted @ 2019-04-24 14:36  一吃  阅读(4324)  评论(0编辑  收藏  举报