evanpurkhiser / kohana-html2pdf
该包已废弃,不再维护。未建议替代包。
使用wkhtmltopdf作为转换后端,将HTML转换为PDF文档的Kohana模块
dev-3.3/master / 3.3.x-dev
2014-05-05 23:48 UTC
Requires
- php: >=5.2.4
- kohana/core: 3.3.*
This package is not auto-updated.
Last update: 2020-01-24 15:08:46 UTC
README
HTML2PDF文档转换器
HTML2PDF是一个Kohana 3.x模块,可以用来将HTML文档转换为PDF文档。该模块使用wkhtmltopdf作为后端处理转换。
要求
您必须在您的机器上安装wkhtmltopdf静态二进制文件(至少版本0.10 RC1),并且它必须在执行PHP应用的用户的PATH中可读。
用法
您可以从HTML创建PDF文档,如下(可选指定HTML内容)
$document = HTML2PDF::document($html)
从这里您可以对文档应用不同的格式化选项,包括
$document->body($html)
- 设置PDF的HTML主体内容$document->header($html)
- 设置在每个页面顶部渲染的HTML$document->header_spacing($spacing)
- 设置内容和页眉之间的间距$document->margins($top, $left, $bottom, $right)
- 设置文档的页边距(以毫米为单位)
请参阅类本身以获取所有可用方法。
最后,您可以通过两种不同的方式将文档渲染为PDF。您可以将PDF保存到文件系统上的文件,或者将PDF转换为Blob并返回。
// Save to the filesystem
$document->save('/home/evan/document.pdf');
// Save to filesystem and return temporary file path
$temp_path = $document->save();
// Convert and put the BLOB into a variable
$pdf_blob = $document->convert();