XSL-FO Bookmarks

To make reading of electronic documnets handy and documents themselves easy to use bookmarks are used. A bookmark is an identifier used to access a part of a document. XSL-FO has three formatting objects for bookmarks:

  • <fo:bookmark-tree> holds a list of access points (identifiers) within a document (for example, a table of contents). Such access points are called bookmarks.
  • <fo:bookmark> is used to identify an access point with a unique name (title) and to specify its location within a document or outside it. A bookmark can be divided into a sequence of bookmarks (so-called sub-bookmarks).
  • <fo:bookmark-title> is used to identify an access point in readable form.

Here is a simple example of implementing bookmarks to a document:

  <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
   ...
   <fo:page-sequence master-reference="all-pages">
     ...
     <fo:flow flow-name="xsl-region-body">
       <fo:block id="s-1">
         Typical Xml2PDF workflow
       </fo:block>
       <fo:block id="ss-1_0">
         Table of Contents
       </fo:block>
       <fo:block id="ss-1_1">
         Why XML
       </fo:block>
       <fo:block>
         Extensible Markup Language (XML) is a simple and very flexible...
       </fo:block>
       <fo:block id="ss-1_2">
         Why PDF
       </fo:block>
       <fo:block>
         Free Adobe Reader guarantees that PDF will be viewed identically..
       </fo:block>
   </fo:page-sequence>

   <fo:bookmark-tree>
     <fo:bookmark internal-destination="s-1" starting-state="show">
       <fo:bookmark-title>Typical Xml2PDF workflow</fo:bookmark-title>
       <fo:bookmark internal-destination="ss-1_0">
         <fo:bookmark-title>Contents</fo:bookmark-title>
       </fo:bookmark>
       <fo:bookmark internal-destination="ss-1_1">
         <fo:bookmark-title>Why XML</fo:bookmark-title>
       </fo:bookmark>
       <fo:bookmark internal-destination="ss-1_2">
         <fo:bookmark-title>Why PDF</fo:bookmark-title>
       </fo:bookmark>
     </fo:bookmark>
   </fo:bookmark-tree>
  </fo:root>