简体   繁体   English

无法在 XSL-FO 中设置初始页码

[英]Unable to set initial page number in XSL-FO

I am having a problem with the way XSL-FO handles page numbering.我对 XSL-FO 处理页码的方式有疑问。 In my application, I'm using Apache FOP to transform XML into PNG content.在我的应用程序中,我使用 Apache FOP 将 XML 转换为 PNG 内容。 This PNG content is then "appended" to content from TIFF files to create the appearance of a single, continuous document.然后将此 PNG 内容“附加”到来自 TIFF 文件的内容以创建单个连续文档的外观。 One of our requirements is to add page numbers to the PNG content.我们的要求之一是向 PNG 内容添加页码。 The catch, however, is that the page numbering needs to begin as if it was in sequence, ie, if there are 2 pages of TIFF content, the first PNG page would be page 3.然而,问题是页面编号需要按顺序开始,即如果有 2 页 TIFF 内容,第一个 PNG 页将是第 3 页。

Calculating the number of pages of TIFF content is easy and I pass it into the transformer as a parameter.计算 TIFF 内容的页数很容易,我将其作为参数传递给转换器。

// setup XSLT
TransformerFactory factory = javax.xml.transform.TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xslFile));
transformer.setParameter("tiffPgOffset", getTiffPgOffset());

and I added the parameter to my XSL file to handle the page offset count.并且我将该参数添加到我的 XSL 文件中以处理页面偏移计数。

   <xsl:param name="tiffPgOffset" />

I can access the parameter value inside the page just fine.我可以很好地访问页面内的参数值。

  <fo:static-content flow-name="xsl-region-after" font-family="Arial">
    <fo:block font-size="16">Page 
      tiffPgOffset = <xsl:value-of select="$tiffPgOffset" />   <!-- it works here -->
    </fo:block>
  </fo:static-content>

The problem occurs when I want to pass the parameter value to the page-sequence object.当我想将参数值传递给页面序列对象时会出现问题。 Given what I had read, I thought that this should work:鉴于我所阅读的内容,我认为这应该有效:

 <fo:page-sequence master-reference="main" initial-page-label="$tiffPgOffset">   <!-- this does not work -->

but it doesn't.但事实并非如此。 Instead, I get the following run-time error:相反,我收到以下运行时错误:

Invalid property encountered on "fo:page-sequence": initial-page-label (No context info available)

I'm not sure what I'm doing wrong, but I'm hoping it will be painfully obvious to someone who has more experience with this.我不确定我做错了什么,但我希望这对有更多经验的人来说会很明显。 Thanks in advance.提前致谢。

尝试在initial-page-number属性中使用AVT

initial-page-number="{$tiffPgOffset}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM