【问题标题】:Show different footers on first and consecutive pages with pisa/xhtml2pdf使用 pisa/xhtml2pdf 在第一页和连续页上显示不同的页脚
【发布时间】:2012-01-20 20:56:07
【问题描述】:

让页脚在 Pisa 文档的第一页上显示为一个框架,并在每隔一页显示为另一个框架时遇到了一些问题。我试图从 here 改编 lastPage 的想法,但没有运气。

可以这样做吗? <pdf:nextpage /> 在这里似乎不是正确的事情,因为该文档有一个可能(或可能不会)流过多个页面的长表。 <pdf:nextframe /> 加上仅首页的框架看起来很有希望,尽管我不确定如何准确使用它。

目前我有(为简洁起见):

<style type="text/css">
  @page {
    margin: 1cm;
    margin-bottom: 2.5cm;
    @frame footer {
      -pdf-frame-content: footerFirst;
      -pdf-frame-border: 1;
      bottom: 2cm;
      margin-left: 1cm;
      margin-right: 1cm;
      height: 1cm;
   }
   @frame footer {
      -pdf-frame-content: footerOther;
      bottom: 2cm;
      margin-left: 1cm;
      margin-right: 1cm;
      height: 1cm;
}
</style>
<body>
  <table repeat="1">
    <!-- extra long table here -->
  </table>
  <div id="footerContent">This is a footer</div>
  <!-- what goes here to switch frames after the first page? -->
  <div id="footerOther"></div>
</body>

这会在每一页上放置相同的页脚。我需要在每个连续页面上留下相同的空间,但框架中没有内容。

【问题讨论】:

    标签: footer pisa xhtml2pdf


    【解决方案1】:

    您可以通过名称定义其他布局,然后使用 nexttemplate 标记告诉 xhtml2pdf 显式切换到它们。我最近这样做是为了在我的第一页上没有标题,但在所有后续页面上都显示它。

    您应该将@page 定义更改为两个不同的页面,可能是这样的:

    <style type="text/css">
      @page {
        margin: 1cm;
        margin-bottom: 2.5cm;
        @frame footer {
          -pdf-frame-content: footerFirst;
          -pdf-frame-border: 1;
          bottom: 2cm;
          margin-left: 1cm;
          margin-right: 1cm;
          height: 1cm;
       }
     }
    
     @page innerpages {
       margin: 1cm;
       margin-bottom: 2.5cm;
       @frame footer {
          -pdf-frame-content: footerOther;
          bottom: 2cm;
          margin-left: 1cm;
          margin-right: 1cm;
          height: 1cm;
       }
     }
    </style>
    

    然后,在你想要切换到不同布局的 html 中,使用这样的标签:

    <pdf:nexttemplate name="innerpages"/>
    

    下一页(以及您再次更改模板之前的后续页面)将使用带有“其他”页脚的内页布局。

    【讨论】:

    • 我遇到了相反的问题:更改最后一页的页脚。有没有类似的解决方案?谢谢
    • @Don:这是相同的解决方案 - 为您的最后一页制作不同的模板,然后使用 标签在最后一页之前切换到它,就像上面一样。
    • 但是我如何判断我是否在最后一个页面之前的页面上? (我不知道有多少行适合一页,所以我无法预测文档将有多少页......)
    • @Don:您将最后一页设为自己的模板,并在准备好时切换到该模板。如果您尝试将动态内容放在最后一页上,而该页面可能总是有内容,也可能不总是有内容,那么您可能需要更花哨。我有一个当前的产品,它在输出的行和行之后有一个特殊的最后一页 - 而不是试图将最后一行放到特殊页面上,我们只是自己运行最后一页 - 不知道这是否有助于您的情况或不是。
    猜你喜欢
    • 1970-01-01
    • 2018-12-28
    • 2012-01-02
    • 2016-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-24
    相关资源
    最近更新 更多