Formatters

RockPdf comes equipped with https://github.com/wasinger/htmlpagedom and you can use this library to modify the markup of your html as you want.

For example you could add classes to every heading element your you could apply styles to every image element.

<h1>Some text</h1>
<img src="https://placekitten.com/200/150">
<h1>Some text</h1>
<img src="https://placekitten.com/200/151">

Example in /site/ready.php:

use Wa72\HtmlPageDom\HtmlPageCrawler;
$modules->get('RockPdf')
  ->formatter(function (HtmlPageCrawler $dom) {
    $dom->filter("h1")->each(function (HtmlPageCrawler $node) {
      $node->setText("-- " . $node->text() . " --");
    });
    return $dom->saveHTML();
  })
  ->formatter(function (HtmlPageCrawler $dom) {
    $dom->filter("img")->each(function (HtmlPageCrawler $node) {
      $node->setStyle("border", "3px solid red");
    });
    return $dom->saveHTML();
  })
  ->load("site/templates/formatters.latte")
  ->save(preview: true, saveHTML: true);

Please see the docs of https://github.com/wasinger/htmlpagedom for details. You can also take a look at RockPdf's addFontAwesomeTextformatter() method.

RockPdf - Formatters