Layout Sequence Example - Cover and Content

This section provides a tutorial example on how to use page-sequence-master to generate a cover and multiple content pages in a single page sequence.

As the first tutorial example of "page-sequence-master", I wrote the following XSL-FO document, Cover-and-Content-Layout-Sequence.fo, that uses two layouts, one for the cover page and one for other pages, to build a layout sequence:

<?xml version="1.1" encoding="utf-8"?>
<!-- Cover-and-Content-Layout-Sequence.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="cover" 
   margin-left="0.25in" margin-right="0.25in" 
   margin-top="1in" margin-bottom="1in" 
   page-height="2.3in" page-width="2.1in">
   <fo:region-body region-name="body" margin="0.25in"/>
  </fo:simple-page-master>
  <fo:simple-page-master master-name="page" margin="0.25in" 
   page-height="2.3in" page-width="2.1in">
   <fo:region-body region-name="body" margin="0.25in"
   background-color="#eeeeee"/>
   <fo:region-after region-name="footer" extent="0.2in"/>
  </fo:simple-page-master>
  <fo:page-sequence-master master-name="book">
   <fo:single-page-master-reference master-reference="cover"/>
   <fo:repeatable-page-master-reference master-reference="page"/>
  </fo:page-sequence-master>
 </fo:layout-master-set>
 <fo:page-sequence master-reference="book">
  <fo:static-content flow-name="footer">
   <fo:block font-size="8pt">herongyang.com</fo:block>
  </fo:static-content> 
  <fo:flow flow-name="body">
   <fo:block>RIVER BANK</fo:block>
   <fo:block>
    The Mole had been working very hard all the morning, 
    spring-cleaning his little home. First with brooms, then with 
    dusters; then on ladders and steps and chairs, with a brush and 
    a pail of whitewash; till he had dust in his throat and eyes, and
    splashes of whitewash all over his black fur, and an aching back 
    and weary arms. Spring was moving in the air above and in the 
    earth below and around him, penetrating even his dark and lowly 
    little house with its spirit of divine discontent and longing. 
    It was small wonder, then, that he suddenly flung down his brush 
    on the floor, said 'Bother!' and 'O blow!' and also 'Hang 
    spring-cleaning!' and bolted out of the house without even waiting
    to put on his coat...
   </fo:block>
  </fo:flow>
 </fo:page-sequence>
</fo:root>

When you process the above sample XSL-FO document to a PDF file and open it, you should see a number of pages with cover page's layout being different than other pages:

Layout Sequence Example - Cover and Content
Layout Sequence Example - Cover and Content

Note that in the above sample, putting the "cover" layout and the "page" layout into one layout sequence is not really a good idea, because it requires us to carefully design the "page-sequence/flow" to ensure that no book content gets presented on the cover page.

A better solution is to use the "cover" layout and the "page" layout separately with two "page-sequence" elements: one for the cover and one for other pages as shown below, Cover-and-Content-Layouts-Separated.fo. It will generate the same output as Cover-and-Content-Layout-Sequence.fo.

<?xml version="1.1" encoding="utf-8"?>
<!-- Cover-and-Content-Layouts-Separated.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="cover" 
   margin-left="0.25in" margin-right="0.25in" 
   margin-top="1in" margin-bottom="1in" 
   page-height="2.3in" page-width="2.1in">
   <fo:region-body region-name="body" margin="0.25in"/>
  </fo:simple-page-master>
  <fo:simple-page-master master-name="page" margin="0.25in" 
   page-height="2.3in" page-width="2.1in">
   <fo:region-body region-name="body" margin="0.25in"
   background-color="#eeeeee"/>
   <fo:region-after region-name="footer" extent="0.2in"/>
  </fo:simple-page-master>
 </fo:layout-master-set>
 <fo:page-sequence master-reference="cover">
  <fo:flow flow-name="body">
   <fo:block>RIVER BANK</fo:block>
  </fo:flow>
 </fo:page-sequence>
 <fo:page-sequence master-reference="page">
  <fo:static-content flow-name="footer">
   <fo:block font-size="8pt">herongyang.com</fo:block>
  </fo:static-content> 
  <fo:flow flow-name="body">
   <fo:block>
    The Mole had been working very hard all the morning, 
    spring-cleaning his little home. First with brooms, then with 
    dusters; then on ladders and steps and chairs, with a brush and 
    a pail of whitewash; till he had dust in his throat and eyes, and
    splashes of whitewash all over his black fur, and an aching back 
    and weary arms. Spring was moving in the air above and in the 
    earth below and around him, penetrating even his dark and lowly 
    little house with its spirit of divine discontent and longing. 
    It was small wonder, then, that he suddenly flung down his brush 
    on the floor, said 'Bother!' and 'O blow!' and also 'Hang 
    spring-cleaning!' and bolted out of the house without even waiting
    to put on his coat...
   </fo:block>
  </fo:flow>
 </fo:page-sequence>
</fo:root>

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

Page Layout Masters

 Layout Declarations

 simple-page-master - Simple Page Layout

 simple-page-master Attributes and Sub Elements

 simple-page-master/region-body Sub Element

 region-before and region-after Sub Elements

 region-start and region-end Sub Elements

 "Body" Region Margin and "Side" Region Extent

 Precedence of Side Region Corners

 Page Layout and Page Sequence Mapping

 What Is "page-sequence-master"

Layout Sequence Example - Cover and Content

 Wheat Is "repeatable-page-master-alternatives"?

 Layout Sequence Example - Odd and Even Pages

 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