简体   繁体   中英

How to enable log in dompdf?

I generating PDF files using dompdf in my PHP application.
Here is the code:

<?php
require_once("dompdf/dompdf_config.inc.php");   
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("XXX.pdf");
return $dompdf;
?>

When I click the download button; PDF tries to download but finally it throws an error

C:\\Users\\xxx\\Downloads\\xxx.pdf.part could not be saved, because the source file could not be read. Try again later, or contact the server administrator.

Now I want to file the error log in dompdf library file. Can anyone help me how to create log in log.htm file? Thanks in advance.

Regards, Sankar.

I have the same issue, the try catch does not seem to catch the error.

I would open the corrupt PDF in a text editor - in my case what I saw were errors reported

Warning: mb_convert_encoding():

That should give you a clue about how to proceed.

The error message you are seeing does not exist in the current source code of dompdf.

Looking through other errors seems to reveal that they're almost always exceptions .

Therefore, if you want to capture the error and log it, you should just be able to wrap it in a try block, similar to this:

require_once("dompdf/dompdf_config.inc.php");   
try {
    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();
    $dompdf->stream("XXX.pdf");
    return $dompdf;
} catch(Exception $e) {
// Do something here with $e and notify the user of the error in whatever way you see fit
}

If this isn't grabbing the error you're experiencing, make sure you're using the latest version. If that still doesn't help, then that error is coming from somewhere else entirely and you'll need to search elsewhere for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM