Adding a Watermark to XHTML and PDF output
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Adding a Watermark to XHTML and PDF output
Post by sorin_ristache »
Please follow these steps for adding a watermark to the PDF output of the DITA map transformation:
- create a custom XSL stylesheet called custom.xsl in the directory [Oxygen-install-dir]\frameworks\dita\DITA-OT\plugins\org.dita.pdf2\Customization\fo\attrs that sets the path of the watermark image, for example:
Code: Select all
<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"/>draft.png</xsl:variable>
</xsl:stylesheet> - rename the file catalog.xml.orig to catalog.xml in directory [Oxygen-install-dir]\frameworks\dita\DITA-OT\plugins\org.dita.pdf2\Customization
- uncomment the following line in the file catalog.xml:
Code: Select all
<!--uri name="cfg:fo/attrs/custom.xsl" uri="fo/attrs/custom.xsl"/-->
- add the following template in file [Oxygen-install-dir]\frameworks\dita\DITA-OT\plugins\org.dita.pdf2\xsl\fo\static-content.xsl:
Code: Select all
<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> - add a call to this template:
before the </fo:block> tag in each of the following templates in the same file [Oxygen-install-dir]\frameworks\dita\DITA-OT\plugins\org.dita.pdf2\xsl\fo\static-content.xsl: insertBodyOddHeader, insertBodyEvenHeader, insertBodyFirstHeader, insertBodyFirstFooter, insertBodyLastHeader, insertBodyLastFooter, insertBodyFootnoteSeparator, insertBodyOddFooter, insertBodyEvenFooter, insertTocOddHeader, insertTocEvenHeader, insertTocOddFooter, insertTocEvenFooter.Code: Select all
<xsl:call-template name="insertImage"/>
- set the parameter customization.dir to value ${frameworksDir}/dita/DITA-OT/plugins/org.dita.pdf2/Customization in a customized version of the DITA Map PDF transform
- copy the image file draft.png in directory [Oxygen-install-dir]\frameworks\dita\DITA-OT\plugins\org.dita.pdf2\Customization\common\artwork, that is the image file name and directory that we set up above in the first step
- run the customized version of the DITA Map PDF transform
For the XHTML output just set a custom CSS with the parameter args.css and set the parameter args.copycss to true in the DITA Map XHTML transform. The custom CSS should contain:
Code: Select all
body {
background-image: url(images/draft.png);
}
Regards,
Sorin
-
- Posts: 70
- Joined: Fri Jul 27, 2012 1:46 am
Re: Adding a Watermark to XHTML and PDF output
Is it possible to tie printing of the watermark to the args.draft parameter in the PDF transformation, so that I can turn it on and off easily? As it is, it always prints. (I'm not sure I understood your mechanism for invoking the watermark, but I think it may be indicated in your step:
If so, does that mean you are to use that transform only for publishing to draft, and that you must have a specially named Customization directory only for that purpose? Otherwise how does the DITA-OT know when to print the image?)set the parameter customization.dir to value ${frameworksDir}/dita/DITA-OT/plugins/org.dita.pdf2/Customization in a customized version of the DITA Map PDF transform.
Thanks.
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Adding a Watermark to XHTML and PDF output
Post by sorin_ristache »
The args.draft parameter is used in DITA-OT for draft-comment elements, not for watermark images. It is not easy to extend this parameter to include watermark images too.gwhite wrote:Is it possible to tie printing of the watermark to the args.draft parameter in the PDF transformation, so that I can turn it on and off easily? As it is, it always prints.
Having two customization directories just for turning the watermark image on and off would be overkill. You should have only one customization directory, create a new parameter that turns the watermark on and off (call it args.watermark for example), set that parameter in the DITA PDF transformation and pass it to the XSL transformation by adding it in the DITA-OT build.xml file. In fact I think you should add it in the DITA-OT/plugins/org.dita.pdf2/build.xml file and run the DITA-OT Integrator after that. In the customized XSL transformation from the org.dita.pdf2 plugin the watermark should be added to the PDF page only if the parameter is set to true.gwhite wrote:If so, does that mean you are to use that transform only for publishing to draft, and that you must have a specially named Customization directory only for that purpose? Otherwise how does the DITA-OT know when to print the image?)
Regards,
Sorin
-
- Posts: 70
- Joined: Fri Jul 27, 2012 1:46 am
Re: Adding a Watermark to XHTML and PDF output
Code: Select all
<param name="args.watermark" expression="${args.watermark}"></param>
Code: Select all
<condition property="args.watermark" value="">
<not><isset property="args.watermark"></isset></not>
</condition>
Gary
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Adding a Watermark to XHTML and PDF output
Post by sorin_ristache »
First you should change the parameter in the Ant file to:
Code: Select all
<param name="WATERMARK" expression="${args.watermark}" if="args.watermark"/>
Code: Select all
<param name="DRAFT" expression="${args.draft}"></param>
Code: Select all
<xsl:param name="WATERMARK" select="'no'"/>
Code: Select all
<xsl:param name="DRAFT"/>
Code: Select all
<xsl:template name="insertImage">
<xsl:if test="$WATERMARK = 'yes'">
<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:if>
</xsl:template>
Regards,
Sorin
-
- Posts: 70
- Joined: Fri Jul 27, 2012 1:46 am
Re: Adding a Watermark to XHTML and PDF output
Code: Select all
<xsl:variable name="imageDir" select="'/common/artwork/'"/>
<xsl:variable name="imageWatermarkPath"><xsl:value-of select="$imageDir"/>draft.png</xsl:variable>
transform.topic2fo.main:
[xslt] Processing C:\Users\gwhite\Documents\Publishing\temp\pdf-ndo\oxygen_dita_temp\stage1a.xml to C:\Users\gwhite\Documents\Publishing\temp\pdf-ndo\oxygen_dita_temp\stage2.fo
[xslt] Loading stylesheet C:\DITA-OTProjectSettings\DITA-OT\plugins\org.dita.pdf2\xsl\fo\topic2fo_shell_fop.xsl
[xslt] C:\DITA-OTProjectSettings\DITA-OT\plugins\org.dita.pdf2\xsl\fo\static-content.xsl:888:133: Fatal Error! Variable imageWatermarkPath has not been declared (or its declaration is not in scope)
[xslt] Failed to process C:\Users\gwhite\Documents\Publishing\temp\pdf-ndo\oxygen_dita_temp\stage1a.xml
BUILD FAILED
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Adding a Watermark to XHTML and PDF output
Post by sorin_ristache »
I suggest keeping only one plugin, the one that comes with DITA-OT and creates PDF output, and setting different customization directories in the parameter customization.dir for the different kinds of PDF output that you need. Did you try this?gwhite wrote:I have run into a new problem with the functioning of the draft watermark solution you communicated in this thread. I have begun moving toward creating a separate plugin in the DITA-OT plugins folder for the different kinds of PDF output my company requires -- such as one that prints a different title page, headers and footers, and so on for a client company.
. . .
But adopting the concept of separate plugins for different purposes, there is no custom.xsl file in a Customization folder.
Sorin
<oXygen/> XML Editor Support
-
- Posts: 70
- Joined: Fri Jul 27, 2012 1:46 am
Re: Adding a Watermark to XHTML and PDF output
The approach of multiple Customization folders would work if it were only me, but it's not as good a solution for a documentation team who have to produce many different types of PDF output. Maintaining all those Customization folders for multiple team members wouldn't work as well as adding plugins to the plugin folder. I think I would be able to make progress on this if I understood the answer to the specific question: in what xsl file do the variable declarations belong that invoke the watermark? And then, does that affect the way the referenced directory location is expressed?
<xsl:variable name="imageDir" select="'/common/artwork/'"/>
<xsl:variable name="imageWatermarkPath"><xsl:value-of select="$imageDir"/>draft.png</xsl:variable>
The custom.xsl files sort of stand in for and override the other xsl files that affect PDF processing, right? Changes introduced to them often amount to a tweak of another file, such as root-processing.xsl, or tables.xsl. If I knew which file to add the variable declaration to, I think that would be the best solution.
Gary
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Adding a Watermark to XHTML and PDF output
Post by sorin_ristache »
Yes, there is a custom.xsl file in a Customization folder. This is true for any PDF plugin added to DITA-OT. It does not matter if it is the PDF plugin that comes with DITA-OT or a new plugin that you add to DITA-OT, provided your plugin is based on the one that comes with DITA-OT.gwhite wrote:But adopting the concept of separate plugins for different purposes, there is no custom.xsl file in a Customization folder. There are custom.xsl files in the ..cfg/attr and ..cfg/xsl folders. I've tried placing the variable declaration in various files in those folders, but the transform always fails. I believe everything else is set up properly.
Right.gwhite wrote:The custom.xsl files sort of stand in for and override the other xsl files that affect PDF processing, right? Changes introduced to them often amount to a tweak of another file, such as root-processing.xsl, or tables.xsl.
You have to modify the same files in every PDF plugin, just like you did in the above customization (4 months ago) when you said that it worked great.gwhite wrote:If I knew which file to add the variable declaration to, I think that would be the best solution.
Sorin
<oXygen/> XML Editor Support
-
- Posts: 86
- Joined: Wed Feb 09, 2011 10:43 pm
Re: Adding a Watermark to XHTML and PDF output
I am able to display the watermark on all pages. I implemented the changes in my customPDF plugin.
I am trying to implement the parameter in the scenario so that I can choose when to display the watermark, but with no success.

To implement the parameter args.watermark, I used the files in the org.dita.pdf2. The build.xml and topic2fo.xsl file I have in my custom plugin are almost empty. I was expecting the scenario to pick up the info from the org.dita.pdf2 folder, since nothing was defined in my plugin.
I am not sure what the build.xml and topic2fo.xsl files of my plugin should contain. The same as the org.dita.pdf2? But I was told for another issue to only transfer in the plugin what was modified.
Not quite sure how to handle the build.xml and topic2fo.xsl files of my plugin.
Regards
Carole
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Adding a Watermark to XHTML and PDF output
Post by sorin_ristache »
For adding to the Oxygen DITA PDF transformation a parameter args.watermark for controlling the addition of a watermark image please follow the above instructions in this post which give you an example of what code to add in each of the following files:Boreas wrote:I am not sure what the build.xml and topic2fo.xsl files of my plugin should contain. The same as the org.dita.pdf2? But I was told for another issue to only transfer in the plugin what was modified.
Not quite sure how to handle the build.xml and topic2fo.xsl files of my plugin.
OXYGEN_INSTALL_DIR/frameworks/dita/DITA-OT/plugins/org.dita.pdf2/build.xml
OXYGEN_INSTALL_DIR/frameworks/dita/DITA-OT/plugins/org.dita.pdf2/xsl/fo/topic2fo.xsl
OXYGEN_INSTALL_DIR/frameworks/dita/DITA-OT/plugins/org.dita.pdf2/xsl/fo/static-content.xsl
Did you add the parameter in the build.xml file as instructed above, like the following?
Code: Select all
<param name="WATERMARK" expression="${args.watermark}" if="args.watermark"/>
Code: Select all
<xsl:param name="WATERMARK" select="'no'"/>
Sorin
<oXygen/> XML Editor Support
-
- Posts: 86
- Joined: Wed Feb 09, 2011 10:43 pm
Re: Adding a Watermark to XHTML and PDF output
you are suggesting that all changes should be done in the org.dita.pdf2, regardless if I have custom plugin to generate my PDF?
At one point in the post, it is said
I used the build and topic2fo of the org.dita.pdf2 and the static-content.xsl from my plugin, is this the mistake?You have to modify the same files in every PDF plugin, just like you did in the above customization (4 months ago) when you said that it worked great.
Carole
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Adding a Watermark to XHTML and PDF output
Post by sorin_ristache »
In a PDF transformation only one plugin is used: either the org.dita.pdf2 plugin or your own custom plugin. This is why all changes should be done in one plugin, the one used in the transformation. So if you are using your own custom plugin for generating the PDF output then you should add all the changes in that plugin, otherwise the changes should go in the org.dita.pdf2 plugin.
Sorin
<oXygen/> XML Editor Support
-
- Posts: 1
- Joined: Thu Jan 14, 2016 11:12 am
Re: Adding a Watermark to XHTML and PDF output
Post by johnmacleren »
-
- Posts: 9
- Joined: Wed Mar 13, 2019 6:37 am
Re: Adding a Watermark to XHTML and PDF output
Post by shilpah123 »
If we use the watermark image for XHTML output, it prints multiple times on the page. Is there a way to print the watermark only once per HTML page? Thanks.
-
- Posts: 9
- Joined: Wed Mar 13, 2019 6:37 am
Re: Adding a Watermark to XHTML and PDF output
Post by shilpah123 »
I have found a solution to print watermark once per page. Pasting the code to be used in CSS below -
body {
background-image: url(watermark.png);
vertical-align: middle;
background-repeat: no-repeat;
}
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service