在将FOP从2.2版迁移/升级到2.3版时,我遇到了一个问题。传呼机停止工作。。。这是示例代码:
主要"模板":
<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:序列化页1时出错。原因:java.io.NotSerializableException:org.apache.fop.fo.PageSequencejava.io.NotSerializableException:org.apache.fop.fo.PageSequence位于java.io.ObjectOutputStream.writeObject0(未知源)
有什么提示吗?我一点也不知道。我发现问题出在<fo:page-number-citation-last ref-id="last-page"/>
调用上。如果删除了,PDF就可以创建了。有了它…不。
编辑:完成xsl生成:
java.io.NotSerializableException: org.apache.fop.fo.pagination.PageSequence
根据FOP关于FO:的帮助页面
。。。要在XSL1.0中实现这一点,请在流的末尾放置一个带有id的空块:
<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"/>
此在某些情况下不起作用:多个页面序列、1以外的初始页码,或强制一定的页数,从而在末尾产生空白页。
在XSL 1.1中,您可以获得另一个选项:确保在页面序列上设置了"id">并引用它使用fo:页码引文-最后。首先,页面顺序:
<!-- page-sequence, NOT block-->
<fo:page-sequence id="seq1" ...
之后,引用页面序列生成的最后一页:
<!-- page-number-citation-last, NOT page-number-citation !! -->
<fo:page-number-citation-last ref-id="seq1"/>
警告:使用FO机制没有可靠的方法来获得实际的总页数。您只能获取页码
因此,在您的情况下,请:
- 将
<fo:page-number-citation-last/>
更改为<fo:page-number-citation/>
或者,在你的(最后一个)
page-sequence
上引入id="lastPage"
属性,而不是最后一个block
,然后你可以通过引用它<fo:page-number-citation-last ref-id="last-page"/>`