codeigniter Dompdf库多个独立文件保存不工作

bihw5rsg  于 2023-03-10  发布在  其他
关注(0)|答案(1)|浏览(107)

大家好,当我试图在循环中保存多个PDF文件时,我在Codeigniter中遇到了dompdf的问题。它只保存一个文件,但我需要为每个用户分别保存多个文件到文件夹中。
"我试过了“

public function export_information(){

    $this->load->library('pdf');
    $export_info_sql = "SELECT * FROM offences_issued";
    $export_info_query = $this->db->query($export_info_sql);
    $export_info_result = $export_info_query->result();

    $query_html = "";
    $counter = 1;
    foreach ($export_info_result as $offence) {         

    $directory_path = FCPATH."offences/".$counter.".pdf";   

    $query_html .= "<table width=100% border=1>";
        $query_html .= "<tr><th>Offence ID</th></tr>";
        $query_html .= "<tr><td>".$offence->issued_id."</td></tr>";
    $query_html .= "</table>";

    $this->pdf->loadHtml($query_html);
    $this->pdf->setPaper('A4', 'portrait');
    $this->pdf->render();       
    $output = $this->pdf->output();

        if (!file_exists($directory_path)) {            
            file_put_contents($directory_path, $output);
        }

    $counter++; 

    }       
    // echo $query_html;
    // exit;    

}

显示此错误

An uncaught Exception was encountered
Type: Dompdf\Exception

Message: No block-level parent found. Not good.

Filename: D:\xampp\htdocs\project101\application\libraries\dompdf\src\Positioner\Inline.php

Line Number: 44

Backtrace:

File: D:\xampp\htdocs\project101\application\libraries\dompdf\src\FrameDecorator\AbstractFrameDecorator.php
Line: 873
Function: position

File: D:\xampp\htdocs\project101\application\libraries\dompdf\src\FrameReflower\Inline.php
Line: 51
Function: position

File: D:\xampp\htdocs\project101\application\libraries\dompdf\src\FrameDecorator\AbstractFrameDecorator.php
Line: 894
Function: reflow

File: D:\xampp\project101\project101\application\libraries\dompdf\src\FrameReflower\Page.php
Line: 141
Function: reflow

File: D:\xampp\htdocs\project101\application\libraries\dompdf\src\FrameDecorator\AbstractFrameDecorator.php
Line: 894
Function: reflow

File: D:\xampp\htdocs\project101\application\libraries\dompdf\src\Dompdf.php
Line: 842
Function: reflow

File: D:\xampp\htdocs\project101\application\controllers\Portal.php
Line: 45
Function: render

File: D:\xampp\htdocs\project101\index.php
Line: 315
Function: require_once
yizd12fk

yizd12fk1#

这解决了问题

https://github.com/dompdf/dompdf/issues/902#issuecomment-431804432

html, body { display: block; }

相关问题