John Giotta
John Giotta

Reputation: 16934

XSL-FO Render Has Region-Body at Top of Page. How do I fix?

I'm assuming that region-body should take place after region-before, but this isn't the case once I've transformed to PDF.

<fo:root>
    <fo:layout-master-set>
        <fo:simple-page-master master-name="simpleA4" page-height="11in" page-width="8.5in"
                               margin-left="0.5cm" margin-right="0.5cm">
            <fo:region-body />
            <fo:region-before region-name="xsl-region-before" extent="10mm"/>
            <fo:region-after region-name="xsl-region-after" extent="3cm"/>
        </fo:simple-page-master>
    </fo:layout-master-set>
    <fo:page-sequence master-reference="simpleA4">
        <fo:static-content flow-name="xsl-region-before">
            <fo:block>
              HEADER
            </fo:block>
        </fo:static-content>
        <fo:static-content flow-name="xsl-region-after">
          <fo:block>
            FOOTER
          </fo:block>
        </fo:static-content>
        <fo:flow flow-name="xsl-region-body">
          <fo:block space-after="5mm">
                <fo:table>
                    <fo:table-body>
                        <fo:table-cell>
                            <fo:block>
                                CELL 1
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block />
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block />
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block />
                        </fo:table-cell>
                    </fo:table-body>
                </fo:table>
            </fo:block>
        </fo:flow>
    </fo:page-sequence>
</fo:root>

Here is a screenshot of rendered output:

Example of rendered output

The region-after is working as expected.

Upvotes: 2

Views: 2087

Answers (1)

Mathias M&#252;ller
Mathias M&#252;ller

Reputation: 22617

You have not defined any margins for your body region and the page master does not have top or bottom margins either. That's why the body region flow starts simply at the top of the page. Here is some advice on this:

Important: The margins you set for the region-body must be greater than or equal to the extents of the the region-before and region-after (XML.com article)

Set top and bottom margins for your body region:

<fo:region-body margin-top="10mm"  margin-bottom="3cm"/>

XSL-FO Document

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <fo:layout-master-set>
        <fo:simple-page-master master-name="simpleA4" page-height="11in" page-width="8.5in"
                               margin-left="0.5cm" margin-right="0.5cm">
            <fo:region-body   margin-top="10mm"  margin-bottom="3cm"/>
            <fo:region-before region-name="xsl-region-before" extent="10mm"/>
            <fo:region-after region-name="xsl-region-after" extent="3cm"/>
        </fo:simple-page-master>
    </fo:layout-master-set>
    <fo:page-sequence master-reference="simpleA4">
        <fo:static-content flow-name="xsl-region-before">
            <fo:block>
              HEADER
            </fo:block>
        </fo:static-content>
        <fo:static-content flow-name="xsl-region-after">
          <fo:block>
            FOOTER
          </fo:block>
        </fo:static-content>
        <fo:flow flow-name="xsl-region-body">
          <fo:block space-after="5mm">
                <fo:table>
                    <fo:table-body>
                        <fo:table-cell>
                            <fo:block>
                                CELL 1
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block />
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block />
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block />
                        </fo:table-cell>
                    </fo:table-body>
                </fo:table>
            </fo:block>
        </fo:flow>
    </fo:page-sequence>
</fo:root>

Rendered PDF Result (FOP)

enter image description here

Try this solution online here, the transformation only copies everything and the result can be rendered as PDF.

Upvotes: 2

Related Questions