Skip to content

Troubleshooting Dompdf

Brian Sweeney edited this page Jan 8, 2024 · 2 revisions

Troubleshooting tips and tricks

Font Issues

  • Try removing the generated installed-fonts.json (2.0.0 or greater) or dompdf_font_family_cache.php (1.2.2 or earlier) file. This file stores information about where to find font files.
  • If your system uses custom font and font cache directories, delete all the files from these directories. Do not delete the files that come with Dompdf, which are located in the lib/fonts directory by default.

Integration-specific font directories:

  • Laravel/Dompdf: storage/fonts

Debugging

Enable debug messaging using the following global PHP variables:

  • $_dompdf_warnings = array(); container for Dompdf debug messages
  • $_dompdf_show_warnings = true; record warning messages
  • $_dompdf_debug = true; dump frame details (positioning, CSS properties) to the dompdf log
  • $_DOMPDF_DEBUG_TYPES = [ 'page-break' => true ]; logs a message when Dompdf determines a page break is required

The following Dompdf options can be used for further debug messaging:

  • debugPng display messages related to parsing of PNG images
  • debugCss display detailed CSS parsing information

The following Dompdf options can be used to impact rendering

  • debugKeepTemp keep temporary files generated by Dompdf
  • debugLayout draw a box around elements in the rendered PDF, must also set one or more of the following:
    • debugLayoutLines line boxes
    • debugLayoutBlocks block elements
    • debugLayoutInline inline elements
    • debugLayoutPaddingBox unused

Configuration

The following set up can be used to enable extra messaging around Dompdf operations:

ini_set("display_errors", true);
ini_set("error_log", "phperr.log");
ini_set("log_errors", true);
error_reporting(E_ALL);

$_dompdf_show_warnings = true; // record warnings generated by Dompdf
$_dompdf_debug = false; // output frame details for every frame in the document
$_DOMPDF_DEBUG_TYPES = [
    'page-break' => false // record information about page break determination
];

$dompdf = new Dompdf([
    "logOutputFile" => "log.html",
    "debugPng" => false, // extra messaging
    "debugKeepTemp" => false, // don't delete temp files
    'debugCss' => false, // output Style parsing information and frame details for every frame in the document
    'debugLayout' => false, // draw boxes around frames
    'debugLayoutLines' => false, // line boxes
    'debugLayoutBlocks' => false, // block frames
    'debugLayoutInline' => false, // inline frames
    'debugLayoutPaddingBox' => false // padding box
]);

$dompdf->loadHtml('Dompdf');
$dompdf->render();

$dompdf->stream(
    'render.pdf',
    array('compress' => 0) // disable PDF compression for easier PDF source inspection
);
// OR $dompdf->output(array('compress' => 0));