Search code examples
xsltxslt-2.0xsl-foapache-fop

How to insert a new page when a table inside a for each block overflows from the current page sequence in Apache fop


I am trying to create a pdf from an XML and i am very new to Apache fop

The first page has fixed data and varies from the tags in the input file. However the issue is with the rest of the pages. I have a table created for each SummaryDetails block from the XML as seen below. The for each runs in the inside the table of a page sequence. The code works perfectly with 2-3 SummaryDetails block and i get a 2 page PDF. However, if there are multiple SummaryDetails block, the 3rd page is not added and the pdf only has only 2 page with number of SummaryDetails block it can fit. In other words, i would want to add a new page inside the for each block when the page overflows so that all the SummaryDetails block is added in the PDF. Is there a possibility to do that?

There will be multiple such blocks in the input XML and i would like to create multiple pages. Assume each page can fit 2-3 summarydetails block.

XML:

    <SummaryDetails> 
    <SummaryDetail>
    <MediaType>P</MediaType>
    <T1>
    <T1ID>I</T1ID>
    <T2>
    <T2ID>T2</T2ID>
     <T3>
     <T3ID>T3</T3ID>
     </T3>
     </T2>
     /T1>
     </SummaryDetail>
     </SummaryDetails>

Layout block :

<fo:layout-master-set>
<fo:simple-page-master master-name="A4" page-height="29.7cm" page-width="21cm" margin-top="1.44cm" margin-bottom="1.25cm" margin-right="0.5cm">
<fo:region-body/>
</fo:simple-page-master>
<fo:simple-page-master  master-name="A4-first" page-height="29.7cm" page-width="21cm" margin-top="1.25cm" margin-bottom="1.25cm" margin-left="1.5cm" margin-right="0.5cm">
<fo:region-body region-name="body"/>
</fo:simple-page-master >
</fo:layout-master-set>

page sequence block for 2nd page :

<fo:page-sequence master-reference="A4-first" force-page-count="no-force" id="end">
<fo:flow flow-name="body">
<fo:block-container break-before="page" overflow="hidden" absoluteposition="absolute" margin-left="0.2cm" top="3.05cm" left="0in">
<fo:table width="100%" >
<fo:table-column column-width="5.4cm"/>
<fo:table-body>
<xsl:for-each select="SummaryDetails">
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block-container>
</fo:flow>
</fo:page-sequence>

Solution

  • The fo:block-container with overflow="hidden" and absoluteposition="absolute" (which should be absolute-position) would mean that when the fo:block-container fills up, your remaining content is somewhere past the bottom of the page but you can't see it because it is hidden.

    Try removing the fo:block-container (and, if necessary, putting the margin properties on the fo:table) and see what happens.