- Run a command
composer require tfox/mpdf-port-bundle
- Add a new line to
app/AppKernel.php
:
$bundles = array(
...
new TFox\MpdfPortBundle\TFoxMpdfPortBundle(),
)
- Add a new entry to your
deps
file:
[TFoxMpdfPortBundle]
git=https://github.com/tasmanianfox/MpdfPortBundle.git
target=/bundles/TFox/MpdfPortBundle
- Add a new line to
app/AppKernel.php
:
new TFox\MpdfPortBundle\TFoxMpdfPortBundle(),
- Add a new line to
app/autoload.php
:
'TFox' => __DIR__.'/../vendor/bundles',
- Run a command
php bin/vendors install
This small example creates a PDF document with format A4 and portrait orientation:
public function indexAction()
{
return new \TFox\MpdfPortBundle\Response\PDFResponse($this->getMpdfService()->generatePdf('Hello World'));
}
/**
* @return \TFox\MpdfPortBundle\Service\PDFService
*/
private function getMpdfService()
{
return $this->get('t_fox_mpdf_port.pdf');
}
Sometimes it is necessary to get a variable which content is PDF document.
$myVar = $this->getMpdfService()->generatePdf('Hello World');
If you would like to work with mPDF class itself, you can use a getMpdf method:
$mpdf = new \Mpdf\Mpdf();
Additional options might be passed via the second argument:
public function indexAction()
{
return new \TFox\MpdfPortBundle\Response\PDFResponse($this->getMpdfService()->generatePdf('Hello World', array(
'format' => 'A4-L' // A4 page, landscape orientation
)));
}
Detailed description is available on official manual page: https://mpdf.github.io/