chrisnharvey / pdfkit
使用 WebKit 的 PHP HTML 到 PDF 转换器。通过 FFI 使用 wkhtmltopdf C 库。
dev-master
2020-10-19 19:40 UTC
Requires
- php: ^7.4
- ext-ffi: *
Requires (Dev)
- phpunit/phpunit: ^9.4
This package is auto-updated.
Last update: 2024-09-20 04:34:00 UTC
README
PDFKit 是一个 PHP 包,它使用 WebKit 将 HTML 转换为 PDF。
通过 PHP FFI 使用 wkhtmltopdf C 库。
注意:此包仍在开发中,其 API 可能会更改。不建议在生产环境中使用。
要求
- PHP 7.4 或更高版本
- FFI 扩展(见 Dockerfile)
- wkhtmltopdf 库(见 Dockerfile)
安装
composer require chrisnharvey/pdfkit
使用方法
use ChrisHarvey\PDFKit\PDFKit; use ChrisHarvey\PDFKit\ConversionFailedException; $pdfkit = new PDFKit(); // Add a page to the pdf $pdfkit->add([ 'page' => 'http://example.com' ]); $pdfkit->saveTo('example.pdf'); $pdfkit->onStageChanged(function () { echo "Moved to next stage"; }); $pdfKit->onProgressChanged(function ($percent) { echo $percent; // Print percentage }); try { $pdfkit->convert(); } catch (ConversionFailedException $e) { print_r($e->getErrors()); print_r($e->getWarnings()); }