dompdf生成的PDF在内容之间有许多空白页


dompdf generating PDF in with many blank pages between content

我使用DOMPDF从html生成pdf文件。正在生成PDF文件,但内容之间出现了许多空白页。以下是我的php代码。

<?php
    $html=file_get_contents("views/testnew.html");
//  echo $html;die();
    $paper_orientation = 'landscape';
    ob_start();
    require_once("dompdf/dompdf_config.inc.php");
    $pdfcontent = $html;
    $dompdf = new DOMPDF();
    $dompdf->set_paper('A4', $paper_orientation);
    $dompdf->load_html($pdfcontent);
    $dompdf->render();
//  $pdf = $dompdf->output();
    $pdf=$dompdf->stream("my_pdf.pdf", array("Attachment" => 0));
//  file_put_contents('Brochure.pdf', $pdf);
?>

以下是我正在用PDF文件编写的HTML

http://jsfiddle.net/6RmmB/

由于PDF正在生成,我认为PHP代码没有任何问题。html中一定有问题,但无法弄清楚到底是什么?

或者我在PHP代码中遗漏了什么?

"雇主识别号"旁边的内容出现在大约8-9页空白页之后。

这似乎是由于dompdf处理表单元格分页的错误造成的。如果删除外部表(该表的存在似乎只是为了提供边框),则页面将呈现得更好。然而,您可能仍然需要调整结构/样式,以获得您想要的。

例如,代替这个:

<table width="100%" border="0" cellpadding="0" cellspacing="0" id="" style="border:1px solid #ccc;color: #000;font-family: Arial,Helvetica,sans-serif;font-size:14px;">
    <tr>
        <td>
            <table width="100%" cellspacing="0" cellpadding="0" border="0" style="border-bottom:1px solid #ccc">
                <tr>
                    <td width="15%" align="left" valign="top" style="border-right:1px solid #ccc;padding:10px;line-height:20px">Form
                        <img src="/var/www/html/pm5/bodytechniques/working/development/version5/therapist/images/w9-form.JPG" width="83" height="37" style="margin-left:15px" />
                        <br>(Rev. August 2013)
                        <br>Department of the Treasury
                        <br>Internal Revenue Service</td>
                    <td width="69%" align="left" valign="top" style="border-right:1px solid #ccc;padding:10px;text-align:center;line-height:45px">
                        <h1 align="center">Request for Taxpayer Identification Number and Certification</h1>
                    </td>
                    <td width="16%" align="left" valign="top">
                        <h3 style="line-height:25px;padding:10px">Give Form to the requester. Do not send to the IRS</h3>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

这样做:

<div style="border:1px solid #ccc;color: #000;font-family: Arial,Helvetica,sans-serif;font-size:14px;">
    <table width="100%" cellspacing="0" cellpadding="0" border="0" style="border-bottom:1px solid #ccc">
        <tr>
            <td width="15%" align="left" valign="top" style="border-right:1px solid #ccc;padding:10px;line-height:20px">Form
                <img src="/var/www/html/pm5/bodytechniques/working/development/version5/therapist/images/w9-form.JPG" width="83" height="37" style="margin-left:15px" />
                <br>(Rev. August 2013)
                <br>Department of the Treasury
                <br>Internal Revenue Service</td>
            <td width="69%" align="left" valign="top" style="border-right:1px solid #ccc;padding:10px;text-align:center;line-height:45px">
                <h1 align="center">Request for Taxpayer Identification Number and Certification</h1>
            </td>
            <td width="16%" align="left" valign="top">
                <h3 style="line-height:25px;padding:10px">Give Form to the requester. Do not send to the IRS</h3>
            </td>
        </tr>
    </table>
</div>

当多个表不适合一个页面时,我会遇到问题。解决方案很简单,在表后添加<div style="clear: both;">