This bundle provides a service for mpdf library with symfony 4.
Run in terminal:
$ php composer.phar require symfgenus/mpdf-wrapper
Symfony flex activates the bundles automatically. If it is not, then enable the bundle:
// /config/bundles.php
[
// ...
Symfgenus\MpdfWrapper\MpdfWrapperBundle::class => ['all' => true],
];
MpdfService provides many ways to use MPDF.
// /config/bundles.php
public function index(MpdfService $MpdfService)
{
return $MpdfService->generatePdfResponse($pdfHtml);
}
// /config/bundles.php
public function index(MpdfService $MpdfService)
{
return $pdf = $MpdfService->generatePdf($pdfHtml);
}
// /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
];
}
For symfony 3, this service can be loaded as following:
$this->get('symfgenus.mpdf.wrapper').