How to use dompdf for Custom Files?

Dear all,I added this in ListOptions_Rendering:-
option 1. (without export=pdf)
$this->ListOptions->Items[“dlpdf”]->Body = “<a href="genpdf.php?id=”. CurrentPage()->id->CurrentValue .“" title="Download PDF" target="_blank"><span class="fa fa-file-pdf-o ew-icon" style="color: red">”;
option 2. (with export=pdf)
$this->ListOptions->Items[“dlpdf”]->Body = “<a href="genpdf.php?export=pdf&id=”. CurrentPage()->id->CurrentValue .“" title="Download PDF" target="_blank"><span class="fa fa-file-pdf-o ew-icon" style="color: red">”;So, I coded the custom file genpdf.php (with include common files checked) as

<?php echo $_GET["id"]."\n"; ?>

The results is OKAY.Now, with Tools → Extensions → dompdf (Enabled)
I modified the custom files genpdf.php (with include common files checked)

<?php $dompdf = new Dompdf\Dompdf(); $dompdf->loadHtml('hello world'); $dompdf->setPaper('A4', 'landscape'); $dompdf->render(); $dompdf->stream(); ?>

Error message => PHP Fatal error: Uncaught Error: Class ‘PHPMaker2020\testproj\Dompdf\Dompdf’ not found in /var/www/html/testproj/dlpdf.php:34\nStack trace:\n#0 {main}\n thrown in /var/www/html/testproj/dlpdf.php on line 34<?php $dompdf = new \Dompdf\Dompdf(); $dompdf->set_option('defaultFont', 'Courier'); // with or without this line $dompdf->loadHtml('hello world'); $dompdf->setPaper('A4', 'landscape'); $dompdf->render(); $dompdf->stream(); ?>
Error message => PHP Fatal error: Uncaught Dompdf\Exception: Unable to find a suitable font replacement for: ‘serif’ in /var/www/html/testproj/vendor/hkvstore/dompdf/src/Css/Style.php:997\nStack trace:\n#0 /var/www/html/testproj/vendor/hkvstore/dompdf/src/Css/Style.php(851): Dompdf\Css\Style->get_font_family()\n#1 /var/www/html/testproj/vendor/hkvstore/dompdf/src/FrameReflower/Text.php(194): Dompdf\Css\Style->__get(‘font_family’)\n#2 /var/www/html/testproj/vendor/hkvstore/dompdf/src/FrameReflower/Text.php(372): Dompdf\FrameReflower\Text->_layout_line()\n#3 /var/www/html/testproj/vendor/hkvstore/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(895): Dompdf\FrameReflower\Text->reflow(Object(Dompdf\FrameDecorator\Block))\n#4 /var/www/html/testproj/vendor/hkvstore/dompdf/src/FrameReflower/Block.php(845): Dompdf\FrameDecorator\AbstractFrameDecorator->reflow(Object(Dompdf\FrameDecorator\Block))\n#5 /var/www/html/testproj/vendor/hkvstore/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(895): Dompdf\FrameReflower\Block->reflow(Object(Dompdf\FrameDecorator\ in /var/www/html/testproj/vendor/hkvstore/dompdf/src/Css/Style.php on line 997But if I click on the default export to pdf for table, the result is fine. Just can’t use dompdf in custom files.Did I miss out any important step(s) on Custom Files to generate stream pdf?Thank in advance.Regards
scs

You’d better use CSS styles in your HTML, e.g.
body { font-family: DejaVuSans; }

Change as per mention above.Now the error changed from serif to dejavusans (Even with Courier, Times-Roman…).$html = “body {font-family: DejaVuSans;}Welcome”;
$dompdf->loadHtml($html);
Error message => PHP Fatal error: Uncaught Dompdf\Exception: Unable to find a suitable font replacement for: ‘dejavusans’ in /var/www/html/testproj/vendor/hkvstore/dompdf/src/Css/Style.php:997

Run composer update to update hkvstore/dompdf v0.8.303 and try again.

Now no more error and document.pdf generated but not able to open by Adobe Reader. Because the contain is text as stated below (some characters change to |)|!DOCTYPE html|
|html|
|head|
|title||/title|
|meta charset=“utf-8”|
|meta name=“viewport” content=“width=device-width, initial-scale=1, shrink-to-fit=no”|
|link rel=“stylesheet” type=“text/css” href=“adminlte3/css/adminlte.css”|
|link rel=“stylesheet” type=“text/css” href=“plugins/fontawesome-free/css/all.min.css”|
|link rel=“stylesheet” type=“text/css” href=“plugins/fontawesome-free/css/v4-shims.css”|
|link rel=“stylesheet” type=“text/css” href=“css/OverlayScrollbars.min.css”|
|link rel=“stylesheet” type=“text/css” href=“css/Testproj.css”|

I only pass the below format to dompdf

<?php $dompdf = new \Dompdf\Dompdf(); $dompdf->loadHtml("Test"); $dompdf->setPaper('A4', 'landscape'); $dompdf->render(); $dompdf->stream(); ?>But the output (.pdf) become the previous attached text format.

Your code does work. You should add exit() after the outputting the PDF, otherwise your page continues to output the HTML.

<?php $dompdf = new \Dompdf\Dompdf(); $dompdf->loadHtml("Test"); $dompdf->setPaper('A4', 'landscape'); $dompdf->render(); $dompdf->stream(); exit(); ?>Output is TEXT base pdf (unreadable by acrobat reader). same as above output |!DOCTYPE html|...... <?php $dompdf = new \Dompdf\Dompdf(["pdf_backend" => "Cpdf"]); $dompdf->loadHtml("Test"); $dompdf->setPaper('A4', 'landscape'); $dompdf->render(); $dompdf->stream(); exit(); ?>Same too

If your code is after some HTML output (e.g. after header.php), you should add ob_clean() before your code.