Skip to content
Till Berger edited this page Jun 17, 2022 · 6 revisions

Migration Guide

1.2.2 or earlier → 2.0.0

Callback signature change

Dompdf callbacks are now called with three individual arguments Frame, Canvas, FontMetrics instead of a single info array. An event set up like

[
    'event' => 'begin_frame',
    'f' => function ($info) {
        $frame = $info['frame'];
        $canvas = $info['canvas'];
        ...
    }
]

before would now bet set up like this:

[
    'event' => 'begin_frame',
    'f' => function ($frame, $canvas) {
        ...
    }
]

For details, see the documentation on callbacks.

page_script is executed immediately

The Canvas methods page_script, page_text, and page_line are now executed immediately rather than during output generation. They should be called after rendering the document, or, if used in embedded PHP code, at the end of the document. Calling them before or during rendering will only have an effect on the pages rendered so far. To set up a page script before rendering, the new end_document callback event is available, which will call page_script internally after rendering is complete.

0.8.5 or earlier → 0.8.6

Breaking change to local resource (image, stylesheet) references

With the 0.8.6 release Dompdf security was increased so that resources (images, fonts, external stylesheets) that would previously load with the default settings may no longer load. To ensure your system continues to load external resources please review the following options:

  • isRemoteEnabled: If you load resources from other servers over the Internet this must be set to true.
  • chroot: If you load resources from your local filesystem make sure the files are within the directory specified by this option. By default chroot is set to the Dompdf directory.

Information on how to change these settings can be found in the readme section on setting options.

0.6.2 or earlier → 0.7.0

dompdf_config.inc.php

The dompdf_config.inc.php file was removed from the library starting with dompdf 0.7.0. All dompdf options are now set at run time. To simplify your in-code instantiation you can implement an intermediary script to set up dompdf and configure the options, using this intermediate script in your project.

Font Loading

The code refactoring required a change to the dompdf_font_family_cache.php file. Though we have attempted to accommodate this change so that you can perform an in-place upgrade your best option would be to install a fresh copy of dompdf. This would, of course, require loading into the new dompdf installation any fonts from your previous installation. You can attempt an in-plac upgrade, but if you run into any bugs your first step should be to reset your font directory (i.e. remove custom font files, font metrics files, and dompdf_font_family_cache.php file).

The command-line font loader script load_font.php is no longer provide as part of the library. The script has been moved to the dompdf-utils project. In lieu of using an external script to load fonts you may use the @font-face CSS rule. Fonts referenced in an @font-face rule will be installed when your document is rendered.

FontMetrics is now instantiated

The FontMetrics class is now instantiated instead of static. This means that how you access this object had to be modified. Any embedded scripts that utilized the FontMetrics class in version of dompdf prior to 0.7.0 should now use the $fontMetrics variable. Please update your embedded scripts.

For example, FontMetrics::get_font('helvetica') would now be $fontMetrics->getFont('helvetica').