使用 pisa/xhtml2pdf 在第一页和连续页上显示不同的页脚

发布于 2024-12-28 14:57:17 字数 1252 浏览 2 评论 0原文

我在让页脚在 Pisa 文档的第一页上显示为一个框架,并在每个其他页面上显示为另一个框架时遇到一些问题。我尝试改编此处的lastPage想法,但没有成功。

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

目前我有(为了简洁而剪掉):

<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>

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

I'm having some trouble getting a footer to appear as one frame on the first page of a Pisa document, and as another frame on every other page. I have attempted to adapt the lastPage idea from here, but with no luck.

Is it possible to do this? <pdf:nextpage /> doesn't seem to be the right thing here since the document has a long table that may (or may not) flow over multiple pages. <pdf:nextframe /> plus a first-page-only frame looks promising, though I'm not sure how to use this exactly.

Currently I have (snipped for brevity):

<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>

This places the same footer on each page. I need the same space left on each consecutive pages, but with no content in the frame.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦幻的味道 2025-01-04 14:57:17

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

您应该将 @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"/>

下一页(以及后续页面,直到您再次更改模板)将使用内页布局与“其他”页脚。

You can define additional layouts by name, then tell xhtml2pdf to switch to them explicitly using the nexttemplate tag. I did exactly this recently to have no header on my first page but to show it on all the subsequent pages.

You should change your @page definition to two different pages, perhaps like this:

<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>

Then, in your html where you want to switch to the different layout, use a tag like this:

<pdf:nexttemplate name="innerpages"/>

The next page (and subsequent pages until you change the template again) will use the innerpages layout with your 'other' footer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文