【问题标题】:domPDF inline PHPdomPDF 内联 PHP
【发布时间】:2012-01-31 05:28:42
【问题描述】:

我正在创建一个 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"

【问题讨论】:

    标签: php pdf pdf-generation dompdf


    【解决方案1】:

    我想你想用:

    $dompdf->load_html($file);
    

    而不是

    $dompdf->load_html_file($file);
    

    【讨论】:

    • 这让我开始工作,但现在它抛出了“价值数据”而不是实际内容。对此有什么想法吗?
    • @GeraldoIsaaks 听起来您处于不同的步骤(这仅涉及加载 DOM 结构 - 我猜您正在尝试获取一些特定的数据或节点)。您应该将代码和问题作为新问题发布。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2017-04-23
      • 1970-01-01
      • 2018-03-21
      • 2019-07-08
      • 2020-05-19
      • 1970-01-01
      • 1970-01-01
      • 2013-06-05
      • 2011-01-20
      相关资源
      最近更新 更多