html转换成高质量的PDF文件[跨平台开源软件]

Convert HTML Page To a PDF Using Open Source Tool [ Linux / OS X / Windows ]
http://www.cyberciti.biz/open-source/html-to-pdf-freeware-linux-osx-windows-software/

项目中需要用到html 转成 pdf的组件,需要支持html中css和js效果的渲染支持。

一周时间内测试了TCPDF/mpdf/html2fpdf/prince/prawn等数个组件,其中prince的转换效果稍稍出众,但是css渲染有一些问题,而且是收费软件,TCPDF功能强大,页头页尾均很好的支持,但对代码高亮等特殊的js效果处理得不到位。

直接周末找到了wkhtmltopdf。

先介绍一下大体功能

跨平台:Cross platform.
开源:Open source.
支持webkit引擎渲染页面:Convert any web pages into PDF documents using webkit.
页头页尾支持:You can add headers and footers.
创建TOC:TOC generation.
命令行执行,方便其它程序调用:Batch mode conversions.
可以运行在XServer下:Can run on Linux server with an XServer (the X11 client libs must be installed).
PHP的libwkhtmltox组件支持,嘎嘎,phper最爱:Can be directly used by PHP or Python via bindings to libwkhtmltox.

原文作者花了大面积的篇幅介绍如何安装使用,我就不多说了,安装简单,一分钟内安装完成。

[shell]
sudo apt-get install wkhtmltopdf
wkhtmltopdf http://www.baidu.com/index.php baidu.pdf
[/shell]

https://github.com/antialize/wkhtmltopdf
https://github.com/mreiferson/php-wkhtmltox
http://www.cs.au.dk/~jakobt/libwkhtmltox_0.10.0_doc/pagesettings.html

发表评论