multiple pdf files with html2pdf

妖精的绣舞 提交于 2019-12-08 10:26:21

问题


I need to create multiple PDF file from a php loop... any ideas on how to do that? I try to use html2pdf but I get a tag error (the include file is working fine beacuse the single output is working!):

require_once('html2pdf.class.php');
$results = mysql_query("SELECT * FROM tbl ORDER BY id DESC LIMIT 10");
while ($row = mysql_fetch_assoc($results)) { 
$id=$row['id'];
       include('pdf.php');
        $content = ob_get_clean();
        try
        {
    $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-1'); 
    $html2pdf->setTestTdInOnePage(false);

    $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
            $Filename = "PDF_".$id.".pdf";
            $html2pdf->Output($Filename, 'F');
        }
        catch(HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
      }

ERROR I get:

File : /var/www/html/eco/_class/parsingHtml.class.php 
Line : 117 HTML code invalid, a tag is closed too many times: <table> 
HTML : ...</table> </td> <...

If I add ob_start(); before the include:

TCPDF ERROR: Unable to create output file: PDF_.pdf

Thanks


回答1:


Once again I solved on my own... Anyway I would like to post the solution for someone who will get the same problem:

require_once('html2pdf.class.php');
$results = mysql_query("SELECT * FROM tbl ORDER BY id ASC");
while ($row = mysql_fetch_assoc($results)) { 
ob_start();
<page>
.... HTML ....
</page>
         $content = ob_get_contents();
        try
        {
    $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-1'); 
    $html2pdf->setTestTdInOnePage(false);
    $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
    $Filename = "../folder/".$name.".pdf";
    $html2pdf->Output($Filename, 'F');
        }
        catch(HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
 $content_print .= ob_get_clean(); // add the content for the next document and now delete the output buffer 

   echo "<br> $name ...done!";
    echo str_pad('',4096)."\n";    //display some results so the page won't stay blank for too long
    ob_flush();
    flush();
    }
echo "all done!";


来源:https://stackoverflow.com/questions/32225465/multiple-pdf-files-with-html2pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!