Search code examples
xsltxsl-foapache-fop

XSLFO - displaying header and footer


Am converting xml to PDF using XSL FO. I want to display Header contents in the below format

Header Contents

Line 1               Line 1.1
Line 2               Line 1.2
Line 2               Line 1.3

Right now, am trying with the below lines of code :

 <fo:block> Line 1 </fo:block> <fo:block>   Line 1.1 </fo:block>
 <fo:block> Line 2 </fo:block> <fo:block>   Line 1.2 </fo:block>
 <fo:block> Line 3 </fo:block> <fo:block>   Line 1.3 </fo:block>

Solution

  • If you want locate "Line 1" aligned to the left of the header and "Line 1.1" aligned to the right of the header, there is no need to use tabular layout. Below example uses fo:leader object to accomplish this requirement.

        <fo:static-content flow-name="xsl-region-before" font-size="9pt">
            <fo:block space-before="2mm" space-before.conditionality="retain" space-after="2mm"  border-bottom="2pt solid green">
                <fo:block text-align-last="justify">Line 1<fo:leader leader-length.maximum="100%" leader-pattern="space"/>Line 1.1</fo:block>
                <fo:block text-align-last="justify">Line 2<fo:leader leader-length.maximum="100%" leader-pattern="space"/>Line 1.2</fo:block>
                <fo:block text-align-last="justify">Line 3<fo:leader leader-length.maximum="100%" leader-pattern="space"/>Line 1.3</fo:block>
            </fo:block>
        </fo:static-content>
    

    The FOP formatting result: FOP Formatting result