dompdf:加载要渲染的 html 文件,不起作用

发布于 2024-09-09 03:06:39 字数 870 浏览 5 评论 0原文

dompdf 无法从我的网站页面生成 pdf。不过,我已经保存了该页面并将其作为简单的静态 html 文件上传,并且它有效!

所以,我不知道问题是否出在 url 上,还是其他什么问题。这是我得到的错误:

警告:require_once(/home/o110334/public_html/dompdf/include/firephp.cls.php)[function.require-once]:无法打开流:/home/o110334/public_html/中没有这样的文件或目录dompdf/dompdf_config.inc.php 第 194 行

致命错误:require_once() [function.require]:无法打开所需的“/home/o110334/public_html/dompdf/include/firephp.cls.php”(include_path='.:/usr/lib/php:/ usr/local/lib/php') 在 /home/o110334/public_html/dompdf/dompdf_config.inc.php 第 194 行

这是代码:

$file = "admin/store/orders/45/invoice/print"; // doesn't work
//$file = "invoice_sample2.html"; //it works (same web page, but stored in a html file)

$dompdf = new DOMPDF();
$dompdf->load_html_file($file);
$dompdf->render();
$dompdf->stream("sample.pdf");

dompdf is not able to generate a pdf from a page of my website. However, I've saved the page and uploaded it as simple static html file, and it worked!

So, I don't know if the issue is with the url, or something else.. this is the error I get:

Warning: require_once(/home/o110334/public_html/dompdf/include/firephp.cls.php) [function.require-once]: failed to open stream: No such file or directory in /home/o110334/public_html/dompdf/dompdf_config.inc.php on line 194

Fatal error: require_once() [function.require]: Failed opening required '/home/o110334/public_html/dompdf/include/firephp.cls.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/o110334/public_html/dompdf/dompdf_config.inc.php on line 194

This is the code:

$file = "admin/store/orders/45/invoice/print"; // doesn't work
//$file = "invoice_sample2.html"; //it works (same web page, but stored in a html file)

$dompdf = new DOMPDF();
$dompdf->load_html_file($file);
$dompdf->render();
$dompdf->stream("sample.pdf");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往昔成烟 2024-09-16 03:06:39

DOMPDF 在本地运行时会尝试各种东西/评估,你最好尝试:

1)通过 http 请求 HTML(当然,长途旅行):

$dompdf->load_html_file('http://yourdomain.ext/'.$file);

2)不要让 DOMPDF eval 但使用输出缓冲本身,并让 DOMPDF 加载生成的 HTML 字符串。

<?php
    ob_start();
    //be sure this file exists, and works outside of web context etc.)
    require("admin/store/orders/45/invoice/print");
    $dompdf = new DOMPDF();
    $dompdf->load_html(ob_get_clean());
    $dompdf->render();
?>

DOMPDF is trying all kinds of stuff/eval's when running local, you're better of trying:

1) the (granted, long way trip) of requesting the HTML by http:

$dompdf->load_html_file('http://yourdomain.ext/'.$file);

2) Don't let DOMPDF eval but use output buffering itself, and let DOMPDF load the resulting string of HTML.

<?php
    ob_start();
    //be sure this file exists, and works outside of web context etc.)
    require("admin/store/orders/45/invoice/print");
    $dompdf = new DOMPDF();
    $dompdf->load_html(ob_get_clean());
    $dompdf->render();
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文