Creating Watermark using .NET

I am trying to create a watermark using .NET. The KB suggest to use the DrawPage event to do this. My code looks like:

DEF VAR oGraphics AS System.Drawing.Graphics   NO-UNDO.
DEF VAR oFont     AS System.Drawing.Font       NO-UNDO.
DEF VAR oBrush    AS System.Drawing.Brush      NO-UNDO.
DEF VAR oColor    AS System.Drawing.Color      NO-UNDO.
DEF VAR oPointF   AS System.Drawing.PointF     NO-UNDO.
DEF VAR oRectangle AS System.Drawing.Rectangle NO-UNDO.

ASSIGN oGraphics  = oClass:Graphics.
oFont   = NEW System.Drawing.Font("Arial", 100).
oBrush  = NEW System.Drawing.SolidBrush(System.Drawing.Color:Black).
oGraphics:DrawString("Demoversion", oFont, oBrush, 0, 0).

However, when I run this code, it does not show any watermark on the page. I also tried to use the DrawProject event with same outcome.

The help file states “Notes for .NET Standard/Core: Drawing events such as DrawPage, DrawDesignerObject, etc. are triggered, but cannot be used for drawing because the reference to the .NET graphics object is not available or is null”.

So I am wondering: is my code wrong or is it simply not possible to use this method?

As we have the Professional Edition, the alternative would be to use the DOM API. What would be the best event to use in that scenario?

Ok. Just found a way to do this using DOM: The QueryFileNameForExportJob event appears to be a good place. Example code below (using Progress OpenEdge).

DEF VAR oProjectList AS ProjectList   NO-UNDO.
DEF VAR oDrawing     AS ObjectDrawing NO-UNDO.
DEF VAR oText        AS ObjectText    NO-UNDO.
DEF VAR oParagraph   AS Paragraph     NO-UNDO.
DEF VAR cImage       AS CHAR          NO-UNDO.
DEF VAR cText        AS CHAR          NO-UNDO.

/* add an image watermark */
cImage = SEARCH(<yourimage>).
oProjectList = NEW ProjectList(oLL).
oProjectList:GetFromParent().
oDrawing = NEW ObjectDrawing(oProjectList:Objects).
oDrawing:Name            = "WatermarkImage".
oDrawing:POSITION:Top    = "20000".
oDrawing:POSITION:Height = "200000".
oDrawing:POSITION:Width  = "150000".
oDrawing:POSITION:Left   = "20000".
oDrawing:SOURCE:Mode     = "1".
oDrawing:Condition       = "TRUE".
oDrawing:SOURCE:Formula   = SUBST("Drawing('&1')", <yourimage>).
oDrawing:SOURCE:Display:OriginalSize = "TRUE".

/* add a text as watermark, print in the righ margin */
&SCOP WatermarkText  "This is an Evaluation Version * "

ASSIGN cText = "'" + FILL({&waterMarkText}, 10)+ "'".

oText = NEW ObjectText(oProjectList:Objects).

ASSIGN oText:NAME            = "WaterMarkText"
       oText:POSITION:Top    = "20000"
       oText:POSITION:Height = "270000"
       oText:POSITION:Width  = "9000"
       oText:POSITION:Left   = "190000"
       oText:Direction       = "3"
       oText:Condition       = "TRUE".

oParagraph = NEW Paragraph(oText:Paragraphs).
oParagraph:Alignment = "0".
oParagraph:CONTENTS  = cText.
oParagraph:FONT:Size = "20".
oParagraph:FONT:Color = "LL.Color.Silver".
oParagraph:Wrapping:Line = "1".
1 Like