【问题标题】:DOMPDF table headerDOMPDF 表头
【发布时间】:2014-08-13 04:01:18
【问题描述】:

制作方法

<tr>
            <th>a</th>
            <th>b</th>
            <th>c</th>
            <th>d</th>
            <th>e</th>
        </tr>

始终可在每一页上打印。

我的观点

<style>
             @page { margin: 150px 50px; }
             #header { position: fixed; left: 0px; top: -100px; right: 0px; height: 50px; text-align: center; }
             #footer { position: fixed; left: 0px; bottom: -180px; right: 0px; height: 150px; text-align: center; }
             #footer .page:after { content: counter(page, upper-roman); }
           </style>

        <div id="header">
             <h1>Tittle</h1>
           </div>

        <div id="content">
        <?php
        echo"<table class='gridtable'>";
        ?>
    <table width="100%" page-break-inside: auto;>

            <tr>
            <th>a</th>
            <th>b</th>
            <th>c</th>
            <th>d</th>
            <th>e</th>
        </tr>


        <?php
        $num = 0;
        foreach($result as $key=>$val){
            $num++;
                echo"<tr>
                            <td>".$a."</td>".
                            "<td>".$val['b']."</td>".
                            "<td>".$val['c']."</td>".
                            "<td>".$val['d']."</td>".
                            "<td>".$val['e']."</td>".
                            "</tr>";
        }
        ?>
        </table>
        <?php
        echo"</table>";
        ?>
        </div>
        <script type="text/php">

            if ( isset($pdf) ) {

              $font = Font_Metrics::get_font("helvetica", "bold");
              $pdf->page_text(280, 780, "Page {PAGE_NUM} of {PAGE_COUNT}", $font, 10, array(0,0,0));

            }
            </script>

例如,这是我下载后的 PDF

第一页:

| Title 1 | Tittle 2 | Tittle 3 |
| row 1   | row 1    | row 1    |

第二页:

| row 2   | row 2    | row 2    |

如何制作这样的第二页​​:

| Title 1 | Tittle 2 | Tittle 3 |
| row 2   | row 2    | row 2    |

我希望标题总是打印在每一页的顶部。谢谢你

【问题讨论】:

  • 请详细说明您的问题

标签: html codeigniter


【解决方案1】:

在最新版本的 DOMPDF(例如,0.5.2 版或更高版本,我相信)中,您可以将包含表格标题的行包装在 THEAD 中。

将您的视图更改为:

<table width="100%" page-break-inside: auto;>
    <thead>
        <tr>
            <th>a</th>
            <th>b</th>
            <th>c</th>
            <th>d</th>
            <th>e</th>
       </tr>
   <thead>

这应该可以解决问题。有一种情况会失败:如果您的表格在您的thead 之后但在任何数据行被渲染之前被渲染,则thead 将不会显示在下一页上。如果表格跨越另一个页面,thead 将显示在后续页面上。

【讨论】:

  • 顺便说一句,如果你想修复上面提到的“一个案例”,请编辑 table_row_group_frame_decorator.cls.php 并从第 55 行开始更改代码: if ( $child === $this->get_first_child () ) { $cellmap->remove_row_group($this);父::拆分();返回; } to if ( $child === $this->get_first_child() ) { $cellmap->remove_row_group($this);父::拆分($child);返回;我不知道是否还有其他副作用,但它对我有用。
  • 版本是什么?还是 DMPDF 还是 DOMPDF?
  • 对不起,错字。它应该是 DOMPDF。当我说“最近”时,我认为它应该是 0.5.2 或更高版本。我一直在使用 0.6.0 beta 版本。更新了答案以反映这一点。
猜你喜欢
  • 1970-01-01
  • 2021-03-11
  • 1970-01-01
  • 1970-01-01
  • 2013-05-22
  • 1970-01-01
  • 2013-10-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多