【问题标题】:Align tfoot to bottom while generating a PDF file (flying-saucer/itext)生成 PDF 文件时将 tfoot 与底部对齐(飞碟/itext)
【发布时间】:2017-08-04 20:06:55
【问题描述】:

我正在使用 fly-saucer/itext 生成基于 HTML 的 PDF 文件,我遇到了向 PDF 文件添加页眉和页脚的问题。我最终做了一个带有 theader 和 tfooter 的 HTML 表格,如下所示:

<table>
<thead>
    <tr>
        <th>
            Header stuff
        </th>
    </tr>
</thead>
<tfoot>
    <tr>
        <th>
            Footer stuff
        </th>
    </tr>
</tfoot>
<tbody>
    <tr>
        <td>
            Content
        </td>
    </tr>
</tbody>
</table>

与 css 规则“table { -fs-table-paginate: paginate; }”一起,页眉和页脚正确分页。但是,我不能让页脚粘在页面底部:

如果表格内容填满页面,则页脚被推到底部:

有没有办法在 tbody 未满的情况下将页脚推到底部??

谢谢, 朱利安

【问题讨论】:

    标签: java pdf itext footer flying-saucer


    【解决方案1】:

    您应该使用CSS 3 Paged media 为PDF 添加页眉和页脚。 这将解决您的问题(在页面底部显示页脚),但也为您提供了很多不错的选项(页码、第一页的特定页眉......)

    这是基本模板:

    <html>
    <head>
        <style>
         #header { position: running(header); }
         #footer { position: running(footer); }
    
         @page {
           @top-center    { content: element(header); }
           @bottom-center { content: element(footer); }
         }
        </style>
    </head>
    <body>
        <div id='header'>Header stuff</div>
        <div id='footer'>Footer stuff</div>
    
        <table>
          <tbody>
              <tr>
                  <td>
                      Content
                  </td>
              </tr>
          </tbody>
        </table>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2021-03-25
      • 2016-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 2016-06-26
      • 2012-04-01
      相关资源
      最近更新 更多