divineomega / uxdm-pdf-destination
UXDM数据迁移的PDF目标
v1.1.0
2022-04-18 21:26 UTC
Requires
- php: ^7.1||^8.0
- divineomega/uxdm: ^3.0.0
- dompdf/dompdf: ^0.8.3
Requires (Dev)
- fzaninotto/faker: ^1.6
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^7.0||^8.0
This package is auto-updated.
Last update: 2024-09-19 02:57:53 UTC
README
UXDM PDF目标允许您将数据迁移到PDF表格中。
安装
要安装UXDM PDF目标,只需运行以下composer命令。
composer require divineomega/uxdm-pdf-destination
创建
要创建一个新的PDF目标,您必须提供您希望导出数据的PDF文件的文件路径。PDF表格的第一行将包含字段名。
以下示例创建了一个PDF目标对象,使用同一目录中名为users.pdf
的PDF文件。
$pdfFile = __DIR__.'/users.pdf'; $pdfDestination = new PDFDestination($pdfFile);
自定义纸张大小和方向
您可以将PDF目标更改为输出具有自定义纸张大小和方向的PDF。为此,使用PDF目标对象的setPaperSize
和setPaperOrientation
方法,如下所示。
$destination->setPaperSize('A5'); $destination->setPaperOrientation('landscape');
HTML前缀和后缀
内部,PDF目标将基本的HTML表格渲染为PDF。如果您希望美化表格、添加标题或额外内容,可以添加HTML前缀或HTML后缀。
以下是如何做到这一点的示例。
$htmlPrefix = '<h1>My Report</h1> <style> table { width: 100% } h1 { text-align: center; } th { text-transform: capitalize; text-align: center; } th, td { margin: 0; border: 1px solid #000; } </style>'; $htmlSuffix = '<p>Created by UXDM</p>'; $destination->setHtmlPrefix($htmlPrefix); $destination->setHtmlSuffix($htmlSuffix);
分配到迁移器
要使用PDF目标作为UXDM迁移的一部分,必须将其分配给迁移器。对于大多数目标,这个过程是相同的。
$migrator = new Migrator; $migrator->setDestination($pdfDestination);
或者,您也可以添加多个目标,如下所示。您还可以通过传递字段名数组作为第二个参数来指定您希望发送到每个目标的字段。
$migrator = new Migrator; $migrator->addDestination($pdfDestination, ['field1', 'field2']); $migrator->addDestination($otherDestination, ['field3', 'field2']);