jaxwilko/php-chrome-pdf
Composer 安装命令:
composer require jaxwilko/php-chrome-pdf
包简介
A package to leverage Chrome as a PDF renderer for PHP
README 文档
README
This package offers an interface for generating PDFs using Chrome.
Notice: This package requires google-chrome/chromium to be installed and available to the php user
Install
composer require jaxwilko/php-chrome-pdf
Usage
For basic usage, you can use the make() helper method:
$pdf = \ChromePdf\ChromePdf::make($content); // or printing to file \ChromePdf\ChromePdf::make($content, '/path/to/out.pdf');
ChromePdf supports multiple input types, these include:
urlfor rendering a website url (i.e.https://example.com)filefor rendering a filetextfor rendering text content
use ChromePdf\ChromePdf; $chromePdf = new ChromePdf(); // Render text content (this is the default option) $chromePdf->setInput($content); $chromePdf->setInput($content, ChromePdf::INPUT_TEXT); // Render a url $chromePdf->setInput('https://example.com', ChromePdf::INPUT_URL); // Render a file $chromePdf->setInput('/path/to/example.html', ChromePdf::INPUT_FILE); // Print PDF to file $chromePdf->print(__DIR__ . '/example.pdf'); // Print PDF and get as binary $pdf = $chromePdf->print();
If you need to customise the chrome flags, you can use the following methods:
// Set a single flag $chromePdf->setFlag('--example-flag'); // Set multiple flags $chromePdf->setFlag([ '--example-flag-a', '--example-flag-b', ]); // Replace all flags $chromePdf->setFlags([ '--example-flag-a', '--example-flag-b', '--example-flag-c' ]); // You can also retrieve flag via $flags = $chromePdf->getFlags(); // Removing a flag $chromePdf->clearFlag('--example-flag');
Chrome flags
The following are some useful flags which may help.
--virtual-time-budget=1000This will make sure remote assets (e.g. fonts) finish loading before printing the page. If set the system waits the specified number of virtual milliseconds before deeming the page to be ready. For determinism virtual time does not advance while there are pending network fetches (i.e no timers will fire). Once all network fetches have completed, timers fire and if the system runs out of virtual time is fastforwarded so the next timer fires immediately, until the specified virtual time budget is exhausted--run-all-compositor-stages-before-drawEffectively disables pipelining of compositor frame production stages by waiting for each stage to finish before completing a frame.
For more see Peter Beverloo's very helpful page.
jaxwilko/php-chrome-pdf 适用场景与选型建议
jaxwilko/php-chrome-pdf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 jaxwilko/php-chrome-pdf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jaxwilko/php-chrome-pdf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-10