To add a watermark to the PDF output of a
DITA Map
PDF - based on XSL-FO transformation scenario, follow this procedure:
- Create a customization directory
(if you have not already done so).
- Create a cfg\common\artwork directory structure in your
customization directory and copy your watermark image to that directory (for example,
C:\Customization\cfg\common\artwork\watermark.png).
- Rename the Customization\catalog.xml.orig file to:
Customization\catalog.xml.
-
Open the
catalog.xml in
Oxygen XML Author Eclipse plugin and
uncomment this line:
The uncommented line should look like
this:
<uri name="cfg:fo/xsl/custom.xsl" uri="fo/xsl/custom.xsl"/>
- Rename the file: Customization\fo\xsl\custom.xsl.orig to:
Customization\fo\xsl\custom.xsl.
- Open the Customization\fo\xsl\custom.xsl file in Oxygen XML Author Eclipse plugin to overwrite two XSLT templates:
- The first template is located in the XSLT stylesheet DITA-OT-DIR\plugins\org.dita.pdf2\xsl\fo\static-content.xsl. Override by copying
the original template content in the custom.xsl and specifying a
watermark image for every page in the PDF content, using a
block-container element that references the watermark image
file:
<fo:static-content flow-name="odd-body-header">
<fo:block-container absolute-position="absolute"
top="-2cm" left="-3cm" width="21cm" height="29.7cm"
background-image="{concat($artworkPrefix,
'Configuration/OpenTopic/cfg/common/artwork/watermark.png')}">
<fo:block/>
</fo:block-container>
<fo:block xsl:use-attribute-sets="__body__odd__header">
<xsl:call-template name="insertVariable">
<xsl:with-param name="theVariableID" select="'Body odd header'"/>
<xsl:with-param name="theParameters">
<prodname>
<xsl:value-of select="$productName"/>
</prodname>
<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__header__pagenum">
<fo:page-number/>
</fo:inline>
</pagenum>
</xsl:with-param>
</xsl:call-template>
</fo:block>
</fo:static-content>
</xsl:template>
- The second template to override is located in the XSLT stylesheet DITA-OT-DIR\plugins\org.dita.pdf2\xsl\fo\commons.xsl and is used for styling the
first page of the output. Override it by copying the original template content in the
custom.xsl and adding the
block-container
element that references the watermark image
file:<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-container absolute-position="absolute"
top="-2cm" left="-3cm" width="21cm" height="29.7cm"
background-image="{concat($artworkPrefix,
'Configuration/OpenTopic/cfg/common/artwork/watermark.png')}">
<fo:block/>
</fo:block-container>
<fo:block xsl:use-attribute-sets="__frontmatter">
<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>
<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>
</fo:flow>
</fo:page-sequence>
<xsl:if test="not($retain-bookmap-order)">
<xsl:call-template name="createNotices"/>
</xsl:if>
</xsl:template>
- Edit the DITA Map PDF - based on XSL-FO transformation scenario, go to the Parameters
tab, and set the customization.dir parameter to point to the location of your
customization directory.