symfgenus / mpdf-wrapper
此捆绑包允许在 symfony3 中使用 mpdf 库。
3.0
2019-03-27 12:08 UTC
Requires
- php: >=7.0
- mpdf/mpdf: ^7.0
- symfony/framework-bundle: ~3.0|~4.0
Requires (Dev)
- symfony/phpunit-bridge: ^4.2
This package is auto-updated.
Last update: 2024-08-27 23:55:53 UTC
README
此捆绑包为 symfony 4 提供 mpdf 库的服务。
1 安装
1.1 使用 composer 下载 MpdfWrapperBundle
在终端中运行
$ php composer.phar require symfgenus/mpdf-wrapper
1.2 启用捆绑包
Symfony flex 会自动激活捆绑包。如果没有自动激活,则需要手动启用捆绑包
// /config/bundles.php [ // ... Symfgenus\MpdfWrapper\MpdfWrapperBundle::class => ['all' => true], ];
2 使用
MpdfService 提供了许多使用 MPDF 的方法。
2.1 它可以生成可以直接通过任何路由提供 PDF 响应。
// /config/bundles.php public function index(MpdfService $MpdfService) { return $MpdfService->generatePdfResponse($pdfHtml); }
2.2 它还可以生成可以保存在变量中并使用的 PDF 内容。
// /config/bundles.php public function index(MpdfService $MpdfService) { return $pdf = $MpdfService->generatePdf($pdfHtml); }
2.3 有时需要创建多个 PDF,可以使用以下方式使用 MpdfService
// /config/bundles.php public function index(MpdfService $MpdfService) { $firstPdf = $MpdfService->getMpdf($argsFirst); $mpdf->WriteHTML($htmlFirst); $firstPdfFile = $mpdf->Output(); $secondPdf = $MpdfService->getMpdf($argsSecond); $mpdf->WriteHTML($htmlSecond); $secondPdfFile = $mpdf->Output(); return [ $firstPdfFile, $secondPdfFile ]; }
3 symfony 3 的使用
对于 symfony 3,可以按以下方式加载此服务
$this->get('symfgenus.mpdf.wrapper').