简体   繁体   English

如何启用dompdf登录?

[英]How to enable log in dompdf?

I generating PDF files using dompdf in my PHP application. 我在PHP应用程序中使用dompdf生成PDF文件。
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 PDF尝试下载,但最终引发错误

C:\\Users\\xxx\\Downloads\\xxx.pdf.part could not be saved, because the source file could not be read. C:\\ Users \\ xxx \\ Downloads \\ xxx.pdf.part无法保存,因为无法读取源文件。 Try again later, or contact the server administrator. 请稍后再试,或与服务器管理员联系。

Now I want to file the error log in dompdf library file. 现在,我想将错误日志归档到dompdf库文件中。 Can anyone help me how to create log in log.htm file? 谁能帮助我如何在log.htm文件中创建日志? Thanks in advance. 提前致谢。

Regards, Sankar. 问候,桑卡尔。

I have the same issue, the try catch does not seem to catch the error. 我有同样的问题,try catch似乎没有捕获到错误。

I would open the corrupt PDF in a text editor - in my case what I saw were errors reported 我将在文本编辑器中打开损坏的PDF-就我而言,我看到的是报告了错误

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. 您看到的错误消息在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: 因此,如果您想捕获错误并将其记录下来,则应该能够将其包装在try块中,类似于:

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. 如果仍然不能解决问题,那么该错误将完全来自其他地方,您需要在其他地方进行搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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