DITA to PDF Output Customization

In this topic you will see how to do a basic customization of the PDF output by setting up a customization directory.

DITA Open Toolkit PDF output customizations can be made in two major ways:
  1. Creating a DITA Open Toolkit plugin which adds extensions to the PDF plugin. More details can be found in the DITA Open Toolkit user manual.
  2. Creating a customization directory and using it from the PDF transformation scenario. A small example of this procedure can be found below.

Let us take for example the common case of embedding a company logo image in the front matter of the book. You can later extend this example to create more complex customizations.

  1. Copy the entire directory: [OXYGEN_DIR]/frameworks/dita/DITA-OT/plugins/org.dita.pdf2/Customization to some other place, for instance: C:\Customization.
  2. Copy your logo image to: C:\Customization\common\artwork\logo.png.
  3. Rename C:\Customization\catalog.xml.orig to: C:\Customization\catalog.xml.
  4. Open the catalog.xml in Oxygen XML Editor and uncomment this line:
      <!--uri name="cfg:fo/xsl/custom.xsl" uri="fo/xsl/custom.xsl"/-->   

    So now it looks like this:

    <uri name="cfg:fo/xsl/custom.xsl" uri="fo/xsl/custom.xsl"/>
  5. Rename the file: C:\Customization\fo\xsl\custom.xsl.orig to: C:\Customization\fo\xsl\custom.xsl
  6. Open the custom.xsl file in Oxygen XML Editor and create the template called createFrontMatter_1.0. This will override the same template from the [OXYGEN_DIR]/frameworks/dita/DITA-OT/plugins/org.dita.pdf2/xsl/fo/front-matter.xsl. Now, custom.xsl has the content:
    <?xml version='1.0'?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:fo="http://www.w3.org/1999/XSL/Format"
        version="1.1">
    
    <xsl:template name="createFrontMatter_1.0">
            <fo:page-sequence master-reference="front-matter" xsl:use-attribute-sets="__force__page__count">
                <xsl:call-template name="insertFrontMatterStaticContents"/>
                <fo:flow flow-name="xsl-region-body">
                    <fo:block xsl:use-attribute-sets="__frontmatter">
                        <!-- set the title -->
                        <fo:block xsl:use-attribute-sets="__frontmatter__title">
                            <xsl:choose>
                                <xsl:when test="$map/*[contains(@class,' topic/title ')][1]">
                                    <xsl:apply-templates select="$map/*[contains(@class,' topic/title ')][1]"/>
                                </xsl:when>
                                <xsl:when test="$map//*[contains(@class,' bookmap/mainbooktitle ')][1]">
                                    <xsl:apply-templates select="$map//*[contains(@class,' bookmap/mainbooktitle ')][1]"/>
                                </xsl:when>
                                <xsl:when test="//*[contains(@class, ' map/map ')]/@title">
                                    <xsl:value-of select="//*[contains(@class, ' map/map ')]/@title"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="/descendant::*[contains(@class, ' topic/topic ')][1]/*[contains(@class, ' topic/title ')]"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </fo:block>
    
                        <!-- set the subtitle -->
                        <xsl:apply-templates select="$map//*[contains(@class,' bookmap/booktitlealt ')]"/>
    
                        <fo:block xsl:use-attribute-sets="__frontmatter__owner">
                            <xsl:apply-templates select="$map//*[contains(@class,' bookmap/bookmeta ')]"/>
                        </fo:block>
                       
                        <fo:block text-align="center" width="100%">
                            <fo:external-graphic src="url({concat($artworkPrefix, '/Customization/OpenTopic/common/artwork/logo.png')})"/>
                         </fo:block>
    
                    </fo:block>
    
                    <!--<xsl:call-template name="createPreface"/>-->
    
                </fo:flow>
            </fo:page-sequence>
            <xsl:call-template name="createNotices"/>
        </xsl:template>
    </xsl:stylesheet>
  7. Edit (or duplicate, then edit) the DITA Map to PDF transformation scenario. In the Parameters tab, set the customization.dir parameter to C:\Customization.

There are other ways in which you could directly modify the XSL stylesheets from the DITA OT but this customization gives you flexibility to future DITA OT upgrades in Oxygen XML Editor.

Related information
Automatic PDF plugin customization generator by Jarno Elovirta.