Pages: 1
Print
Author Topic: watermark in PDF output  (Read 8177 times)
IF
Member

Posts: 80


« on: September 20, 2010, 11:54:02 AM »

Is there a way to add a watermark to a PDF output directly from XMetal 6.0, e.g., configure the output to have the word "DRAFT" appear on every page? thanks. isabelle
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2484



WWW
« Reply #1 on: September 20, 2010, 12:48:25 PM »

No. The DITA OT and / or RenderX XEP settings would need to be modified to accomplish this.
Logged
Su-Laine Yeo
Solutions Consultant
Member

Posts: 260


« Reply #2 on: September 20, 2010, 05:37:10 PM »

I believe you can set up Acrobat Distiller to automatically add a watermark to PDF files. When creating a PDF in XMetaL, use the "XMetaL Enhanced PDF via RenderX XEP and Acrobat Distiller" option, and whatever settings you've configured for Acrobat Distiller should be picked up.

If you want to go the route of modifying the DITA Open Toolkit, the dita-users group on Yahoo! has a thread which might be helpful: http://tech.groups.yahoo.com/group/dita-users/message/16373 .

Su-Laine

Logged

Su-Laine Yeo
Solutions Consultant
JustSystems Canada, Inc.
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2484



WWW
« Reply #3 on: September 21, 2010, 07:15:23 PM »

The thread at that yahoo group might be a little hard to translate for use with the "XMetaL Enhanced PDF via RenderX XEP" deliverable type (assuming that is the one being used) because the suggestion there is actually for PDF2 (which in our UI is exposed as the deliverable "Book via RenderX"). "XMetaL Enhanced PDF via RenderX XEP" parameterizes a number of things that the other one doesn't and so it differs significantly in this particular area.

There are going to be various ways to solve this: you could parameterize parts of this solution yourself, or extract the path to the image file you wish to embed from some attribute value in the DITA map content, or perhaps do something in ANT, or even insert the text directly using FO statements. I won't try to guess what the best way to do those are (they will vary depending on your requirements). Instead I will just provide the bare minimum to get this working. If you need something more complex you could build on the code here.

Assumptions:
1. You have installed an unmodified version of XMetaL Author Enterprise 6.0 (if changes have been made then you will need to take those into account).
2. You are generating output using the deliverable called "XMetaL Enhanced PDF via RenderX XEP".
3. You wish to keep your PDF file sizes to a minimum.
4. You wish to embed the word "DRAFT" behind all other content centered on every page.
5. You want this to be easily modified and have access to an application you can use to create "PDF images" (single page PDF documents) or images of other types in case you are not happy with my "artwork".

Required Changes:
1. Locate your DITA OT folder. If you are not sure how deployment works or which DITA OT to modify you should see these:
   http://forums.xmetal.com/index.php/topic,1008.0.html
   http://forums.xmetal.com/index.php/topic,237.0.html

2. Copy one of the attached "PDF images" (after unzipping the ZIP archive) into the following folder in our plug-in inside your copy of the <DITA OT>:
   <DITA OT>\demo\xmfo\Customization\common\artwork

Example:
   <DITA OT>\demo\xmfo\Customization\common\artwork\watermark_draft_gold_outline.pdf   

3. Open the following file inside our plug-in:
   <DITA OT>\demo\xmfo\Customization\fo\xsl\xm_layout_masters_overrides.xsl

4. Make these additions (listed in blue) inside xm_layout_masters_overrides.xsl

    <xsl:template
      match="fo:region-body[contains(parent::*/@master-name,'odd')] | fo:region-body[contains(parent::*/@master-name,'first')]"
      mode="layout-masters-processing">
      <xsl:element name="fo:region-body">     
          <xsl:attribute name="margin-top"><xsl:value-of select="$xm.page.margin.top"/></xsl:attribute>
          <xsl:attribute name="margin-right"><xsl:value-of select="$xm.page.margin.outer"/></xsl:attribute>
          <xsl:attribute name="margin-bottom"><xsl:value-of select="$xm.page.margin.bottom"/></xsl:attribute>     
          <xsl:attribute name="margin-left"><xsl:value-of select="$xm.page.margin.inner"/></xsl:attribute>

   <!-- Add a background image for DRAFT watermark -->
        <xsl:attribute name="background-image">url('Customization/OpenTopic/common/artwork/watermark_draft_gold_filled.pdf')</xsl:attribute>
        <xsl:attribute name="background-repeat">no-repeat</xsl:attribute>
        <xsl:attribute name="background-position-horizontal">center</xsl:attribute>
        <xsl:attribute name="background-position-vertical">center</xsl:attribute>


      </xsl:element>
    </xsl:template>

    <xsl:template
      match="fo:region-body[contains(parent::*/@master-name,'even')] | fo:region-body[contains(parent::*/@master-name,'last')]"
      mode="layout-masters-processing">
      <xsl:element name="fo:region-body">     
          <xsl:attribute name="margin-top"><xsl:value-of select="$xm.page.margin.top"/></xsl:attribute>
          <xsl:attribute name="margin-right"><xsl:value-of select="$xm.page.margin.inner"/></xsl:attribute>
          <xsl:attribute name="margin-bottom"><xsl:value-of select="$xm.page.margin.bottom"/></xsl:attribute>     
          <xsl:attribute name="margin-left"><xsl:value-of select="$xm.page.margin.outer"/></xsl:attribute>

   <!-- Add a background image for DRAFT watermark -->
        <xsl:attribute name="background-image">url('Customization/OpenTopic/common/artwork/watermark_draft_gold_filled.pdf')</xsl:attribute>
        <xsl:attribute name="background-repeat">no-repeat</xsl:attribute>
        <xsl:attribute name="background-position-horizontal">center</xsl:attribute>
        <xsl:attribute name="background-position-vertical">center</xsl:attribute>

       
      </xsl:element>
    </xsl:template>


5. Save the XSL file.

How it Works:
1. When you generate output the DITA OT copies the "artwork" (all files) from <DITA OT>\demo\xmfo\Customization\common\artwork\ to the output folder in the following subfolder structure:
   \Customization\common\artwork

2. The FO file is generated in the output folder.

3. A link to the background image is inserted into the FO file by the modified XSLT above along with appropriate attributes so that the FO contains something like this:
   <fo:region-body
      background-image="url('Customization/OpenTopic/common/artwork/watermark_draft_gold_outline.pdf')"
      background-position-horizontal="center"
      background-position-vertical="center"
      background-repeat="no-repeat"
      margin-bottom="1in"
      margin-left="0.75in"
      margin-right="1.25in"
      margin-top="1in"/>


4. When RenderX reads the FO file it finds the PDF image relative to it and digs down into the path specified in url('Customization\common\artwork\watermark_draft_gold_outline.pdf').

Additional Notes:
If you do not like the sample "PDF images" I have provided here you may make your own with a suitable application.

Other file types can also be embedded, including JPG, however, because PDF images like these consist of just "text" and a few PDF codes they are very tiny. See RenderX XEP documentation for all file types you can embed into PDF documents.

"PDF images" (of this type) are infinitely "zoom-able" and so should look nice at any resolution vs embedding JPG or other raster (bitmap) image type.

Keep in mind that if an image is too large to fit into a given FO region it may simply not appear in the PDF generated by RenderX XEP. If yours is not appearing try a smaller image (width x height) to eliminate that possibility before checking the FO for correct paths and filenames, etc.

RenderX has extensions for scaling and resizing background images. These are not part of standard XSL-FO so not discussed here. Consult RenderX XEP documentation if this is a need.

External References:
http://www.w3schools.com/xslfo/obj_region-body.asp
http://www.renderx.com/tutorial.html (search for "background-image" on that page)

* watermarks_for_draft_documents.zip (26.46 KB - downloaded 315 times.)
« Last Edit: September 22, 2010, 10:47:18 AM by Derek Read » Logged
IF
Member

Posts: 80


« Reply #4 on: September 23, 2010, 06:04:56 PM »

Thank you very much for taking the time to write such clear instructions. This worked flawlessly. I especially appreciate the "how it works" section. Thanks. isabelle
Logged
txvia
Member

Posts: 44


« Reply #5 on: September 16, 2011, 08:52:17 AM »

Hi Derek: I have a similar question related to this: If I just want to add a background image only on the cover page and that no other pages should have it, how can I do it? Furthermore, I'd like the background image to fill up my entire cover page, what parameters should I set to make that happen? Thanks for your help.
Logged
Bonie
Member

Posts: 1


« Reply #6 on: March 23, 2016, 03:40:36 AM »

Hi Derek: I have a similar question related to this: If I just want to add a background image only on the cover page and that no other pages should have it, how can I do it? Furthermore this is an honest review of Phen375, I'd like the background image to fill up my entire cover page, what parameters should I set to make that happen? Thanks for your help.

I'd like to set an image that covers the entire first page too without any white border space in a PDF doc.

And then on the rest of the pages have it as the background but very translucent so it's barely visible. Is there any way to do this guys?
« Last Edit: December 22, 2016, 10:30:08 AM by Bonie » Logged
barbwire
Member

Posts: 44


« Reply #7 on: March 24, 2016, 03:48:44 AM »

Hi Derek: I have a similar question related to this: If I just want to add a background image only on the cover page and that no other pages should have it, how can I do it? Furthermore, I'd like the background image to fill up my entire cover page, what parameters should I set to make that happen? Thanks for your help.
If XSL developer has been expert, there are usually separate XSL templates for cover page and "common" pages. So in other words: it is possible to do such thing to the XSL style sheets.

For image to fill up whole page... I think, that you can do maybe fo:block-container which has absolute position. And then give the block-container correct values for top, left, height, width.
Logged
Pages: 1
Print
Jump to:  

email us