Search code examples
javapdfpdf-generationofbizapache-fop

Show content on only one page


I have three contents to render PDF(in sequence): C1, C2 and C3.

C1 and C3 can be rendered by more than one page. C2 need only one page.

The problem is the C3 render on the page of C2.

Is there any options or configurations to the page of C2 show only the content of C2?


Solution

  • (This answer is based on the premise you are using XSL-FO, deduced from the presence of the tag)

    If you use a different fo:page-sequence for each section of content, you are guaranteed that each one will begin at the beginning of a new page, even if the previous page would still have available space:

    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <fo:layout-master-set>
            ...
        </fo:layout-master-set>
        <fo:page-sequence master-reference="pages">
            ... C1 ...
        </fo:page-sequence>
        <fo:page-sequence master-reference="pages">
            ... C2 ...
        </fo:page-sequence>
        <fo:page-sequence master-reference="pages">
            ... C3 ...
        </fo:page-sequence>
    </fo:root>
    

    You can also use the properties break-before="page" or break-after="page" on fo:block elements to force page breaks, but I think the previous solution is more elegant.