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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3248199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:07:34  来源:igfitidea点击:

dompdf: loading html files to render, doesn't work

phpdompdf

提问by aneuryzm

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!

dompdf 无法从我网站的页面生成 pdf。但是,我保存了该页面并将其上传为简单的静态 html 文件,并且成功了!

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

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

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

警告: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 行

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");

回答by Wrikken

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

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

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

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

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

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

2) 不要让 DOMPDFeval而是使用输出缓冲本身,并让 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();
?>