Using dompdf in Custom Files with "Includes common files" option

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
madjid
User
Posts: 1

Using dompdf in Custom Files with "Includes common files" option

Post by madjid »

Hello everyone,

I hope this message finds you well. I am writing to seek assistance regarding an issue I am facing while using the dompdf library in a Custom File with the "Includes common files" option enabled. I am attempting to generate a PDF file using dompdf, but I have encountered some difficulties.

To provide you with a clearer picture, here is the code I have used in the Custom File:

<!DOCTYPE html>
<html>
<body>

<?php
// Include autoloader
require_once 'vendor/autoload.php';
// Reference the Dompdf namespace
use Dompdf\Dompdf;
// Instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->set_option('defaultFont', 'sans-serif');
// Load HTML content
$dompdf->loadHtml('Hello World');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
?>
</body>
</html>

Despite executing this code, I am encountering an error message stating "Failed to load PDF document" when attempting to load the PDF file.

I would greatly appreciate any assistance or guidance you can provide to help me resolve this issue. If there are any additional steps or considerations I should be aware of when using dompdf in Custom Files with the "Includes common files" option, please let me know.

Thank you for your attention and support.


arbei
User
Posts: 9286

Post by arbei »

In your usage you should put your code in Page_Load or Page_Render server event, not in the Content which is supposed to be HTML to be viewed in browser.


Post Reply