我正在创建一个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"
答案 0 :(得分:4)
我想你想用:
$dompdf->load_html($file);
而不是
$dompdf->load_html_file($file);
答案 1 :(得分:2)
我不熟悉domPDF,但是根据错误消息和函数名称来判断,我假设load_html_file()
需要一个文件名,但你给它的是内容 HTML文件。尝试$dompdf->load_html_file( 'http://www.yahoo.com' )
或找到接受HTML字符串作为参数的函数。