Table of Contents
More Resources
Adding a Footer
Footer
Customize your PDF output by adding a footer to your main content pages.
Editing a Footer Template
Edit the custom-xsl.xsl file to add a footer to your main content pages.
Adding Footer Attributes
Define attribute sets so that your footer displays as expected.
Adjusting the Footer Size
Adjust the size and alignment of your footer.
Footer

Customize your PDF output by adding a footer to your main content pages.
section
You can add a footer to your main content pages when publishing to PDF. Adding a footer to your PDF output requires:
You can also customize your footer by adding a Total Page Number and Adjusting the Footer Size.
Editing a Footer Template

Edit the custom-xsl.xsl file to add a footer to your main content pages.
context

You want to add a footer template in the custom-xsl.xsl file (located in cfg/fo/xsl/) to add a custom footer with specific footer text or the page number.

  1. To add a footer, you need to modify the “insertBodyOddFooter” XSL template. The default in org.dita.pdf2 uses the ‘Body odd footer’ variable and shows the footer content and page number:

    Step Information
    < xsl:template name="inserBodyOddFooter"> 
      < fo:static-content flow-name="odd-body-footer"> 
        < fo:block xsl:use-attribute-sets="__body__odd__footer"> 
          < xsl:call-template name="insertVariable"> 
            < xsl:with-param name="theVariableID" select="'Body odd footer'"/> 
            < xsl:with-param name="theParameters"> 
              < heading> 
                < fo:inline xsl:use-attribute-sets="__body__odd__header__heading"> 
                  < fo:retrieve-marker retrieve-class-name="current-header"/> 
                < /fo:inline> 
              < /heading> 
              < pagenum> 
                < fo:inline xsl:use-attribute-sets="__body__odd__footer__pagenum"> 
                  < fo:page-number/> 
                < /fo:inline> 
              < /pagenum> 
            < /xsl:with-param> 
          < /xsl:call-template> 
        < /fo:block> 
      < /fo:static-content> 
    < /xsl:template> 

  2. You’re going to change the template to show some text and the page number.
  3. Anything you want to put in the footer must be contained within the fo:static-content tag. And it is usually convenient to keep the fo:block as well due to the __body__odd__footer attribute-set:

    Step Information
    < xsl:template name="insertBodyOddFooter"> 
      < fo:static-content flow-name="odd-body-footer"> 
        < fo:block xsl:use-attribute-sets="__body__odd__footer"> 
          
        < /fo:block> 
      < /fo:static-content> 
    < /xsl:template> 

  4. To add footer text, you need to access two different variables (for the text and page number) and use the fo:leader to split them on opposite sites of the page.

    Step Information
    < fo:block xsl:use-attribute-sets="__body__odd__footer"> 
      < xsl:call-template name="insertVariable"> 
        < xsl:with-param name="theVariableID" select="'Custom Footer Text'"/> 
      < /xsl:call-template> 
      < fo:leader leader-pattern="space"/> 
      < xsl:call-template name="insertVariable"> 
        < xsl:with-param name="theVariableID" select="'Custom Page Number'"/> 
        < xsl:with-param name="theParameters"> 
          < pagenum> 
            < fo:page-number/> 
          < /pagenum> 
        < /xsl:with-param> 
      < /xsl:call-template> 
    < /fo:block> 
    
    Note:If you want to display the total page count (for example, “Page x of y”), you’ll need to use the Total Page Number guide.
  5. Combine all the code together into the footer template and add it to the custom-xsl.xsl file located at cfg/fo/xsl/:

    Example
    < xsl:template name="insertBodyOddFooter"> 
      < fo:static-content flow-name="odd-body-footer"> 
    
        < fo:block xsl:use-attribute-sets="__body__odd__footer"> 
          < xsl:call-template name="insertVariable"> 
            < xsl:with-param name="theVariableID" select="'Custom Footer Text'"/> 
          < /xsl:call-template> 
          < fo:leader leader-pattern="space"/> 
          < xsl:call-template name="insertVariable"> 
            < xsl:with-param name="theVariableID" select="'Custom Page Number'"/> 
            < xsl:with-param name="theParameters"> 
              < pagenum> 
                < fo:page-number/> 
              < /pagenum> 
            < /xsl:with-param> 
          < /xsl:call-template> 
        < /fo:block> 
    
      < /fo:static-content> 
    < /xsl:template> 
result

You added your custom footer template to the custom-xsl.xsl file located at cfg/fo/xsl/.

postreq
Your custom footer template contains new attribute-sets. See Adding Footer Attributes to define the new attribute and ensure your footer displays correctly.
Adding Footer Attributes

Define attribute sets so that your footer displays as expected.
prereq
Before you can add new attribute-sets, you must add a footer template using the procedure in Editing a Footer Template.
context

While Editing a Footer Template, you added the new attribute-set __body__odd__footer. You need to define this attribute-set in the custom-attrs.xsl file (located in cfg/fo/attrs/) for your footer to display correctly.

  1. The only attribute set that the footer requires is odd__footer. Add this code to your custom-attrs.xsl file:

    Step Information
    < xsl:attribute-set name="odd__footer"> 
      < xsl:attribute name="text-align-last"> justify< /xsl:attribute> 
      < xsl:attribute name="font-family"> sans-serif< /xsl:attribute> 
      < xsl:attribute name="font-size"> 10pt< /xsl:attribute> 
      < xsl:attribute name="font-weight"> regular< /xsl:attribute> 
      < xsl:attribute name="color"> #888< /xsl:attribute> 
      < xsl:attribute name="padding-top"> 3pt< /xsl:attribute> 
      < xsl:attribute name="padding-bottom"> 15pt< /xsl:attribute> 
      < xsl:attribute name="margin-left"> 
        < xsl:value-of select="$page-margins"/> 
      < /xsl:attribute> 
      < xsl:attribute name="margin-right"> 
        < xsl:value-of select="$page-margins"/> 
      < /xsl:attribute> 
    < /xsl:attribute-set> 
    You may notice that in the custom-xsl.xsl file, we used the __body__odd__footer attribute set, not the odd__footer attribute set. However, because the __body__odd__footer attribute set inherits all the attributes from odd__footer, and odd__footer is used more generally, so it is more useful to edit this attribute set.
result
Now that your footer attribute is set, see Setting Global Variables to set up your variables and have a footer output like this:
Adjusting the Footer Size

Adjust the size and alignment of your footer.
Let’s look at a sample footer to understand which attributes to modify to position your footer exactly where you want it. At the bottom of the page, a screenshot of the custom-attrs.xsl file displays each attribute used to adjust the footer dimensions.
E
The distance between the top of the footer and the bottom of the page
You’ll need to modify the “page-margin-botom” variable. This is defined outside any attribute-set in the root of the stylesheet. The default is 20mm.
F
The distance between the top of the footer and the top of the footer text
You’ll need to modify the “padding-top” attribute value of the “odd__footer” attribute set. Modifing this value will adjust the size of the footer, but not the vertical location of the footer (use E).
G
The distance between the bottom of the footer text and the bottom of the footer background
You’ll need to modify the “padding-bottom” attribute value of the “odd__footer” attribute set. This value can be relatively large to make sure that the footer background runs off of the bottom of the page.