slims/pdf-factory
Composer 安装命令:
composer require slims/pdf-factory
包简介
SLiMS Library to generate report as PDF file with varous PDF providers
README 文档
README
Example code:
<?php use SLiMS\Pdf\Factory; use SLiMS\Pdf\Contract; use Dompdf\Dompdf; require __DIR__ . '/../vendor/autoload.php'; class MyProvider extends Contract { public function setPdf():void { $this->pdf = new Dompdf(); } public function setContent():void { $this->pdf->loadHtml('<h1>Hello World!</h1>'); } public function download(string $filename):void { $this->stream($filename, ['Attachment' => true]); } public function stream(?string $filename = null, ?array $options = null):void { $this->pdf->render(); $this->pdf->stream(($filename??md5('this') . 'pdf'), ($options??['Attachment' => false])); exit; } public function saveToFile(string $filepath, ?Closure $callback = null):void { $this->pdf->render(); if ($callback !== null) { $callback($this->pdf, $filepath); } else { file_put_contents($filepath, $this->pdf->output()); exit; } } } Factory::registerProvider('MyProvider', MyProvider::class); Factory::useProvider('MyProvider'); if (isset($_GET['download'])) { Factory::download('harno.pdf'); } if (isset($_GET['stream'])) { Factory::stream(); } if (isset($_GET['save'])) { // Simple save Factory::saveToFile(__DIR__ . '/test.pdf'); // Advance save with custom file handler Factory::saveToFile('test2.pdf', function($pdf, $filepath) { // you can use league\filesystem etc. file_put_contents(__DIR__ . '/' . $filepath, $pdf->output()); }); }
统计信息
- 总下载量: 42
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2023-09-30