使用 CodeIgniter 生成 PDF
我正在使用 dompdf 从 html 文件创建一个 pdf 文件,该文件是动态创建的它的目的是作为 pdf 生成器的输入,但是我在执行此操作时遇到了麻烦,我在 这个线程中实现了代码 一切正常(我可以输出一个简单的 pdf),但是当我尝试给它一个更具体的 url 时,我收到此错误:
遇到错误,无法 加载请求的文件
这是有问题的代码:
function printPDF(){
//write_file() usa un helper (file)
$this->load->library('table');
$this->load->plugin('to_pdf');
// page info here, db calls, etc.
$query = $this->db->get('producto');
$data['table'] = $this->table->generate($query);
$path_url = base_url().'print/existencias.html';
write_file($path_url, $data['table']);
$html = $this->load->view($path_url, 'consulta', true);
pdf_create($html, 'consulta');
}
I am using dompdf to create a pdf file out of an html file that gets created on-the-fly for the sole purpose of it serving as input for the pdf generator, however I am having trouble doing this, I implemented the code in this thread and everything works fine (I could output a simple pdf) however when I try to give it a more specific url I get this error:
An Error Was Encountered Unable to
load the requested file
here's the code that has the problem:
function printPDF(){
//write_file() usa un helper (file)
$this->load->library('table');
$this->load->plugin('to_pdf');
// page info here, db calls, etc.
$query = $this->db->get('producto');
$data['table'] = $this->table->generate($query);
$path_url = base_url().'print/existencias.html';
write_file($path_url, $data['table']);
$html = $this->load->view($path_url, 'consulta', true);
pdf_create($html, 'consulta');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不确定确切的问题,但请检查一下:
1)如CI手册中所述,load->view的第二个参数应该是关联数组或对象,通过extract转换为vars。这可能会在生成 $html 时产生一些问题。
2) 尝试使 $path_url 相对于 application/views 目录,如 CI 手册中所述。
Not sure about the exact problem, but please check this:
1) as stated in CI's manual, load->view's second parameter should be an associative array or an objet, translated to vars via extract. That may generate some problem generating $html.
2) try making $path_url relative to application/views directory, as read in CI's manual.
您应该使用 tcpdf 创建 pdf。
//创建控制器例如:
you should use tcpdf to create a pdf.
//create controller for example :
你可以这样尝试
You can try it like this