Example - Page-Break-with-Header.fo

This section provides a tutorial example of an XSL-FO document structure, Page-Break-with-Header.fo, which declares a simple page layout with a body region and a header region. It also specifies a flow of blocks to be presented in the body region in a sequence of 2 pages with static header block on each page.

Now let's take a look at our second example, Page-Break-with-Header.fo, which represents an XSL-FO document with some simple features like page break and pager header:

<?xml version="1.1" encoding="utf-8"?>
<!-- Page-Break-with-Header.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="content" margin="0.5in">
   <fo:region-body region-name="body" margin-top="0.5in"/>
   <fo:region-before region-name="header" extent="0.5in"
    background-color="#eeeeee"/>
  </fo:simple-page-master>
 </fo:layout-master-set>
 <fo:page-sequence master-reference="content">
  <fo:static-content flow-name="header">
   <fo:block border-bottom-width="1px" border-bottom-style="solid" 
    text-align="end">Page-Break-with-Header.fo</fo:block>
  </fo:static-content>
  <fo:flow flow-name="body">
   <fo:block>Hello world!</fo:block>
   <fo:block break-before="page">Text on the new page...</fo:block>
  </fo:flow>
 </fo:page-sequence>
</fo:root>

Notes about this example:

We can run Apache FOP to process Page-Break-with-Header.fo into a PDF file, Page-Break-with-Header.pdf:

herong> fop -fo Page-Break-with-Header.fo -pdf Page-Break-with-Header.pdf

Then open Page-Break-with-Header.pdf with Adobe Acrobat Reader, and scroll to the second page, we will see the "Text on the new page..." message rendered on the second page with 0.5 inch margin and a nice header as shown below:

XSL-FO Example Output - Page-Break-with-Header.fo
XSL-FO Example Output - Page-Break-with-Header.fo

Table of Contents

 About This Book

 Introduction of XSL-FO

 Apache™ FOP (Formatting Objects Processor)

 RenderX XEP as an XSL-FO Tool

 Introduction of Area Model

XSL-FO Document Basics and Examples

 Document Top Level Structure Rules

 Example - hello.fo

Example - Page-Break-with-Header.fo

 Example - Cover-Page-and-Two-Columns.fo

 Page Layout Masters

 Block-Level Formatting Objects

 Inline-Level Formatting Objects

 Including Graphics in XSL-FO document

 Table of Rows and Columns

 List, Item, Label, and Body

 Floating Blocks - "float" and "footnote"

 Hyperlinks, Table of Contents and Indexes

 Headers and Footers using "static-content"

 Font Attributes and Font Families

 Apache FOP Font Configurations

 RenderX XEP Font Configurations

 Converting HTML to PDF

 References

 Full Version in PDF/ePUB