Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XSL-FO page


May 28, 2021 XSL-FO


Table of contents


XSL-FO page

This section is described in How the layout of pages in XSL-FO is formed.

XSL-FO uses a page template called "Page Masters" to define the layout of the page.


XSL-FO Page Templates

XSL-FO uses a page template called "Page Masters" to define the layout of the page. Each template must have a unique name:

<fo:simple-page-master master-name="intro">
<fo:region-body margin="5in" />
</fo:simple-page-master>

<fo:simple-page-master master-name="left">
<fo:region-body margin-left="2in" margin-right="3in" />
</fo:simple-page-master>

<fo:simple-page-master master-name="right">
<fo:region-body margin-left="3in" margin-right="2in" />
</fo:simple-page-master> 

In the example above, three elements, the simple-page-master-gt; element, define three different templates. Each template (page-master) has a different name.

The first template is named "intro". It can be used as a template for introductory pages.

The second and third templates are named "left" and "right". They can be used as page templates for even and odd page numbers.


XSL-FO Page Size (Page Size)

XSL-FO defines the size of the page using the following properties:

  • Page-width defines the width of the page
  • Page-height defines the height of the page

XSL-FO Page Margins

XSL-FO uses the following properties to define the margins of the page:

  • Margin-top defines the top margin
  • Margin-bottom defines the bottom margin
  • Margin-left defines the left margin
  • Margin-right defines the right margin
  • Margin defines margins for all edges

Tip: You can learn more about page margin properties in this site's CSS Properties!


XSL-FO Page Area (Page Regions)

XSL-FO defines the area of the page using the following elements:

  • Region-body defines the body area
  • region-before defines the top area (header)
  • region-after defines the bottom area (footer)
  • region-start defines the left area (left column)
  • Region-end defines the right-hand area (right column)

Note that region-before, region-after, region-start, and region-end are part of the main area. To prevent text from the body area from overwriting the text to those areas, the margin of the body area must be at least equal to the size of the other areas.

XSL-FO page


XSL-FO instance

This is a piece extracted from an XSL-FO document:

<fo:simple-page-master master-name="A4" page-width="297mm"
page-height="210mm" margin-top="1cm" margin-bottom="1cm"
margin-left="1cm" margin-right="1cm">
<fo:region-body margin="3cm"/>
<fo:region-before extent="2cm"/>
<fo:region-after extent="2cm"/>
<fo:region-start extent="2cm"/>
<fo:region-end extent="2cm"/>
</fo:simple-page-master> 

The code above defines a Simple Page Master Template with the name "A4".

The width of the page is 297 mm and the height is 210 mm.

The four margins of the page (top margin, bottom margin, left margin, right margin) are all 1 cm.

The margin of the body is 3 cm (all four sides are).

The body's before, after, start, and end regions are all 2 cm.

The width of the body in the instance above can be calculated by subtracting the left and right margins from the page width and the margins of the region-body:

297mm - (2 x 1cm) - (2 x 3cm) = 297mm - 20mm - 60mm = 217mm

Note that region-start and region-end are not counted in. As explained earlier, these areas are part of the body.

The above is a description of the XSL-FO page, which will be covered in the next section.