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屬性。