【问题标题】:Create pdf with DOM PDF outside DOMpdf directory在 DOMpdf 目录之外使用 DOM PDF 创建 pdf
【发布时间】:2013-01-30 19:56:27
【问题描述】:

您好,我的网站上安装了 mybb。我还安装了 dompdf 并且它在它自己的目录中工作,即我已经安装在 "DOM" 目录中。现在我可以用这个简单的代码轻松地通用 pdf,保存在 "DOM" 目录中。

<?php
require_once "dompdf_config.inc.php";
//$file = "www/test/css_at_font_face.html"; 
$file="msf.html";
$dompdf = new DOMPDF();
$dompdf->load_html_file($file);
$dompdf->render();
$dompdf->stream("sample.pdf");

?>

如果我尝试访问导演之外的其他文件 DOM

load_html_file($file); $dompdf->渲染(); $dompdf->stream("sample.pdf");

?> 我收到错误Remote file requested, but DOMPDF_ENABLE_REMOTE is false

【问题讨论】:

    标签: php directory dompdf


    【解决方案1】:

    为了启用远程访问不要编辑“dompdf_config.inc.php”

    改用:

    $dompdf = new DOMPDF();
    $dompdf->set_option('enable_remote', TRUE);
    
    $dompdf->set_option('enable_css_float', TRUE);
    $dompdf->set_option('enable_html5_parser', FALSE);
    

    【讨论】:

      【解决方案2】:

      在不启用远程文件访问的情况下加载 html:

      <?php
      require_once "dompdf_config.inc.php";
      $file = "www/test/css_at_font_face.html"; 
      $html=file_get_contents($file);
      $dompdf = new DOMPDF();
      $dompdf->load_html($html);
      $dompdf->render();
      $dompdf->stream("sample.pdf");
      
      ?>
      

      启用远程文件访问:

      取自 dompdf_config.inc.php

      /**
       * Enable remote file access
       *
       * If this setting is set to true, DOMPDF will access remote sites for
       * images and CSS files as required.
       * This is required for part of test case www/test/image_variants.html through www/examples.php
       *
       * Attention!
       * **This can be a security risk**, in particular in combination with DOMPDF_ENABLE_PHP and
       * allowing remote access to dompdf.php or on allowing remote html code to be passed to
       * $dompdf = new DOMPDF(); $dompdf->load_html(...);
       * This allows anonymous users to download legally doubtful internet content which on
       * tracing back appears to being downloaded by your server, or allows malicious php code
       * in remote html pages to be executed by your server with your account privileges.
       *
       * @var bool
       */
      def("DOMPDF_ENABLE_REMOTE", true);
      

      【讨论】:

      • 跟进,“远程”是指使用完整 URL(包括域部分)的任何文件。即使域与访问 domdpf 的域相同也是如此。
      猜你喜欢
      • 1970-01-01
      • 2015-05-18
      • 1970-01-01
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 2017-08-19
      • 1970-01-01
      相关资源
      最近更新 更多