gpt4 book ai didi

xsl-fo - Apache FOP 2.2 -> 2.3,分页

转载 作者:行者123 更新时间:2023-12-04 17:41:01 24 4
gpt4 key购买 nike

我在将 FOP 从 2.2 版迁移/升级到 2.3 版时遇到了问题。分页器停止工作...这是示例代码:

主要"template":

<xsl:stylesheet 
version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
exclude-result-prefixes="fo">
<fo:page-sequence
master-reference="templates/A4.xsl"
initial-page-number="1"
font-size="9pt"
font-weight="plain"
font-family="Arial"
>

<section id="footer" filename="templates/ftr_PgNmb.xsl" />

<fo:flow flow-name="xsl-region-body">

<fo:block >Page 1</fo:block>

<fo:block page-break-before="always"/>
<fo:block >Page 2</fo:block>

<fo:block page-break-before="always"/>
<fo:block>Page 3</fo:block>

<fo:block id="last-page" />

</fo:flow>

</fo:page-sequence>

分页器 1:

<xsl:stylesheet version="1.1" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
exclude-result-prefixes="fo"
>
<xsl:apply-templates select="templates/ftr_PgNmbTemplate.xsl"/>

分页器 2:

<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"
exclude-result-prefixes="fo">
<xsl:template match="templates/ftr_PgNmbTemplate.xsl">
<fo:static-content flow-name="xsl-region-after-firstpage">
<fo:block>
<fo:table table-layout="fixed" width="100%" border-collapse="separate">
<fo:table-column />
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block text-align="right">
Page <fo:page-number /> of <fo:page-number-citation-last ref-id="last-page"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
</fo:static-content>

<fo:static-content flow-name="xsl-region-after-otherpages">
<fo:block>
<fo:table table-layout="fixed" width="100%" border-collapse="separate">
<fo:table-column/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block text-align="right">
Page <fo:page-number /> of <fo:page-number-citation-last ref-id="last-page"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
</fo:static-content>

</xsl:template>

我得到的错误是:

SEVERE: Error while serializing page 1. Reason: java.io.NotSerializableException: org.apache.fop.fo.pagination.PageSequence java.io.NotSerializableException: org.apache.fop.fo.pagination.PageSequence at java.io.ObjectOutputStream.writeObject0(Unknown Source)

有什么提示吗?我一点头绪都没有。我所发现的只是问题出在 <fo:page-number-citation-last ref-id="last-page"/>称呼。如果删除了 PDF,就可以很好地创建它。有了它……不。

编辑:生成的完整 xsl:

java.io.NotSerializableException: org.apache.fop.fo.pagination.PageSequence

最佳答案

根据 FOP's help page about FO :

... To accomplish this in XSL 1.0, place an empty block with an id at the end of the flow:

<fo:flow ...>
...
<!-- block, NOT page-sequence -->
<fo:block id="last-page"/>
</fo:flow>

获取最后一页的页码如下:

<!-- page-number-citation, NOT page-number-citation-last !!! -->
<fo:page-number-citation ref-id="last-page"/>

This does not work in certain situations: multiple page sequences, an initial page number other than 1, or forcing a certain page count, thereby producing blank pages at the end.

In XSL 1.1, you get another option to do this: make sure an "id" is set on the page-sequence and reference it using fo:page-number-citation -last . First, the page-sequence:

<!-- page-sequence, NOT block-->
<fo:page-sequence id="seq1" ...

After that, reference the last page the page-sequence generates:

<!-- page-number-citation-last, NOT page-number-citation !! -->
<fo:page-number-citation-last ref-id="seq1"/>

Warning: There is no reliable way to get the real total page count with FO mechanisms. You can only get page numbers.


所以在你的情况下,请:

  1. 更改 <fo:page-number-citation-last/><fo:page-number-citation/> .
  2. 或者,引入一个 id="lastPage"你(最后)的属性page-sequence ,不是你的最后一个block , 然后你可以通过以下方式引用它:

    <fo:page-number-citation-last ref-id="last-page"/>`

关于xsl-fo - Apache FOP 2.2 -> 2.3,分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54504400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com