mfabdelaziz/weasyprint-bundle
Composer 安装命令:
composer require mfabdelaziz/weasyprint-bundle
包简介
Cmreate PDF in Symfony by converting Twig/HTML templates.
README 文档
README
PhpWeasyPrint is a PHP (7.4+) wrapper for WeasyPrint PDF generator. It allows you to generate PDF files from HTML string or URL.
The WeasyPrintBundle provides a simple integration for your Symfony project.
This bundle is massively inspired by KnpLabs/KnpSnappyBundle, of which it aims to be a one-to-one substitute
Installation
With composer, require:
composer require pontedilana/weasyprint-bundle
Then enable it in your kernel (a flex recipe is coming soon):
// config/bundles.php <?php return [ //... Pontedilana\WeasyprintBundle\WeasyprintBundle::class => ['all' => true], //... ];
Configuration
If you need to change the binaries, change the instance options or even disable one or both services, you can do it through the configuration.
# config/packages/weasyprint.yaml weasyprint: pdf: enabled: true binary: /usr/local/bin/weasyprint options: [] image: enabled: true binary: /usr/local/bin/weasyprint options: []
If you want to change temporary folder which is sys_get_temp_dir() by default, you can use
# config/packages/weasyprint.yaml weasyprint: temporary_folder: "%kernel.cache_dir%/weasyprint"
You can also configure the timeout used by the generators with process_timeout:
# config/packages/weasyprint.yaml weasyprint: process_timeout: 20 # In seconds
Usage
The bundle registers two services:
- the
weasyprint.pdfservice allows you to generate pdf files. - the
weasyprint.imageservice allows you to generate images (works only with WeasyPrint 52.5 or lower);
Generate a pdf document from a URL
// @var Pontedilana\PhpWeasyPrint\Pdf $weasyprintPdf->generate('https://www.github.com', '/path/to/the/file.pdf');
Generate a pdf document from a twig view
// @var Pontedilana\PhpWeasyPrint\Pdf $weasyprintPdf->generateFromHtml( $this->renderView( 'frontend/product/pdf.html.twig', [ 'some' => $vars, ] ), '/path/to/the/file.pdf' );
Render a pdf document as response from a controller
use Pontedilana\WeasyprintBundle\WeasyPrint\Response\PdfResponse; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class SomeController extends AbstractController { public function pdfAction(Pontedilana\PhpWeasyPrint\Pdf $weasyprintPdf) { $html = $this->renderView( 'frontend/product/pdf.html.twig', [ 'some' => $vars, ] ); return new PdfResponse( $weasyprintPdf->getOutputFromHtml($html), 'file.pdf' ); } }
Render a pdf document with a relative url inside like css files or images
use Pontedilana\WeasyprintBundle\WeasyPrint\Response\PdfResponse; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class SomeController extends AbstractController { public function pdfAction(Pontedilana\PhpWeasyPrint\Pdf $weasyprintPdf) { $pageUrl = $this->generateUrl('homepage', [], true); // use absolute path! return new PdfResponse( $weasyprintPdf->getOutput($pageUrl), 'file.pdf' ); } }
Credits
WeasyPrintBundle and PhpWeasyPrint has been developed by Pontedilana.
SnappyBundle has been developed by KnpLabs.
mfabdelaziz/weasyprint-bundle 适用场景与选型建议
mfabdelaziz/weasyprint-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bundle」 「pdf」 「symfony-bundle」 「WeasyPrint」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mfabdelaziz/weasyprint-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mfabdelaziz/weasyprint-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mfabdelaziz/weasyprint-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
Symfony bundle for the Rekapager library
Symfony bundle for Cloudflare integration: trusted proxies, real client IP detection, forwarded headers.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-29