使用CodeIgniter生成PDF

wydwbb8l  于 2022-12-06  发布在  其他
关注(0)|答案(3)|浏览(171)

我正在使用dompdf从HTML文件创建一个PDF文件,该文件是在运行中创建的,唯一的目的是作为PDF生成器的输入,但是我在这样做时遇到了麻烦,我在this thread中实现了代码,一切都工作正常(我可以输出一个简单的PDF),但是当我试图给予它一个更具体的URL时,我得到了这个错误:
无法加载模块:Public到这里去看看!
下面是出现问题的代码:

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');
        }
68de4m5k

68de4m5k1#

不确定确切的问题,但请检查以下内容:
1)如CI手册中所述,load-〉view的第二个参数应该是一个关联数组或对象,通过extract转换为vars。
2)尝试将$path_url设置为相对于application/views目录,如CI手册中所述。

yjghlzjz

yjghlzjz2#

你应该使用tcpdf来创建一个pdf。//create控制器例如:

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.
csbfibhn

csbfibhn3#

你可以这样试试

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;
}

相关问题