Adding a Watermark to PDF Output

To add a watermark to the PDF output of a DITA map transformation, follow these steps:

  1. Create a custom XSL stylesheet named custom.xsl that sets the path of the watermark image, as in the following example:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
        <xsl:variable name="imageDir" select="'/common/artwork/'"/>
        <xsl:variable name="imageWatermarkPath"><xsl:value-of select="$imageDir"/>ExampleImage.png</xsl:variable>
    </xsl:stylesheet>
  2. Place the custom.xsl file in the following directory: DITA_OT_DIR\plugins\org.dita.pdf2\Customization\fo\attrs.
  3. In the DITA_OT_DIR\plugins\org.dita.pdf2\Customization directory, locate the file named catalog.xml.orig and rename it as catalog.xml.
  4. Edit the catalog.xml file and uncomment from the following line:
    <!--uri name="cfg:fo/attrs/custom.xsl" uri="fo/attrs/custom.xsl"/-->
    <uri name="cfg:fo/attrs/custom.xsl" uri="fo/attrs/custom.xsl"/>
  5. Edit the static-content.xsl file that is located in the DITA_OT_DIR\plugins\org.dita.pdf2\xsl\fo directory and add the following template:
    <xsl:template name="insertImage">
                <fo:block-container absolute-position="fixed" top="160mm">
                    <fo:block>
                        <fo:external-graphic src="url({concat($customizationDir.url, $imageWatermarkPath)})" xsl:use-attribute-sets="image" />
                    </fo:block>
                </fo:block-container>
    </xsl:template>
  6. In the same file (static-content.xsl), add a call to this template before the <fo:block> tag in each of the header templates (insertBodyOddHeader, insertBodyEvenHeader, insertBodyFirstHeader, insertBodyLastHeader, insertTocOddHeader, insertTocEvenHeader, and insertBodyFootnoteSeparator), or in each of the footer templates (insertBodyFirstFooter, insertBodyLastFooter, insertBodyOddFooter, insertBodyEvenFooter, insertTocOddFooter, insertTocEvenFooter, and insertBodyFootnoteSeparator). The call would look like this:
    <xsl:call-template name="insertImage"/>
    Note: If you add the call in both the header and footer templates, the watermark image will be displayed twice in each page of the output.
  7. Edit a DITA Map PDF transformation scenario and in the Parameters tab, set the value of the customization.dir parameter to something like: ${frameworksDir}/dita/DITA-OT/plugins/org.dita.pdf2/Customization, where ${frameworksDir}/dita/DITA-OT is pointing to your DITA_OT_DIR.
  8. Apply the transformation scenario.