symfgenus / mpdf-wrapper
This bundle allows to use mpdf library with symfony3.
Installs: 50
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
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-12-28 00:44:03 UTC
README
This bundle provides a service for mpdf library with symfony 4.
1 Installation
1.1 Download MpdfWrapperBundle using composer
Run in terminal:
$ php composer.phar require symfgenus/mpdf-wrapper
1.2 Enable the bundle
Symfony flex activates the bundles automatically. If it is not, then enable the bundle:
// /config/bundles.php [ // ... Symfgenus\MpdfWrapper\MpdfWrapperBundle::class => ['all' => true], ];
2 Usage
MpdfService provides many ways to use MPDF.
2.1 It can generate a direct pdf response which can be served through any route.
// /config/bundles.php public function index(MpdfService $MpdfService) { return $MpdfService->generatePdfResponse($pdfHtml); }
2.2 It can also generate pdf content which can be saved in a variable and used.
// /config/bundles.php public function index(MpdfService $MpdfService) { return $pdf = $MpdfService->generatePdf($pdfHtml); }
2.3 Sometimes there is need to create multiple PDFs, MpdfService can be used as following:
// /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 Usage for symfony 3
For symfony 3, this service can be loaded as following:
$this->get('symfgenus.mpdf.wrapper').