Dompdf库多个分开的文件保存不起作用

huangapple go评论49阅读模式
英文:

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-&gt;load-&gt;library(&#39;pdf&#39;);
	$export_info_sql = &quot;SELECT * FROM offences_issued&quot;;
	$export_info_query = $this-&gt;db-&gt;query($export_info_sql);
	$export_info_result = $export_info_query-&gt;result();

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

	$directory_path = FCPATH.&quot;offences/&quot;.$counter.&quot;.pdf&quot;;	

	$query_html .= &quot;&lt;table width=100% border=1&gt;&quot;;
		$query_html .= &quot;&lt;tr&gt;&lt;th&gt;Offence ID&lt;/th&gt;&lt;/tr&gt;&quot;;
		$query_html .= &quot;&lt;tr&gt;&lt;td&gt;&quot;.$offence-&gt;issued_id.&quot;&lt;/td&gt;&lt;/tr&gt;&quot;;
	$query_html .= &quot;&lt;/table&gt;&quot;;

	$this-&gt;pdf-&gt;loadHtml($query_html);
	$this-&gt;pdf-&gt;setPaper(&#39;A4&#39;, &#39;portrait&#39;);
	$this-&gt;pdf-&gt;render();		
	$output = $this-&gt;pdf-&gt;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; }

huangapple
  • 本文由 发表于 2023年3月8日 16:16:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75670675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定