Java 在使用ApacheFop创建的PDF中添加索引页
我已经使用ApacheFop编写了一个应用程序,它生成了包含多个章节的PDF。有没有一种方法,我可以知道-哪一章出现在哪一页。实际上,我需要在开始时创建索引,它告诉我哪一章出现在哪一页上。您可以在需要知道页码的元素上放置一个ID,然后用Java 在使用ApacheFop创建的PDF中添加索引页,java,pdf-generation,xsl-fo,apache-fop,Java,Pdf Generation,Xsl Fo,Apache Fop,我已经使用ApacheFop编写了一个应用程序,它生成了包含多个章节的PDF。有没有一种方法,我可以知道-哪一章出现在哪一页。实际上,我需要在开始时创建索引,它告诉我哪一章出现在哪一页上。您可以在需要知道页码的元素上放置一个ID,然后用引用它 例如: 在包含章节标题的每个块上放置一个带有自动生成ID的ID: <xsl:for-each select="chapter"> <fo:block id="{generate-id(.)}"> <xs
引用它
例如:
<xsl:for-each select="chapter">
<fo:block id="{generate-id(.)}">
<xsl:value-of select="@title"/>
</fo:block>
</xsl:for-each>
<xsl:for-each select="chapter">
<fo:block id="{generate-id(.)}">
<fo:page-number-citation ref-id="{generate-id(.)}"/>
</fo:block>
</xsl:for-each>
索引(这里更像是目录)是否在实际内容之前生成并不重要,因为ID是由XSL解析器计算的,FOP在页面布局之后解析这些引用(从而解析页码)已确定。您只需在需要知道页码的元素上添加ID,然后使用
引用即可
例如:
<xsl:for-each select="chapter">
<fo:block id="{generate-id(.)}">
<xsl:value-of select="@title"/>
</fo:block>
</xsl:for-each>
<xsl:for-each select="chapter">
<fo:block id="{generate-id(.)}">
<fo:page-number-citation ref-id="{generate-id(.)}"/>
</fo:block>
</xsl:for-each>