Customizing PDF output

Example of PDF output customization with a custom transformation type.

Procedure

  1. Create a new plug-in directory com.example.print-pdf into DITA-OT plugins directory.
  2. Create a plug-in configuration file plugin.xml, declare the new transformation type print-pdf and dependencies.
    <?xml version='1.0' encoding='UTF-8'?>
    <plugin id="com.example.print-pdf">
      <require plugin="org.dita.pdf2"/>
      <feature extension="dita.conductor.transtype.check" value="print-pdf"/>
      <feature extension="dita.transtype.print" value="print-pdf"/>
      <feature extension="dita.conductor.target.relative" file="integrator.xml"/>
    </plugin>
  3. Add an Ant script integrator.xml to define the transformation type.
    <?xml version='1.0' encoding='UTF-8'?>
    <project name="com.example.print-pdf">
      <target name="dita2print-pdf.init">
        <property name="customization.dir" location="${dita.plugin.com.example.print-pdf.dir}/cfg"/>
      </target>
      <target name="dita2print-pdf" depends="dita2print-pdf.init, dita2pdf2"/>
    </project>
  4. Add a cfg/catalog.xml file to take custom XSLT stylesheets into use.
    <?xml version="1.0" encoding="UTF-8"?>
    <catalog prefer="system" xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
      <uri name="cfg:fo/attrs/custom.xsl" uri="fo/attrs/custom.xsl"/>
      <uri name="cfg:fo/xsl/custom.xsl" uri="fo/xsl/custom.xsl"/>
    </catalog>
  5. Add attribute and variable overrides to cfg/fo/attrs/custom.xsl
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    version="2.0">
      <!-- Change page size to A4 -->
      <xsl:variable name="page-width">210mm</xsl:variable>
      <xsl:variable name="page-height">297mm</xsl:variable>
    </xsl:stylesheet>
  6. Add XSLT overrides to cfg/fo/xsl/custom.xsl
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:xs="http://www.w3.org/2001/XMLSchema"
                    xmlns:fo="http://www.w3.org/1999/XSL/Format"
                    version="2.0">
      <!-- Move figure title to top and description to bottom -->
      <xsl:template match="*[contains(@class,' topic/fig ')]">
        <fo:block xsl:use-attribute-sets="fig">
          <xsl:call-template name="commonattributes"/>
          <xsl:if test="not(@id)">
            <xsl:attribute name="id">
              <xsl:call-template name="get-id"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:apply-templates select="*[contains(@class,' topic/title ')]"/>
          <xsl:apply-templates select="*[not(contains(@class,' topic/title ') or contains(@class,' topic/desc '))]"/>
          <xsl:apply-templates select="*[contains(@class,' topic/desc ')]"/>
        </fo:block>
      </xsl:template>
    </xsl:stylesheet>
  7. Add variable definition file cfg/common/vars/en.xml for English to override generated text.
    <?xml version="1.0" encoding="UTF-8"?>
    <vars xmlns="http://www.idiominc.com/opentopic/vars">
      <!-- Remove dot from list number -->
      <variable id="Ordered List Number"><param ref-name="number"/></variable>
      <!-- Change unordered list bullet to an em dash -->
      <variable id="Unordered List bullet">&#x2014;</variable>
    </vars>

Results

The plug-in directory should have the layout and files:

com.example.print-pdf/
  cfg/
    common/
      vars/
        en.xml
    fo/
      attrs/
        custom.xsl
      xsl/
        custom.xsl
    catalog.xml
  integrator.xml
  plugin.xml

What to do next

Run integration process to install the plug-in and take the print-pdf transformation type into use.