Using Templates

You want to add some fancy backgrounds to your PDFs? Sure!

/** @var RockPdf $pdf */
$pdf = $modules->get('RockPdf');
$pdf
  ->setDocTemplate("/site/bg.pdf")
  ->load("/site/test.php")
  ->save(preview: true);
RockPdf - Using Templates

In this example we have a template file with one page and we have a final document with one page. That's not always the case.

Continue

By default mPDF will use the last page of your template as background for all following pages in your document. That makes it possible to use a different background for the cover page and use some generic footer for all following pages. If your template has only one page itself then all pages will use the same background:

RockPdf - Using Templates

You can disable adding of the same background over and over again with the second parameter of the setDocTemplate method:

/** @var RockPdf $pdf */
$pdf = $modules->get('RockPdf');
$pdf
  ->setDocTemplate("/site/bg.pdf", false)
  ->load("/site/test.php")
  ->save(preview: true);
RockPdf - Using Templates

On this page