Skip to content

baumrock/RockPdf

Repository files navigation

RockPdf

Quickstart

/** @var RockPdf $pdf */
$pdf = $this->wire->modules->get('RockPdf');
$pdf
  ->addFont('poppins', [
    'R' => 'site/templates/rockpdf/fonts/Poppins Regular 400.ttf',
    'B' => 'site/templates/rockpdf/fonts/Poppins Bold 700.ttf',
  ], true)
  ->setDocTemplate("/path/to/bg.pdf")
  ->load("rockpdf/baumrock.com/markup.latte")
  ->saveHTML()
  ->save();

$pdf->preview();

Iframe Preview

$wire->addHookAfter("ProcessPageEdit::buildForm", function($event) {
  $form = $event->return;

  /** @var RockPdf $pdf */
  $pdf = $this->wire->modules->get('RockPdf');
  $pdf->iframe($form->get('your_pdf_field_name'));
});

Headers & Footers

Note: Using the php methods like SetHTMLHeader() does not work if you applied a @page rule to your CSS! That's why it's best to always add the header/footer via @page in css so it will work for sure. The footer named foo can be set in css as footer: html_foo.

See also https://mpdf.github.io/paging/using-page.html#example-using-headers-and-footers

<style>
@page {
  footer: html_footer;
  margin-footer: 11mm;
}
</style>
<htmlpagefooter name="footer">
  <table class="mside w100p f10">
    <tr>
      <td>{date("d.m.Y")}</td>
      <td class="tr" n:syntax="off">
        Seite {PAGENO}/{nb}
      </td>
    </tr>
  </table>
</htmlpagefooter>

Latte and mPDF tags

mPDF tags like {PAGENO} conflict with the default latte single brace syntax. Simply change the syntax to off or double:

<p n:syntax="off">Seite {PAGENO}/{nb}</p>

Changing mPDF Settings

/** @var RockPdf $pdf */
$pdf = $this->wire->modules->get('RockPdf');
$pdf
  ->addFont('poppins', [
    'R' => 'site/templates/rockpdf/fonts/Poppins Regular 400.ttf',
    'B' => 'site/templates/rockpdf/fonts/Poppins Bold 700.ttf',
  ], true)
  ->invoke(function ($mpdf) {
    $mpdf->shrink_tables_to_fit = 0;
  })
  ...

Load fonts from file field

Use the description to indicate font type (bold, regular, ...):

$pdf->addFontFromField(
  page: $yourpage,
  field: 'myfonts'
  name: 'default',
  default: true,
);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •