1

我正在创建一个 PHP 脚本来将我的 HTML/CSS/PHP 页面转换为 PDF。我遇到了 domPDF 类,并且已将所有文件上传到我的服务器。我正试图解决这个问题,我已经编写了这个示例脚本,看看我是否可以让它工作。脚本是:

ob_start() ;

require_once("dompdf_config.inc.php");

$file= file_get_contents('http://www.yahoo.com');

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

我收到了这个错误:

"Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'Permission denied on <!DOCTYPE html> <html lang="en-US" class="y-fp-bg y-fp-pg-grad bkt701" style=""> <!-- m2 template --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Yahoo!</title> <meta http-equiv="X-UA-Compatible" content="chrome=1"> <meta name="description" content="Welcome to Yahoo!, the world's most visited home page. Quickly find what you're searching for, get in touch with friends and stay in-the-know with the latest news and information."> <meta name="keywords" content="yahoo, yahoo home page, yahoo homepage, yahoo search, yahoo mail, yahoo messenger, yahoo games, news, finance, sport, entertainment"> <script type="text/javascript"> //Roundtrip rtTop = Number(new Date()); document.documentElement.className += ' jsenabled'; </script> <script type="text/javascript"> (function () { //refresh check var d=document,c=";\ in /home/public_html/Sandbox/include/dompdf.cls.php on line 329"

4

2 回答 2

4

我想你想使用:

$dompdf->load_html($file);

而不是

$dompdf->load_html_file($file);
于 2011-12-31T22:23:05.043 回答
2

我不熟悉 domPDF,但从错误消息和函数名称来看,我假设load_html_file()需要一个文件名,但你给它的是 HTML 文件的内容。尝试$dompdf->load_html_file( 'http://www.yahoo.com' )或找到一个接受 HTML 字符串作为参数的函数。

于 2011-12-31T22:20:58.817 回答