Skip to content Skip to navigation

OpenStax-CNX

You are here: Home » Content » XSL-FO page layouts

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

In these lenses

  • xsl-fo display tagshide tags

    This module is included inLens: XSL Formatting Objects
    By: Hannes Hirzel

    Comments:

    "Basic layout example"

    Click the "xsl-fo" link to see all content selected in this lens.

    Click the tag icon tag icon to display tags associated with this content.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.
 

XSL-FO page layouts

Module by: Hannes Hirzel. E-mail the author

Summary: This modules gives examples how layouts are defined in XSL FO (XSL Formatting Objects).

Introduction

In the element fo:layout-master-set and its children called page-masters the page layouts are defined.

Page-masters have the role of describing the intended subdivisions of a page and the geometry of these subdivisions. In the examples given in this module there is only one page-master element - the fo:simple-page-master element. When using it in an XSL-FO document all pages will have that layout.

The following examples are simple but complete layout specifications. Only one page layout called 'simple' is specified.

Examples

Minimal example (A4 page)

<fo:layout-master-set>

    <fo:simple-page-master 
        master-name="simple"
        page-width="210mm" 
        page-height="297mm">

        <fo:region-body/>

    </fo:simple-page-master>

</fo:layout-master-set>
[Source]

With two columns

<fo:layout-master-set>

    <fo:simple-page-master 
        master-name="simple"
        page-width="210mm" 
        page-height="297mm">

        <fo:region-body column-count="2" />

    </fo:simple-page-master>

</fo:layout-master-set>

Note:

In the content if you want for example a title to span both columns you have to include it in a fo block with the attribute span="all".

With margins specified

Definition of page size and margins

<fo:layout-master-set>
    <fo:simple-page-master master-name="simple"
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1cm"
                  margin-bottom="2cm"
                  margin-left="2.5cm"
                  margin-right="2.5cm">
    </fo:simple-page-master>
 </fo:layout-master-set>

With header (region-before) and footer (region-after)

Definition of page with header and footer

<fo:layout-master-set>

    <fo:simple-page-master master-name="simple"
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1cm"
                  margin-bottom="2cm"
                  margin-left="2.5cm"
                  margin-right="2.5cm">

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

      <fo:region-before extent="3cm"/>

      <fo:region-after extent="1.5cm"/>

    </fo:simple-page-master>
 
 </fo:layout-master-set>
 

Note:

The space for the header and footer is taken from the <fo:region-body /> area. Thus this has to be compensated in the definition of <fo:region-body /> by adding margins of at least the extent of the header (margin-top="3cm") and footer (margin-bottom="1.5cm").

Complete XSL-FO file with simple layout

The following code is the layout-master-set from above used for a complete XSL-FO example XML file. The paratemers 'margin-top' and 'margin-bottom' have been set to 0. Only 'region-body' is used for content. It results in the body area having a margin of 2cm everywhere.

<?xml version="1.0" encoding="utf-8"?>

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">



<fo:layout-master-set>

    <fo:simple-page-master master-name="simple"
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="0cm"
                  margin-bottom="0cm"
                  margin-left="2cm"
                  margin-right="2cm">

      <fo:region-body margin-top="2cm"
                                margin-bottom="2cm"/>

      <fo:region-before extent="2cm"   background-color="yellow"/>

      <fo:region-after extent="2cm"  background-color="red"/>

    </fo:simple-page-master>
 
 </fo:layout-master-set>





  <fo:page-sequence master-reference="simple">

    <fo:flow flow-name="xsl-region-body">

      <fo:block font-size="10mm">'hello' in 'region-body'      
      </fo:block>
      
    </fo:flow> 
  </fo:page-sequence> 



</fo:root>

Execute on the command line fop verySimpleLayout.fo verySimpleLayout.pdf

The result in a PDF viewer

Screen shot of pdf viewer with very simple FO layout

Another example

<?xml version="1.0" encoding="utf-8"?>

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

<fo:layout-master-set>

    <fo:simple-page-master master-name="simple"
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="0cm"
                  margin-bottom="0cm"
                  margin-left="1.5cm"
                  margin-right="1.5cm">

      <fo:region-body margin-top="1.7cm"
                                margin-bottom="1.5cm"   
                                column-count="5" column-gap="1mm" />

      <fo:region-before extent="1.7cm"   background-color="white"/>

      <fo:region-after extent="1.5cm"  background-color="white"/>

    </fo:simple-page-master>
 
 </fo:layout-master-set>


  <fo:page-sequence master-reference="simple">

    <fo:flow flow-name="xsl-region-body" text-align="center" font-size="30mm" font-weight="bold">
                


<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="red">
<fo:block>A</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="blue">
<fo:block>B</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="green">
<fo:block>C</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="orange">
<fo:block>D</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="brown">
<fo:block>E</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="purple">
<fo:block>F</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="red">
<fo:block>G</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="blue">
<fo:block>H</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="green">
<fo:block>I</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="orange">
<fo:block>J</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="brown">
<fo:block>K</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="purple">
<fo:block>L</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="red">
<fo:block>M</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="blue">
<fo:block>N</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="green">
<fo:block>O</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="orange">
<fo:block>P</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="brown">
<fo:block>Q</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="purple">
<fo:block>R</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="red">
<fo:block>S</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="blue">
<fo:block>T</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="green">
<fo:block>U</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="orange">
<fo:block>V</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="brown">
<fo:block>W</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="purple">
<fo:block>X</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="red">
<fo:block>Y</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="blue">
<fo:block>Z</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="green">
<fo:block>A</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="orange">
<fo:block>A</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="purple">
<fo:block>A</fo:block></fo:block-container>

<fo:block-container height="38mm" padding-top="4mm" border-style="solid"  border-color="#DDD" color="red">
<fo:block>A</fo:block></fo:block-container>
      
    </fo:flow> 
  </fo:page-sequence> 
</fo:root>

XSL-FO-ABC-chart.png

Noteworthy elements

To get the five columns column-count="5" column-gap="1mm" is used in the definition of <region-body>.

To get the same height for all the boxes a block-container is used

<fo:block-container height="38mm" >
<fo:block>A</fo:block>
</fo:block-container>

Content actions

Download module as:

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks