atwx/silverstripe-headless-pdf
Composer 安装命令:
composer require atwx/silverstripe-headless-pdf
包简介
Headless Chrome PDF generation for SilverStripe
README 文档
README
A Silverstripe module for printing a given html-template into a pdf file using headless chromium in php. This module enables the creation of zugferd compatible e-invoices. For this the additional module horstoeko/zugferd is required.
Installation
This module can be installed via Composer with
composer require atwx/silverstripe-headless-pdf
Requirements
This module requires the following modules
php: "^8.3",
silverstripe/framework: "^6.0",
chrome-php/chrome: "^1.15"
Configuration
The browser-factory will search for the environment variable CHROME_PATH when starting. To prevent it from guessing, this variable should be set in your .env (configuration instruction from chrome-php/chrome).
If the browser has trouble rendering the PDF (mostly timeouts), you can try different navigation wait events. This can be set in the WAITING_MODE variable in the .env. All available events can be found here. For each constant the string version has to be used. In this module the default value is 'networkIdle'.
This pdf module uses hashes created with the sha256 algorithm for protecting the html. Therefore you need to set the HEADLESS_PDF_HASH_KEY variable in your .env otherwise the pdf creation return an 403 http error. Any other authentication method has to be disabled for the HeadlessPDFController->renderPdfTemplate function.
Additionally if you are using ddev you can set the IS_DDEV variable in your .env to "true". By doing this sandboxing is disabled and certificate errors are ignored allowing printing PDFs locally. To use headless chrome in ddev you need the headless chrome add-on by gebruederheitz.
Usage
To print a pdf you need to create a new instance of HeadlessPDFService and call its generatePdf function. This function takes up to 5 arguments:
- a link for rendering the html-template which will then be printed as a pdf,
- a string containing the filename,
- a bool
getPathfor getting the pdf as a string (default) or as a path to a temporary file, - optional xml-data for creating zugferd compatible e-invoices (this requires additionally the horstoeko/zugferd module),
- and an optional array for php-chrome options changing the default pdf-options defined in the
HeadlessPDFService.
The link given as first argument needs to point to
/pdf/renderPdfTemplate/<optional ID>
calling the HeadlessPDFController with the following get-parameters:
templatecontaining the full template name/path (called with renderWith($template)),hashgenerated withHeadlessPDFController::generateHash,- optional
classNameto use an object in the template corresponding to $ID in the link. This object is callable as$TemplateObjectin the template, - optional
controllerto use an iterable list of dataobjects in the template callable as$TemplateDatalist. This list can be defined in a getPdfDatalist function in the given controller, - optional
variationcontaining a string callable asVariationin the template to enable similar pdf versions without the need to create a new template.
For the correct rendering of the pdf received as a string you need to set the two HTTP-headers
$this->getResponse()->addHeader('Content-Type', 'application/pdf')
$this->getResponse()->addHeader('Content-Disposition', 'inline; filename="' . <filename> . '.pdf"')
atwx/silverstripe-headless-pdf 适用场景与选型建议
atwx/silverstripe-headless-pdf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「pdf」 「headless」 「silverstripe」 「chrome」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 atwx/silverstripe-headless-pdf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 atwx/silverstripe-headless-pdf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 atwx/silverstripe-headless-pdf 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This extension provides integration with solr to output content from TYPO3 in JSON format.
Instrument headless chrome/chromium instances from php5.6
Admin Hub for GetCandy. A modern headless e-commerce solution for Laravel PHP framework.
Analytics chooser extensions for site settings.
A new generation of multi-process async event-driven spider engine based on Workerman
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 45
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2026-05-04