首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在DOMpdf目录外使用DOMpdf创建pdf

在DOMpdf目录外使用DOMpdf创建pdf
EN

Stack Overflow用户
提问于 2013-01-31 03:56:27
回答 2查看 12.5K关注 0票数 5

嗨,我已经在我的网站上安装了mybb。我还安装了dompdf,它在自己的目录下工作,即我已经安装在"DOM"目录下。现在,我可以使用这段简单的代码轻松地通用pdf,将其保存在"DOM"目录中。

代码语言:javascript
复制
<?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->render();$dompdf->stream("sample.pdf");

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-31 04:25:48

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

代码语言:javascript
复制
<?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

代码语言:javascript
复制
/**
 * 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);
票数 4
EN

Stack Overflow用户

发布于 2014-02-26 00:29:48

要启用远程访问,请勿编辑"dompdf_config.inc.php“。

请改用:

代码语言:javascript
复制
$dompdf = new DOMPDF();
$dompdf->set_option('enable_remote', TRUE);

$dompdf->set_option('enable_css_float', TRUE);
$dompdf->set_option('enable_html5_parser', FALSE);
票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14612531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档