RockPdf - Easy PDF Creation

Easy PDF creation for ProcessWire with (optional) Latte templates and custom fonts

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>
    <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, ...):

68747470733a2f2f692e696d6775722e636f6d2f784441386b31632e706e67

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

More modules by bernhard

  • RockMigrations

    The Ultimate Automation and Deployment-Tool for ProcessWire
  • RockFinder

    Highly Efficient and Flexible SQL Finder Module
  • RockFrontend

    Module for easy frontend development
  • RockFinder3

    Combine the power of ProcessWire selectors and SQL.
  • SiteRockFrontend

    Site Profile for RockFrontend
  • RockLESS

    Module to parse LESS files via PHP.
  • AdminStyleRock

    Docs & Development Module for rock style of AdminThemeUikit
  • RockHeadlineIDs

    Demo Textformatter
  • RockMigrations1

    Module to handle Migrations inside your Modules easily.

All modules by bernhard

Install and use modules at your own risk. Always have a site and database backup before installing new modules.