famelo/pdf
Composer 安装命令:
composer require famelo/pdf
包简介
Provides a quick and simple way to generate a PDF from a Fluid Template through the MPDF library
README 文档
README
This package provides a quick and simple way to generate a PDF from a Fluid Template through the MPDF library
Example:
$document = new \Famelo\PDF\Document('My.Package:SomeDocument'); $document->assign('someVariable', 'foobar'); // Trigger a Download and exit $document->download('SomeDocument ' . date('d.m.Y') . '.pdf'); // Show the document inline and exit $document->send(); // Save the document to a local file $document->save('/Some/Path/SomeDocument ' . date('d.m.Y') . '.pdf');
This example will render a template located at resource://My.Package/Private/Documents/SomeDocument.html
and convert it to PDF.
Page Format and orientation
By default pages will be rendered as a A4 Portrait. You can choose another format/orientation like this:
// set format to A5 Portrait $document = new \Famelo\PDF\Document('My.Package:SomeDocument', 'A5'); // set format to an A4 Landscape $document->setFormat('A4-L'); // set format to 100mm x 200mm $document->setFormat([100, 200]);
The MPDF library supports different page sizes with these keywords or an array containing 2 values for width + height:
- A0 - A10
- B0 - B10
- C0 - C10
- 4A0
- 2A0
- RA0 - RA4
- SRA0 - SRA4
- Letter
- Legal
- Executive
- Folio
- Demy
- Royal
- Ledger
- Tabloid*
All of the above values can be suffixed with "-L" to force a Landscape page orientation document e.g. "A4-L". If format is defined as a string, the final orientation parameter will be ignored.
*Ledger and Tabloid are standard formats with the same page size but different orientation (Ledger is landscape, and Tabloid is portrait). mPDF treats these identically; if you wish to use Ledger, you should specify "Ledger-L" for landscape.
Page numbering in Fluid
If you want to use mPDFs page numbering variables like {PAGENO} or {nbpg} you have to wrap them in a CDATA section, to keep Fluid from interpreting them as variables.
PDF Generator Implementation
By default this Library uses the MPDF library to generate the PDFs. But you can change the defaultGenerator through the Settings.yaml like this:
Famelo: PDF: # Generator using wkhtmltopdf through knplabs/knp-snappy DefaultGenerator: '\Famelo\PDF\Generator\WebkitGenerator' DefaultGeneratorOptions: Binary: '/usr/local/bin/wkhtmltopdf'
Feel free to create and use a generator for your favorite PDF Library And send me a Pull-Request if you think others might like to use it :)
famelo/pdf 适用场景与选型建议
famelo/pdf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 74.05k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2013 年 01 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 famelo/pdf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 famelo/pdf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 74.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 26
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2013-01-15