简体   繁体   中英

Page numbers in XSL-FO document

In my project XSL-FO is using to create PDF dynamicly. Documents are selected from grid/table and I can't predict it's number. All documents are printed as a one PDF. I need to add a page numbers for each sub-documents ie

  • 1st subdocument : 1/2, 2/2
  • 2nd subdocument : 1/3, 2/3, 3/3
  • 3rd subdocument : 1/1
  • ....

Code of my main PDF document, which produces page number in one sequence.

<xsl:import href="DocumentsUtils.DocumentsTemplates.DetailedProductionOrderTemplate.xsd"/>
<xsl:template match="/t:ArrayOfDeliveryDocumentModel">

<fo:page-sequence master-reference="simple" force-page-count="no-force">
    <fo:static-content flow-name="xsl-region-after" font-family="{$font}" font-size="9pt">
      <fo:block text-align="center">
        Page <fo:page-number/>
      </fo:block>
    </fo:static-content>
    <fo:flow page-sequence="xsl-region-body" font-family="{$font}" font-size="9pt">
      <xsl:apply-templates/>
        <fo:block id="last-page"/>
    </fo:flow>
  </fo:page-sequence>

Subdocument template

<xsl:template match="t:DeliveryDocumentModel">
<fo:block text-align="center" font-family="{$font}" break-before="page">
  <fo:table border-collapse="collapse" table-layout="fixed">
    <fo:table-column column-width="9.5cm" column-number="1"/>
    <fo:table-column column-width="9.5cm" column-number="2"/>
    <fo:table-body>
      <fo:table-row height="1cm" display-align="center">
        <fo:table-cell text-align="right" border-style="none" padding="0.5pt">
          <fo:block text-align="right" margin-right="1cm" font-weight="bold" font-size="11pt">
            <xsl:value-of select="t:DocumentNoHeader" /> : <xsl:value-of select="t:DocumentNo" />
          </fo:block>
        </fo:table-cell>
        <fo:table-cell text-align="left" border-style="none" padding="0.5pt">
          <fo:block text-align="left">
            <xsl:value-of select="t:DeliveryDateHeader" /> : <xsl:value-of select="extensions:FormatDateTime(t:DeliveryDate)" />
          </fo:block>
        </fo:table-cell>
      </fo:table-row>
    </fo:table-body>
.....

If it will be inpossible, could you help me to display a value from template in header ie order Id for each subdocument ? - 1st subdocument : Order Id : 1234 - 2nd subdocument : Order Id : 1235 - 3rd subdocument : Order Id : 1236 - ....

I did not do a test, I just coded in place as you did not post any XML. You should move the page-sequence generation into your t:DeliveryDocumentModel template as follows (with comments) to understand what each part is doing:

<xsl:template match="t:DeliveryDocumentModel">
<!-- create a varible unique to each document, use the count -->
<xsl:variable name="docnum" select="concat('doc_',count(preceding-sibling:t:DeliveryDocumentModel))"/>
<!-- set the initial page number to "1" -->
<fo:page-sequence master-reference="simple" force-page-count="no-force" initial-page-number="1">
    <fo:static-content flow-name="xsl-region-after" font-family="{$font}" font-size="9pt">
        <!-- reference the unique number for the last page it is on -->
        <fo:block text-align="center"> Page <fo:page-number/> of <fo:page-number-citation-last ref-id="{$docnum}"/>
        </fo:block>
    </fo:static-content>
    <!-- put the id on the flow, so the end of the flow will be on the last page of each page sequence -->
    <fo:flow page-sequence="xsl-region-body" font-family="{$font}" font-size="9pt" id="{$docnum}">
        <fo:block text-align="center" font-family="{$font}">
...

Essentially you put a unique id on each flow and each flow is inside a page-sequence for each document. You get the last page number of the flow now through page-number-citation-last. YOu also reset each page-sequence to start at "1". You should get 1 of 3 ... 1 of 2 ... 1 of 16 ... Oh and you can remove the break-before="page" on that block as the page-sequence is doing that for you.

For your page numbers, make a separate fo:page-sequence for each t:DeliveryDocumentModel and use initial-page-number="1" to restart the page number for each page sequence. See http://www.w3.org/TR/xsl/#initial-page-number

You can use fo:page-number-citation-last to get the page number of the last page in the pages generated from the fo:page-sequence .

By making a separate fo:page-sequence for each t:DeliveryDocumentModel , you can also put your order number in the fo:static-content for the fo:page-sequence .

Alternatively, you could add an fo:marker ( http://www.w3.org/TR/xsl/#fo_marker ) in the fo:flow FOs for each t:DeliveryDocumentModel and use an fo:retrieve-marker ( http://www.w3.org/TR/xsl/#fo_retrieve-marker ) in the fo:static-content . You should be able to extrapolate what you need from the "Thumb Index (marker, retrieve-marker)" example at http://www.antennahouse.com/antenna1/comprehensive-xsl-fo-tutorials-and-samples-collection/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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