[英]Generating a PDF using CodeIgniter
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:我正在使用dompdf从 html 文件中创建一个 pdf 文件,该文件是即时创建的,其唯一目的是用作 pdf 生成器的输入,但是我在执行此操作时遇到了麻烦,我在此实现了代码线程和一切正常(我可以 output 一个简单的 pdf)但是当我试图给它一个更具体的 url 我得到这个错误:
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');
}
you should use tcpdf to create a pdf.您应该使用 tcpdf 创建 pdf。 //create controller for example :
//例如创建控制器:
public function create_pdf()
{
$this->load->library("Pdf");
$data['results'] = // your data
$this->load->view('pdfview',$data);
}
//pdfview is the page having tcpdf code and your pdf code.
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. 1) 如 CI 手册所述,load->view 的第二个参数应该是关联数组或对象,通过提取转换为变量。 That may generate some problem generating $html.
这可能会产生一些生成 $html 的问题。
2) try making $path_url relative to application/views directory, as read in CI's manual. 2)尝试使 $path_url 相对于 application/views 目录,如 CI 手册中所述。
You can try it like this你可以这样试试
public function export_pdf() {
$filename = 'FILENAME.pdf';
header("Content-Description: Advertise Report");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/pdf; ");
$file = fopen('php://output', 'w');
$header = array("Question", "Answer", "Name", "Email", "Phone", "Date");
fputpdf($file, $header);
fputpdf($file, 'YOUR DATA');
fclose($file);
exit;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.