Watermarking II

So static text is all very well for a document but lets say we need something more dynamic, maybe the text is in an XML element in the incoming XML data for the report or maybe we need some conditional logic to show a specific value based on some flag value in the incoming XML.

Let's deal with the simple situation first - pulling a value from the incoming XML data. This is pretty straightforward, use the same method to add the watermark in Word but rather than enter a fixed string, just reference the XML element that is holding the watermark text.

Just be careful here, you might need to provide the full path to the element or use a .// prefix to get the text to render correctly.

You can also assign an element value to an XSL variable, so if you want to concatenate a few strings in your XML or static test you can build up watermark text quite easily.

For the more complex case above where we need some logic, I needed to scratch my balding pate a little. Roc has posed a question on the forum wanting some conditional logic around the watermark.


Hi XMLP Gurus,

Is it possible to code watermark in XMLP by inserting a field and coding the condition in that field. Depending on the condition I can print the watermark text on the output. Is this achievable?

Thanks in advance...


I took a little while to get an answer - I was getting a little desperate looking to build some XSLFO template to handle te logic - I stumbled upon a very useful inline 'if' statement that was hidden away - yes, another hidden feature that even I did not know about. It takes the format:


xdoxslt:ifelse(boolean expression ,true result, false result)
in use we get something like
xdoxslt:ifelse(.//WM_FLAG='C?,'Canceled','Approved')

So if the WM_FLAG element contains a 'C' then the 'if' statement returns 'Canceled' otherwise 'Approved' - now you can actually nest the 'ifelse' statements so we can get some serious logic into the inline 'if'. In this case, for the watermark we used the following:


<xsl:variable name="wMark" select="xdoxslt:ifelse(.//WM_FLAG='C?,'Canceled','Approved')"/>

this assigns the result of the 'if' to a variable wMark - we then use


<?$wMark?>

as the value in the watermark text. This then gets resolved at runtime correctly based on the 'if' statement, neat huh?

I have to mention that we have an issue at the moment if you are using the @section command - we're looking into that.

Finally, there is another method to add a watermark - via a java API that we provide. Its a post document generation step and of course you need to have some means of calling the java API. Either a java concurrent program or maybe someting funky in the after report trigger if you are using OReports to generate the XML ... hmmm thats needs some thought.

Using the API is pretty straightforward, its actually documented here for all versions but I'll give you the basics.

Use the SetTextDefaultWatermark( ) method to set a text watermark with the following attributes:

- Text angle (in degrees): 55
- Color: light gray (0.9, 0.9, 0.9)
- Font: Helvetica
- Font Size: 100
- The start position is calculated based on the length of the text

Alternatively, use the SetTextWatermark( ) method to set each attribute separately. Use the SetTextWatermark() method as follows:


SetTextWatermark ("Watermark Text", x, y) - declare the watermark text, and set the x and y coordinates of the start position. In the following example, the watermark text is "Draft" and the coordinates are 200f, 200f.


? setTextWatermarkAngle (n) - sets the angle of the watermark text. If this method is not called, 0 will be used.


? setTextWatermarkColor (R, G, B) - sets the RGB color. If this method is not called, light gray (0.9, 0.9, 0.9) will be used.


? setTextWatermarkFont ("font name", font size) - sets the font and size. If you do not call this method, Helvetica, 100 will be used.


The following example shows how to set these properties and then call the PDFDocMerger.


Input:


? PDF Documents (InputStream)


Output:


? PDF Document (OutputStream)


For example


import java.io.*;
import oracle.apps.xdo.common.pdf.util.PDFDocMerger;

...

public boolean mergeDocs(InputStream inputStreams, OutputStream outputStream)

{   try   {     // Initialize PDFDocMerger         PDFDocMerger docMerger = new PDFDocMerger(inputStreams, outputStream);     // You can use setTextDefaultWatermark() without these detailed setting         docMerger.setTextWatermark("DRAFT", 200f, 200f); //set text and place         docMerger.setTextWatermarkAngle(80); //set angle         docMerger.setTextWatermarkColor(1.0f, 0.3f, 0.5f); // set RGB Color     // Merge PDF Documents and generates new PDF Document         docMerger.mergePDFDocs();         docMerger = null;         return true;       }         catch(Exception exc)       {         exc.printStackTrace();         return false;        }      }
Not too tough, right!

Comments:

Hi XMLP gurus I am having an AR Invoice Print template with a different last page footer. I also have a water mark image on the RTF template. Its a straight water marking, not conditional watermarking. When I do a PDF Preview: 1. If there are multiple pages in output, the water mark is appearing on first page but not on all other pages. 2. If there's only one page in output, then the water mark is not appearing on thsi page even. Is this an inherent problem ?? IS it a bug? Please drop your advice. Regards Prabu

Posted by prabu on July 20, 2008 at 09:22 PM MDT #

Prabu, Check out bug number 5767916. Strange thing is that I am getting this problem even though the patch has been applied. Got an SR open. Will keep you posted. Jon.

Posted by Jon Bartlett on August 21, 2008 at 01:50 PM MDT #

I am using the simple method of inserting a water mark to a RTf template.. i have a problem .. I am embedding my signature as an image in to my RTF and whenver the water mark comes on top of the image the water mark is cut off.. please help... Thanks, Nisha

Posted by Nisha on August 17, 2009 at 05:53 AM MDT #

Hi, I need to implement the watermark feature inside in the custom RTF template. Data for the watermark needs to be derived from the element PO_DATA/WATERMARK_TEXT from the XML. Is there are any solution ? Regards, Prakash K.B.

Posted by Prakash on October 13, 2009 at 01:58 PM MDT #

Hi, I need to implement watermark feature inside "?for-each@section:PO_DATA?". Value for the watermark needs to be fetched from PO_DATA/WATERMARK_TEXT from the XML. Is there any approach to incorporate this requirement ? Regards, Prakash.

Posted by Prakash on October 13, 2009 at 02:16 PM MDT #

WHEN I TYPE IN RTF WATERMARK I'M NOT ABLE TO CREATE VARIABLE TO CHECKTHE CONDITION CAN ANY ONE HELP

Posted by MEENU on March 18, 2010 at 06:18 AM MDT #

Please let me know where i can download the document you have embedded , when i am clicking the document , but it is saying invalid link.

Thanks and regards,
Sunil Dutt.S

Posted by sunil dutt on September 09, 2012 at 08:55 AM MDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Follow bipublisher on Twitter Find Us on Facebook BI Publisher Youtube ChannelDiscussion Forum

Join our BI Publisher community to get the most and keep updated with the latest news, How-to, Solutions! Share your feedback and let us hear your voice @bipublisher on Twitter, on our official Facebook page, and Youtube!

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today