enflow/document-replacer
Composer 安装命令:
composer require enflow/document-replacer
包简介
Modify docx templates and convert them to PDF
README 文档
README
The enflow/document-replacer package provides a easy way to modify docx templates, replace text and save it. Adds the ability to export it to PDF trough unoserver/unoconvert.
Installation
You can install the package via composer:
composer require enflow/document-replacer
PDF conversion
This package comes with an implementation to convert docx templates to PDF using unoserver. You can install this on your machine globally using:
sudo add-apt-repository ppa:libreoffice/ppa
sudo apt install libreoffice
sudo pip install unoserver
Converters
It's highly recommend using the new unoconvert converter. If you are unable to upgrade, we still provide the deprecated UnoconvConverter for the time being. UnoconvConverter is deprecated and will be removed in 3.0.
Server
Unoserver works together with unoconvert. Unoserver runs as a daemon on the server, and unoconvert connects through it to pass the files. To see why this is more efficient, see https://github.com/unoconv/unoserver/#overview
Start the server with:
unoserver --daemon
It's recommended setting this up with a server like supervisord, without the --daemon flag, to auto restart the process if needed.
Usage
use Enflow\DocumentReplacer\DocumentReplacer; DocumentReplacer::template('filename.docx') ->converter(UnoserverConverter::class) ->replace([ '${user}' => 'Michel', '${address.city}' => 'Alphen aan den Rijn', '${company}' => 'Enflow', ]) ->save('document.pdf');
Images
If you wish to replace images in your document, you can pass the Image class to the replacement array like this:
use Enflow\DocumentReplacer\DocumentReplacer; use Enflow\DocumentReplacer\ValueTypes\Image; DocumentReplacer::template('filename.docx') ->converter(UnoconvConverter::class) ->replace([ '${primary}' => Image::forPath('image.png'), '${second}' => Image::forBase64('iVBORw0KGgoA...'), ]) ->save('document.pdf');
The search-pattern model for images can be like:
${search-image-pattern}${search-image-pattern:[width]:[height]:[ratio]}${search-image-pattern:[width]x[height]}${search-image-pattern:size=[width]x[height]}${search-image-pattern:width=[width]:height=[height]:ratio=false}Where:- [width] and [height] can be just numbers or numbers with measure, which supported by Word (cm|mm|in|pt|pc|px|%|em|ex)
- [ratio] uses only for
false,-orfto turn off respect aspect ration of image. By default template image size uses as 'container' size.
More info can be found in the PHPWord documentation
Non-default server options
Running the server on non-default options (IP 127.0.0.1 / port 2002)? You can pass along the interface and port to the UnoserverConverter:
DocumentReplacer::template('filename.docx') ->converter(UnoserverConverter::class, [ 'interface' => '192.168.0.1', 'port' => 1533, ])
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email michel@enflow.nl instead of using the issue tracker.
Credits
About Enflow
Enflow is a digital creative agency based in Alphen aan den Rijn, Netherlands. We specialize in developing web applications, mobile applications and websites. You can find more info on our website.
License
The MIT License (MIT). Please see License File for more information.
enflow/document-replacer 适用场景与选型建议
enflow/document-replacer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30.01k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2019 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「document」 「docx」 「enflow」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 enflow/document-replacer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 enflow/document-replacer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 enflow/document-replacer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Push Laravel Excel exporters to Google Sheets
Invalidity check of documents in the database of Ministry of the Interior of the Czech Republic
Push Laravel Excel exporters to Google Sheets or Google BigQuery
Document indexation and migration tool for Elasticsearch
Adds a Document Management System to SilverStripe
Pacote para validar/gerar/formatar RG e CPF
统计信息
- 总下载量: 30.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-25