nazrulwazir/pdf
Composer 安装命令:
composer require nazrulwazir/pdf
包简介
A PDF builder using HTML or DOCX templates.
关键字:
README 文档
README
Looking for maintainers, I no longer do much if any PHP dev, I have moved on, mostly work in dotnet core, node.js & golang these days. If anyone is keen to take over these projects, get in touch - brad@bjc.id.au
PS. I know this is one of the more popular repos and I know some of you have been having a few issues with it. I use athenapdf for all my PDF generation needs these days.
The Pdf Gear
This project started life as a DOCX templating engine. It has now envolved to also support converting HTML to PDF using a headless version of webkit, phantomjs.
The DOCX templating is great for documents that end clients update and manage over time, particularly text heavy documents. For example I use it to auto generate some legal contracts, where simple replacements are made for attributes like First Name, Last Name, Company Name & Address. The client, an insurance company, can provide updated template word documents that might contain subtle changes to policies & other conditions.
The HTML to PDF engine is great for cases where greater control over the design of the document is required. It's also more natural for us programmers, using standard HTML & CSS, with a splash of Javscript.
How to Install
Installation via composer is easy:
composer require gears/pdf:*
You will also need to add the following to your root composer.json file.
"scripts":
{
"post-install-cmd": ["PhantomInstaller\\Installer::installPhantomJS"],
"post-update-cmd": ["PhantomInstaller\\Installer::installPhantomJS"]
}
DOCX: If you are going to be using the DOCX templating you will need to install either libre-office-headless or unoconv on your host.
How to Use, the basics
Both APIs are accessed through the main Pdf class.
To convert a word document into a PDF without any templating:
$pdf = Gears\Pdf::convert('/path/to/document.docx');
To save the generated PDF to a file:
Gears\Pdf::convert('/path/to/document.docx', '/path/to/document.pdf');
To convert a html document into a PDF:
$pdf = Gears\Pdf::convert('/path/to/document.html');
NOTE: The save to file works just the same for a HTML document.
DOCX Templating
By default the DOCX backend defaults to using libre-office-headless,
to use unoconv, override the converter like so:
$document = new Gears\Pdf('/path/to/document.docx'); $document->converter = function() { return new Gears\Pdf\Docx\Converter\Unoconv(); }; $document->save('/path/to/document.pdf');
NOTE: Currently the HTML backend only uses phantomjs.
There are several templating methods for the DOCX engine.
The first is setValue, this replaces all instances of
${FOO} with BAR
$document->setValue('FOO', 'BAR');
To clone an entire block of DOCX xml, you surround your block with tags like:
${BLOCK_TO_CLONE} & ${/BLOCK_TO_CLONE}. Whatever content is
contained inside this block will be repeated 3 times in the generated PDF.
$document->cloneBlock('BLOCK_TO_CLONE', 3);
If you need to replace an entire block with custom DOCX xml you can. But you need to make sure your XML conforms to the DOCX standards. This is a very low level method and I wouldn't normally use this.
$document->replaceBlock('BLOCK_TO_REPLACE', '<docx><xml></xml></docx>');
To delete an entire block, for example you might have particular sections of the document that you only want to show to certian users.
$document->deleteBlock('BLOCK_TO_DELETE');
Finally the last method is useful for adding new rows to tables.
Similar to the cloneBlock method. You place the tag in first cell
of the table. This row is the one that gets cloned.
$document->cloneRow('ROW_TO_CLONE', 5);
For more examples please see the Unit Tests. These contain the PHP code to generate the final PDF along with the original DOCX templates.
NOTE: The HTML to PDF converter does not have these same templating functions. Obviously it's just standard HTML that you can template how ever you like.
HTML PhantomJs Print Environment
This is still in development and subject to radical change. So I won't document this section just yet...
Credits
The DOCX templating code originally came from PHPWord
You may still like to use PHPWord to generate your DOCX documents. And then use this package to convert the generated document to PDF.
Developed by Brad Jones - brad@bjc.id.au
nazrulwazir/pdf 适用场景与选型建议
nazrulwazir/pdf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 10 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「template」 「pdf」 「docx」 「converter」 「builder」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nazrulwazir/pdf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nazrulwazir/pdf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nazrulwazir/pdf 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple ASCII output of array data
E2E Studios PHP Framework adaptation of leafsphp/blade package
Provides TCPDF integration for Symfony
Ensolab template project
docx template manipulation class, based on mustache templating language
A adapter for the mPDF print library
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-11