【问题标题】:domPDF - Table always going to bottom if reaching page heightdomPDF - 如果达到页面高度,表格总是会到底部
【发布时间】:2018-06-12 04:13:08
【问题描述】:

我正在使用 DOMPDF 生成 PDF 文件,但我遇到了一个小问题。
这是此模板的基本表格:

<!DOCTYPE html>
<html lang="pl">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>PDF</title>
</head>
<body>
    <table>
        <tbody>
            <tr>
                <td>
                    <h4>List 1:</h4>
                    <ol>
                        @foreach ($listArray_1 as $inv)
                            <li>{{ $inv->firstname }} {{ $inv->middlename }} {{ $inv->lastname }}</li>
                        @endforeach
                    </ol>
                </td>

                <td>
                    <h4>List 2:</h4>
                    <ol>
                        @foreach ($listArray_2 as $inv)
                            <li>{{ $inv->firstname }} {{ $inv->middlename }} {{ $inv->lastname }}</li>
                        @endforeach
                    </ol>
                </td>

                <td>
                    <h4>List 3:</h4>
                    <ol>
                        @foreach ($listArray_3 as $inv)
                            <li>{{ $inv->firstname }} {{ $inv->middlename }} {{ $inv->lastname }}</li>
                        @endforeach
                    </ol>
                </td>

                <td>
                    <h4>List 4:</h4>
                    <ol>
                        @foreach ($listArray_4 as $inv)
                            <li>{{ $inv->firstname }} {{ $inv->middlename }} {{ $inv->lastname }}</li>
                        @endforeach
                    </ol>
                </td>
            </tr>
        </tbody>
    </table>
</body>
</html>

但是,如果某些&lt;td&gt; 大于页面高度,它会使 2 个第一页空白并在第三页呈现剪切内容(剪切到页面末尾)。
问题出在哪里?在 CSS 或 DOM PDF 中? (我不能使用 wkhtmltopdf :/ )

【问题讨论】:

    标签: php html css dompdf


    【解决方案1】:

    使用另一个库的可能解决方案: 我使用 mPDF 来完成这项任务。我可以想象它在 mPDF 内部是一个非常困难的过程,但设法获得一个好的 pdf,使用可能跨越或不跨越多个页面的多个表。一切顺利。

    $mpdf = new \Mpdf\Mpdf(['tempDir' => __DIR__ . '/tmp']);
    $mpdf->shrink_tables_to_fit = false;
    $mpdf->WriteHTML( <<<HTML
    <style>    
    table
    {
         page-break-inside: avoid;
    }
    </style>
    <table>.... LONG table</table>
    <table>.... another table</table>
    <table>.... LONG table</table>
    HTML
    );
    

    `

    【讨论】:

      猜你喜欢
      • 2014-05-30
      • 2012-10-20
      • 1970-01-01
      • 2012-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-10
      相关资源
      最近更新 更多