【问题标题】:mPDF - Show table footer (tfoot) only oncemPDF - 仅显示一次表格页脚 (tfoot)
【发布时间】:2018-07-03 08:34:51
【问题描述】:

我正在使用Kartik's mPDF extension for Yii2 从 HTML 表创建一个 PDF 文件。 表格页脚在所有页面中都可见,但我希望它只显示在整个表格的末尾(在最后一页中)。

我怎样才能做到这一点?我正在使用GridViewArrayDataProvider 创建表。

display: table-row-group; is not supported by mPDF for tfoot element 因此无法在 PDF 中工作。

【问题讨论】:

  • 添加一些代码。

标签: php yii2 mpdf kartik-v table-footer


【解决方案1】:

我找到了一个需要更改表的解决方案。

我没有在页脚中使用tfoot 元素,而是在tbody 中添加一行带有页脚数据的行并为其添加样式。 由于 mPDF 不支持:last-child 选择器,我不得不使用支持的:nth-child() 选择器:

$pdf->cssInline = 'tbody tr:nth-child(' . $row_count . ') td { font-weight: bold; }';

我通过在数据数组上调用count() 添加附加行后设置$row_count。为了在 GridView 中显示正确的总项目数,我添加了 $row_count 值减 1 的自定义布局:

$pdf->content = GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => $this->columns,
    'showFooter' => false,
    'layout' => '
        <div>' . Yii::t('app', 'Total <strong>{count}</strong> items.', ['count' => ($this->row_count - 1)]) . '</div>
        {items}
    '
]);

生成的 PDF 文件在表格前具有正确的项目计数,并且仅在表格的最后端具有正确样式的“页脚”。

我希望我的解决方案对其他人有所帮助。如果您找到了更好的解决方案,请发布答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-04
    • 1970-01-01
    • 2016-07-24
    • 2012-07-10
    • 2012-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多