heimrichhannot/contao-pdf-creator-bundle
Composer 安装命令:
composer require heimrichhannot/contao-pdf-creator-bundle
包简介
A generic pdf creation bundle
README 文档
README
This bundle adds a generic way to configure the creation of pdf files, reuse these configurations and create pdfs on base of them. It's based on PDF Creator library.
Features
- add PDF configurations from backend module or yaml
- can be easily used in your bundle
- bundled support for:
- contao article syndication
- Syndication Type Bundle
Note: there is no pdf library bundled with this bundle, you need to add the ones you want to use by your own! See Usage section for more information.
Screenshot Configuration
Usage
Setup
-
Install the pdf library you want to use (currently dompdf, mpdf and tcpdf are supported, see PDF Creator library) for more information
-
Install bundle with composer or contao manager
composer require heimrichhannot/contao-pdf-creator-bundle -
Update database
-
Create a pdf configuration in contao backend within system -> pdf configuration or via yaml (see configuration reference)
Yaml pdf configuration
To reuse configurations or customize them on different environments, you can set pdf creator configs in your configuration files. You'll find all possible options in the configuration reference.
Example:
# /config/config.yml huh_pdf_creator: configurations: news_export: type: dompdf name: "Default News export configuration" filename: '%%title%%-my_brand_corporate.pdf' output_mode: inline brand_brochure: type: dompdf name: "Brand brochure" filename: 'my_brand_corporate.pdf' output_mode: download format: A5 base_template: 'files/media/brand_cd/brand_brochure_template.pdf'
Export article as pdf
-
Set
huh_pdf_creator.enable_contao_article_pdf_syndicationto true# config/config.yml or app/config/config.yml (Contao 4.4) huh_pdf_creator: enable_contao_article_pdf_syndication: true
-
Clear cache and update database
-
Choose pdf as syndication option in article configuration and select a pdf configuration
Syndication Bundle
Select PDF syndication and choose the pdf creator setting you want for export.
Advanced topics
Logging
To get enhanced debug information while creating pdfs, you can enter the contao dev mode. In dev mode, pdf creator bundle save all logs created by the pdf library (if the library supports PSR-3 logging) to a huh_pdf_creator-[DATE].log file in the log folder. For dompdf this bundle support the custom logging implementation and stores the log to a huh_pdf_creator-dompdf.log file in the log folder.
Server routing issues / authentication
To avoid trouble with server routing (special url handling with docker etc.) and use the library on access restricted websites (for example staging setups), you can set a base_url that will override the url determined from the request and credentials (http basic authentication is supported only). These options are only available with yaml configuration as they usually server-specific.
huh_pdf_creator: configurations: custom_pdf_config: type: dompdf name: "PDF behind authentication" base_url: 'https://customer.example.org' credentials: 'user:password'
DomPdf chroot setting
Pdf Creator Bundle comes with default settings for dompdf chroot option for the most typical folders where files are stored, that are used in pdfs. You can adjust this settings in the bundle configuration.
These are the default settings:
huh_pdf_creator: allowed_paths: - web - public - files - assets
Developer
Add pdf creator to your bundle
-
Use
PdfGenerator::generate()to generate a pdf with your content. It expects an id of an PDF Creator config, html content and anPdfContextinstance and returns aPdfCreatorResultinstance.use Heimrichhannot\PdfCreatorBundle\Generator\PdfGenerator; use Heimrichhannot\PdfCreatorBundle\Generator\PdfGeneratorContext; class ExportCustomEntity { /**@var PdfGenerator */ protected $pdfGenerator; public function __invoke(string $content, array $row): void { $context = new PdfGeneratorContext($row['title']); $result = $this->pdfGenerator->generate($content, $row['pdfConfiguration'], $context); } }
-
Use
DcaGeneratorto add an PDF Creator config field to your dca.use Contao\CoreBundle\DataContainer\PaletteManipulator; use Heimrichhannot\PdfCreatorBundle\Generator\DcaGenerator; class LoadDataContainerListener { /** @var DcaGenerator */ protected $dcaGenerator; public function __invoke(string $table): void { if ('tl_custom_dca' === $table) { PaletteManipulator::create()->addField('pdfConfiguration', 'someField')->applyToPalette('default', 'tl_custom_entity'); $GLOBALS['TL_DCA']['tl_custom_entity']['fields']['pdfConfiguration'] = $this->dcaGenerator->getPdfCreatorConfigSelectFieldConfig(); } } }
Events
| Event | Description |
|---|---|
| BeforeCreateLibraryInstanceEvent | Passes the PDF Creator BeforeCreateLibraryInstanceCallback |
| BeforeOutputPdfCallbackEvent | Passes the PDF Creator BeforeOutputPdfCallback |
More information
heimrichhannot/contao-pdf-creator-bundle 适用场景与选型建议
heimrichhannot/contao-pdf-creator-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 863 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 02 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bundle」 「pdf」 「contao」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 heimrichhannot/contao-pdf-creator-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 heimrichhannot/contao-pdf-creator-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 heimrichhannot/contao-pdf-creator-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Contao Open Source CMS
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
统计信息
- 总下载量: 863
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2021-02-26

