我正在尝试使用DOM pdf和Codeigniter创建PDF文件。我的控制器中有以下脚本,我将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>
答案 0 :(得分:2)
根据CodeIgniter documentation on views,您必须修改对load-&gt; view()的调用,以便将数据作为字符串返回给控制器,而不是推送到Web浏览器。尝试按如下方式修改控制器代码:
include_once('dompdf/dompdf_config.inc.php');
$html= $this->load->view('view_pdf','',true);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "landscape" );
$dompdf->render();
$dompdf->stream("my_pdf.pdf", array("Attachment" => 0));
我做的唯一更改是将必要的参数添加到$this->load->view()
。
(我不使用CodeIgniter。任何CI用户都有什么要添加的吗?)
答案 1 :(得分:0)
include_once('dompdf/dompdf_config.inc.php');
$this->load->view('view_pdf');
$html = $this->output->get_output();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "landscape" );
$dompdf->render();
$dompdf->stream("my_pdf.pdf", array("Attachment" => 0));