加载 Codeigniter 的视图文件时,DOM PDF 不起作用
我正在尝试使用 DOM pdf 和 Codeigniter 创建 PDF 文件。我的 Controller 中有以下脚本,并且我将 DOM 文件夹保留在我的控制器中。但是当我运行脚本时,我收到致命错误消息。
但是当我将模型中的值发送到控制器中的 DOMPDF 的 $html 时..我可以生成 pdf。
您能帮我解决这个错误吗?
include_once('dompdf/dompdf_config.inc.php');
$html= $this->load->view('view_pdf');
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "landscape" );
$dompdf->render();
$dompdf->stream("my_pdf.pdf", array("Attachment" => 0));
这是我的查看文件;
<html>
<head>
<style>
#header { position: absolute; left: 0; top: -50px; right: 0; height: 140px; text-align: center; }
#footer {position: fixed ; left: 0px; bottom: -20px; right: 0px; height: 30px; font-size:10; }
#footer .page:after { content: counter(page, upper-roman); }
#table-6 {
width: 100%
border: 1px solid #B0B0B0;
}
#table-6 tbody {
/* Kind of irrelevant unless your .css is alreadt doing something else */
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
#table-6 td {
padding: 3px 10px;
font-size: 12px;
font-weight: normal;
text-align:center;
}
#table-6 tr:nth-child(even) {
background: #F2F2F2;
font-size: 12px;
font-weight: normal;
}
</style>
</head>
<body>
This is a test
</body>
</html>
I am trying to create PDF file using DOM pdf and Codeigniter. I have the following script in my Controller and I have kept the DOM folder inside my controller . But when I run the script I get fatal error message.
But when I send a value from my model to DOMPDF's $html which is in my controller .. I can generate the pdf.
Could you please kindly help me how to get rid of this error?
include_once('dompdf/dompdf_config.inc.php');
$html= $this->load->view('view_pdf');
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "landscape" );
$dompdf->render();
$dompdf->stream("my_pdf.pdf", array("Attachment" => 0));
This is my View File ;
<html>
<head>
<style>
#header { position: absolute; left: 0; top: -50px; right: 0; height: 140px; text-align: center; }
#footer {position: fixed ; left: 0px; bottom: -20px; right: 0px; height: 30px; font-size:10; }
#footer .page:after { content: counter(page, upper-roman); }
#table-6 {
width: 100%
border: 1px solid #B0B0B0;
}
#table-6 tbody {
/* Kind of irrelevant unless your .css is alreadt doing something else */
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
#table-6 td {
padding: 3px 10px;
font-size: 12px;
font-weight: normal;
text-align:center;
}
#table-6 tr:nth-child(even) {
background: #F2F2F2;
font-size: 12px;
font-weight: normal;
}
</style>
</head>
<body>
This is a test
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 CodeIgniter 关于视图的文档,您必须修改对 load->view 的调用() 以便数据作为字符串返回到控制器,而不是推送到 Web 浏览器。尝试按如下方式修改控制器代码:
我所做的唯一更改是将必要的参数添加到
$this->load->view()
。(我不使用 CodeIgniter。CI 用户有什么要补充的吗?)
According to the CodeIgniter documentation on views you have to modify your call to load->view() so that the data is returned as a string to the controller rather than pushed to the web browser. Try modifying your controller code as follows:
The only change I made was to add the necessary parameters to
$this->load->view()
.(I don't use CodeIgniter. Do any CI users have anything to add?)