带有html2pdf的多个pdf文件 [英] multiple pdf files with html2pdf

查看:194
本文介绍了带有html2pdf的多个pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从一个php循环中创建多个PDF文件...有关如何执行此操作的任何想法? 我尝试使用html2pdf,但出现标签错误(因为单个输出正常,包含文件工作正常!):

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

我得到错误:

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

如果我在包含之前添加 ob_start(); :

If I add ob_start(); before the include:

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

谢谢

推荐答案

再一次我自己解决了...无论如何,我想将解决方案发布给遇到相同问题的人:

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!";

这篇关于带有html2pdf的多个pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆