XSL-FO Tutorials - Herong's Tutorial Examples - v2.25, by Herong Yang
Page Header in region-before Area
This section provides a tutorial example on how to generate page headers using a block-container in a static-content of the page-sequence, and mapped to the region-before in the layout.
If you want to generate page headers with XSL-FO documents, you need to following guidelines:
1. Declare a simple-page-master layout with region-before in addition to region-body, if you want page headers to show up on the "before" edge of the page.
2. Specify region-before[@extent] wide enough to hold the header content.
3. Specify region-body[@margin-top] wider than region-before[@extent], so that page body content does not overlap with the page header.
4. Add a static-content formatting object inside the page-sequence that uses the layout.
5. Specify static-content[@flow-name] with the region-before[@region-name] value from the layout.
6. Add a block formatting object inside the static-content to generate page header content.
7. If you want a line to separate page header from page body, you can turn on the bottom border of the block.
8. If you want to lower the header content to the bottom of the region-before area, you can wrap the header content in a block-container of the same height and display-align="after".
Here is my tutorial example, Page-Header-in-region-before.fo, that generates page headers using a block-container in a static-content of the page-sequence, and mapped to the region-before in the layout:
<?xml version="1.0" encoding="utf-8"?> <!-- Page-Header-in-region-before.fo - Copyright (c) 2006 HerongYang.com. All Rights Reserved. --> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> <fo:simple-page-master master-name="my_page" margin="0.1in" page-height="3.3in" page-width="2.55in"> <fo:region-body region-name="my_body" background-color="#eeeeee" margin-top="0.4in"/> <fo:region-before region-name="my_header" background-color="#ffeeee" extent="0.3in"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="my_page"> <fo:static-content flow-name="my_header"> <fo:block-container height="0.3in" display-align="after"> <fo:block text-align="end" font-size="9pt" border-bottom-width="1px" border-bottom-style="solid"> Page <fo:page-number/> </fo:block> </fo:block-container> </fo:static-content> <fo:flow flow-name="my_body"> <fo:block text-align="center" margin-top="6pt" font-weight="bold">Little Snow-White </fo:block> <fo:block text-align="justify" margin-top="6pt"> Once upon a time in midwinter, when the snowflakes were falling like feathers from heaven, a queen sat sewing at her window, which had a frame of black ebony wood. As she sewed she looked up at the snow and pricked her finger with her needle. Three drops of blood fell into the snow. The red on the white looked so beautiful that she thought to herself, "If only I had a child as white as snow, as red as blood, and as black as the wood in this frame." </fo:block> <fo:block text-align="justify" margin-top="6pt"> Soon afterward she had a little daughter who was as white as snow, as red as blood, and as black as ebony wood, and therefore they called her Little Snow-White. And as soon as the child was born, the queen died. </fo:block> </fo:flow> </fo:page-sequence> </fo:root>
If you process this example XSL-FO document with Apache FOP to a PDF file, you will see a simple page header displayed on all pages:
Table of Contents
Apache™ FOP (Formatting Objects Processor)
XSL-FO Document Basics and Examples
Block-Level Formatting Objects
Inline-Level Formatting Objects
Including Graphics in XSL-FO document
Floating Blocks - "float" and "footnote"
Hyperlinks, Table of Contents and Indexes
►Headers and Footers using "static-content"
►Page Header in region-before Area
Page Headers for Multiple Chapters
Font Attributes and Font Families
Apache FOP Font Configurations