英文:
Dompdf library multiple saperate files save not working
问题
你好,我理解你的要求,以下是你提供的代码的翻译部分:
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++;	
    }		
}
希望这有助于你解决问题。如果你有其他问题,可以随时提出。
英文:
Hello everyone I am facing a problem with dompdf in Codeigniter when I am trying to save multiple pdf files in a loop. It saves only one file but I need multiple files to save in the folder separately for each user.
I tried this
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;	
}
It shows this error
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
答案1
得分: 0
这解决了问题。
英文:
This fixed the problem
https://github.com/dompdf/dompdf/issues/902#issuecomment-431804432
html, body { display: block; }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论