PHP - DOMPDF 1 函数有效,另一个则无效
我目前正在使用 DOMPDF,并试图找出为什么我的 PDF 没有正确创建。
当我运行以下代码时,
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename, $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->set_base_path($_SERVER['DOCUMENT_ROOT']);
$dompdf->output_html();
//$dompdf->load_html($html);
//$dompdf->set_paper("a4", "portrait" );
//$dompdf->render();
//$dompdf->stream($filename . ".pdf");
}
?>
在浏览器中我看到了我期望生成的 PDF 内容,但是如果我运行此代码,
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename, $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->set_base_path($_SERVER['DOCUMENT_ROOT']);
//$dompdf->output_html();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "portrait" );
$dompdf->render();
$dompdf->stream($filename . ".pdf");
}
?>
我不会得到任何响应,而我期望得到一个下载窗口。这是有原因的吗?我想知道格式不正确的 HTML 是否会导致问题?
I am working with DOMPDF currently, and I trying to work out why my PDF's are not being created correctly.
When I run the following code,
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename, $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->set_base_path($_SERVER['DOCUMENT_ROOT']);
$dompdf->output_html();
//$dompdf->load_html($html);
//$dompdf->set_paper("a4", "portrait" );
//$dompdf->render();
//$dompdf->stream($filename . ".pdf");
}
?>
In my browser I see the PDF content that I expect to be generated, however if I run this code,
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename, $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->set_base_path($_SERVER['DOCUMENT_ROOT']);
//$dompdf->output_html();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "portrait" );
$dompdf->render();
$dompdf->stream($filename . ".pdf");
}
?>
I get no repsonse, where I would be expecting to get a download window. Is there a reason for this, I wonder if poorly formatted HTML could the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 CI 插件代码应该可以在 1.7.x 上运行。心意如下,供大家参考:
Your CI plugin code should work on 1.7.x. Here's mind for your reference: