0

我正在使用 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 个空白页之后

4

2 回答 2

3

这看起来是由于 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>
于 2013-12-17T15:36:00.467 回答
1

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

于 2018-02-28T20:23:51.553 回答