To open a PDF made with Dompdf, you might want to add
ob_end_clean();
before
$dompdf->stream();
In your PHP project.
ob_end_clean — Clean (erase) the contents of the active output buffer and turn it off
Full Example Code:
<?php
require 'vendor/autoload.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
$content = '<h1>Hello World</h1>';
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($content);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
ob_end_clean();
// Output the generated PDF to Browser
$dompdf->stream();
?>
For potentially more answers, go here.
Top comments (0)