Home
Analytics
Adding watermark
birt_ag
<p>I'm using Birt 4.2.0. Can i know how to add a watermark to the report which will be viewed in both PDF and DOC.</p><p>I need to add watermark based on the xml value, for ex if the tag <unapproved>0</unapproved> then only the watermark should be displayed. For any other values of the <unapproved> the watermark should not be displayed.</p><p> </p><p>Thank U.</p>
Find more posts tagged with
Comments
kclark
<p>I think you'll need to create two master pages. One with a background image and the other without. Then depending on your unapproved field you can switch the master page doing something like this</p><pre class="_prettyXprint">if (somedata == 0){this.getStyle().masterPage = "watermarkMP";}else{this.getStyle().masterPage = "nowatermarkMP";} </pre>
birt_ag
<p>Hi clark thanks for the reply..</p><p>I've a doubt. Using which property i can add the watermark. ?
</p><p>and one more thing is, as of now i've 3 different master-pages already within report without any watermarks, now i need to create 3 more master-pages with but adding this watermark. correct rite ? </p>
Abigail
<p>There is a code ,you can try it :</p><p><span>//Create an instance of Image and load an existing image</span>
<span>using</span> (Image image= Image.LoadImageFromFile(<span>
@C:1.pdf
</span>));
{
Graphics graphics = <span>new</span> Graphics(image);
RasterEdgeImaging.Font font = <span>new</span> RasterEdgeImaging.Font(<span>"Times New Roman"</span>, 16, FontStyle.Bold);
RasterEdgeImaging.Brushes.SolidBrush brush=<span>new</span> RasterEdgeImaging.Brushes.SolidBrush();
brush.Color=Color.Black;
brush.Opacity=100;
image.CreateWatermark(<span>"watermark"</span>, font, brush, <span>new</span> PointF(image.Width/2, image.Height/2));
image.Save(<span>
@C
:1-<a data-ipb='nomediaparse' href='
http://www.rasteredge.com/how-to/csharp-imaging/pdf-watermark-creating/'>watermark.pdf</a>"</span>);</p>
;
birt_ag
<p>Hi,</p><p> </p><p>I got to know how to add the background images.</p><div>But now i've multiple masterpage and for each page i need to set different background images. I created a style by adding a background image for each of the masterpage, but once i run the report only the image added to 1st master page is getting printed for all the pages.</div><div> </div><div>can anyone help me on this .. Thank u.</div>
birt_ag
<p>can i get any help on this</p>
GLO_FR
<p>Hi birt_ag,</p><p> </p><p>if you want to add the watermark on your page with the designer go to "Master page" > Property > Advanced > Background image or use the script of Abigail.</p><p> </p><p>For your problem, did you switch correctly your masterpage ?</p><p>One other script to switch is (in the beforeFactory, with a named element on the page)</p><pre class="_prettyXprint _lang-js">rptDesignHandle = reportContext.getReportRunnable().designHandle.getDesignHandle();myElement = rptDesignHandle.findElement("myelement");if (myValue == 1){myElement.setProperty("MasterPage" , "Watermark 1");}else{myElement.setProperty("MasterPage" , "Watermark 2");}</pre><p>For more help, if possible, please upload your design.</p>
birt_ag
<p>Hi GLO_FR,</p><p> </p><p>I'm attaching the design created with the sample database along with the images i used. Kindly place the images in resource folder.</p><p>In the report, i;ve created two master pages named approved and rejected. And i'm associating each master page to one of the tables.</p><p> </p><p>For the 1st table , the background image should be approved, whereas for the 2nd table data it should be rejected. But for both the table data its using the image of 1st masterpage itself.</p><p> </p>
GLO_FR
<p>Hi again,</p><p> </p><p>sorry the late answer (timezone
).</p><p> </p><p>So here is your design</p><p>first master page : approved with watermart1</p><p>second master page : rejected with watermart2</p><p>third master page : default with no watermark</p><p> </p><p>First table is named tableApproved</p><p>Second table is named tableRejected</p><p> </p><p>You have 2 solutions</p><p>1) is to apply/choose the masterpage in the pagebreak section (see screenshot)</p><p>2) second solution is to put some simple script on the layout in the beforeFactory</p><pre class="_prettyXprint _lang-js">tabApproved = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("tabApproved");tabRejected = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("tabRejected");tabApproved.setProperty("masterPage" , "approved");tabRejected.setProperty("masterPage" , "rejected");</pre><p>Here is a video of one of my colleague which can be very usefull <a data-ipb='nomediaparse' href='
http://www.youtube.com/watch?v=HClRkwrtLyY'>http://www.youtube.com/watch?v=HClRkwrtLyY</a></p>
birt_ag
<p>Hi GLO_FR,</p><p> </p><p>Actually in my previous post i had tried out the 1st solution u gave, i.e [color=rgb(0,0,0);font-family:helvetica, arial, sans-serif;] to apply/choose the masterpage in the pagebreak section. But its not working.[/color]</p><p> </p><p> </p><p>I tried the scripting solution u gave, but that also not working.. Only the 1st masterpage image is rendered even in 2nd page. <br />
<br />
I downloaded the design file u had attached in previous reply, but its not displaying any images</p>
GLO_FR
<blockquote class="ipsBlockquote" data-author="birt_ag" data-cid="120920" data-time="1380781761"><div>...
<p>I downloaded the design file u had attached in previous reply, but its not displaying any images</p></div></blockquote><p> </p><p>Ok, you have to put your 2 images in the resources folder and name them watermark1.jpg(=rejected) and watermark2.jpg (approved).</p><p>Attached 2 examples. One with script, one without script. Both of them works.</p>
birt_ag
<p>Hi,</p><p>Still i'm not able to see any of the images in the report. I've set the resource folder also. used the image names which u mentioned.</p><p>one thing i observed now is there is no background image option for the master page.</p><p>I'm using BIRT 4.2.0 . Is it anything to do with this ?</p><p> </p><p> </p>
GLO_FR
<p>Strange.</p><p> </p><p>did you change your view in the advanced tab ? it looks like you are using the local poperties view</p><p> </p>
birt_ag
<p>Hi ,</p><p> </p><p>The background images are displaying in web viewer and pdf, but for doc view its not getting displayed. I need the background image for doc view .
</p><p> </p><p>Thank U</p>
GLO_FR
<p>Hi,</p><p> </p><p>if you export the report in doc format, they are some things you have to know :</p><p> </p><p>* the "no repeat" option is not supported by the word emitter. If you want just one time your watermark in the middle of the page, your image have to have the same dimension as your document (height and width)</p><p>* you can't have multiple watermark in the same document : only one. <span>Word does not support multiple background color/image.</span></p><p> </p><p>The actual rptdesign should work for a word export, but you will only have the first watermark and it will be repeated several times on the background.</p>
birt_ag
<p>ok..</p><p>Thanks a lot for the timely replies GLO_FR . It was of great help indeed .</p>
birt_ag
<p>Hi GLO_FR,</p><p> </p><p>The code snippet u gave for switching the masterpage is working perfectly. But i'm not able to get retrieve the Data-set value using script.</p><p> </p><p>unApproved = row["unapproved"];</p><p> </p><p>when i wrote this line in before factory for fetching the dataset value its throwing error..</p><p> </p><div style="color:#FF0000;"><div><div>ReferenceError: "row" is not defined. (/report/method[
@name="
;beforeFactory"]#4) (Element ID:1) </div><div> </div></div></div><p>Is it proper or any other way is there ? can u please help me on this ?</p><pre class="_prettyXprint">rptDesignHandle = reportContext.getReportRunnable().designHandle.getDesignHandle();myElement = rptDesignHandle.findElement("myelement");if (myValue == 1){myElement.setProperty("masterPage" , "Watermark 1");}else{myElement.setProperty("masterPage" , "Watermark 2");}</pre>
birt_ag
<p>HI GLO_FR,
I got to know how to grab the unapproved value.. </p><p> </p><p>But the masterpage is not getting switched as required.
I'm attaching the rpt and xml file which i created. I've added the script in the oncreate event for the table PMS1-Out</p><p> </p><p>Due to size limitation i've attached the zip file by renaming the rar file has txt. Once downloaded rename the extension to rar and extract the design file and xml file.</p><p> </p><p>Thank U</p><p> </p><p> </p>
GLO_FR
<p>Hi, if you want to switch the masterpage, you have to put some script on a report element (table label, chart.....) and have an action on the "masterpage" property. But you can't do it directly from your dataset.</p><p>One solution is to create a global variable on the "onFetch" event and use it on your report element.</p><p> </p><p>Check this example (rename Sample2.txt to Sample2.rar, then extract design)</p><p> </p><p>BTW, I think your last upload was not the good rptdesign+xml file</p>