Chapter 12. Print customizations

Table of Contents

Document level properties
Title fonts and sizes
Book titles
Chapter titles
Other component titles
Section titles
Figure, table, and other titles
Print title pages
Title page attribute-sets
Title page spec file
Title page element templates
Custom title page layout
Template sequence for book title pages
Custom page design
Default page masters
Declaring custom page masters
Using custom page masters
Print TOC control
Page margins
TOC title
Styling print TOC entries
TOC page numbering
Editable table of contents
Running headers and footers
Default headers and footers
Changing the header or footer text
Running section titles
Graphic in header or footer
Multi-line header or footer
Changing header or footer styles
Allocating widths in the headers and footers
Allocating height for headers and footers
Page numbering style
Borders and background shading
Customizing inline text
Subscripts and superscripts
Customizing admonitions
Side floats
A sidebar as side float
Margin notes
Custom margin notes
Custom side float
Adding a font
Locate the font file
Configuring a font in FOP
Configuring a font in XEP
Adding a new font to FO output

Getting your printed output to look the way you want may require more DocBook customization than for HTML output. HTML output can be styled using a separate CSS stylesheet applied to the generated HTML files. For print output, you need to specify style properties in the DocBook XSL stylesheet for FO output. In Chapter 7, Printed output options you saw how to set parameters on the command line to change some formatting features. Given the number and type of parameters that need to be set, a customization layer makes more sense for print customization.

The basic framework for a print customization is an XSL stylesheet that imports the standard DocBook FO stylesheet and then adds your changes. Here is a simple example that just sets some page parameters.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:fo="http://www.w3.org/1999/XSL/Format"   
                version="1.0">

<xsl:import href="../../docbook-xsl-1.68.1/fo/docbook.xsl"/>

<xsl:param name="page.height.portrait">9in</xsl:param>
<xsl:param name="page.width.portrait">7in</xsl:param>
<xsl:param name="page.margin.inner">0.75in</xsl:param>
<xsl:param name="page.margin.outer">0.50in</xsl:param>
<xsl:param name="page.margin.top">0.17in</xsl:param>
<xsl:param name="page.margin.bottom">0.50in</xsl:param>

</xsl:stylesheet>

In addition to letting you set parameters, such a customization layer lets you add properties to attribute sets and customize individual stylesheet templates.

Document level properties

The root.properties attribute-set lets you assign XSL-FO properties that apply to the whole document. For example, you might want to globally turn off hyphenation, or print everything in blue type. By default, the stylesheet puts several important properties in this attribute set. Most of the property values can be changed with stylesheet parameters.

Table 12.1. root.properties attribute-set

FO propertyFrom stylesheet parameterDefault value
font-familybody.font.familyserif
font-sizebody.font.size10pt
text-alignalignmentjustify
line-heightline-heightnormal
font-selection-strategyNo parametercharacter-by-character

Generally you should use the appropriate parameter to reset any of these properties. But if you want to add new properties, you can do that by putting an attribute-set of the same name in your customization layer. Since attribute-sets of the same name are merged, your new properties will be added to the default properties. Here is an example that sets the font color to blue.

<xsl:attribute-set name="root.properties">
  <xsl:attribute name="color">blue</xsl:attribute>
</xsl:attribute-set>

When processed, the attributes in this attribute-set are placed in the fo:root element in the XSL-FO output:

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="serif" 
font-size="10pt" text-align="justify" line-height="normal" 
color="blue" font-selection-strategy="character-by-character"  
language="en">

The resulting PDF file will have all blue type. Keep in mind that only properties that are inheritable can be set this way. For example, the widows and orphans properties are inheritable and can be changed from their default values of 2. See a good XSL-FO reference to see which properties are inheritable. The root.properties attribute-set first appeared in version 1.61 of the stylesheets.