【问题标题】:multiple pdf files with html2pdf带有html2pdf的多个pdf文件
【发布时间】:2015-08-26 11:31:09
【问题描述】:

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

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();

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

谢谢

【问题讨论】:

  • 请写出错误
  • 请编辑您的问题以包含您收到的确切错误消息。确保触发错误的代码行包含在您的问题中,并指出它是哪一行。
  • 这可能是由于不正确的 HTML 与 html2pdf 不兼容造成的。我建议你改用mPDF,因为它对这些功能有了很大的改进。
  • 这意味着我必须重做所有的 PDF/php 文件……这是一个非常复杂的文件,如果不使用循环,效果很好……

标签: php pdf html2pdf


【解决方案1】:

我又一次自己解决了......无论如何,我想为遇到同样问题的人发布解决方案:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-01
    • 2011-04-21
    • 1970-01-01
    • 1970-01-01
    • 2015-11-19
    相关资源
    最近更新 更多