Home
Analytics
How to add Watermark image on report ?
bholenath
Hello All,
I would like to know following things regarding a watermark image on report :
1. Is watermark and background image one-and-the-same thing for BIRT reports?
2. If it is same, then can it be added programmatically - using Java API and not the design-time scripting ?
3. Can the orientation of the same be changed -- e.g. center of the page or diagonal across the page etc ?
I'm using BIRT 2.2 version
Any inputs over the topic will be very helpful for me.
Thanks in advance,
Cheers,
Amit
Find more posts tagged with
Comments
bholenath
Since I couldnt get any confirmation about the "watermark" and "background image" being one and the same for BIRT reports - I assumed that it IS the case.
I have found a way to add the background images to report -- through MasterPage -- at the runtime. Following code-snipped will achieve the results
boolean isNewPage = false;
SimpleMasterPageHandle simpleMasterPageHandle = null;
if(reportDesignHandle.getMasterPages().getCount() > 0)
simpleMasterPageHandle = (SimpleMasterPageHandle)reportDesignHandle.getMasterPages().get(0);
else{
simpleMasterPageHandle = reportDesignHandle.getElementFactory().newSimpleMasterPage("Simple MasterPage");
isNewPage = true;
}
simpleMasterPageHandle.setProperty("backgroundAttachment", "fixed");
simpleMasterPageHandle.setProperty("backgroundImage", "C:testJDJEditorsChoiceAward.jpg");
simpleMasterPageHandle.setProperty("backgroundPositionX", "50%");
simpleMasterPageHandle.setProperty("backgroundPositionY", "50%");
simpleMasterPageHandle.setProperty("backgroundRepeat", "no-repeat");
if(isNewPage)
reportDesignHandle.getMasterPages().add(simpleMasterPageHandle);
Any other approach over the same is most welcome. Thanks in advance.
Cheers,
Amit
rashad01
Hi,
I am also looking for something similar, I have to add a watermark to my report and it should appear only conditionally. That is it should be displayed only if type= DRAFT.
Can u help me with this??
n one more question, where do we put that above piece of code?? Is it put under the script tab, because i am not able to add anything to the script tab.?
Thanks and Regards,
Rashad
bholenath
Hi Rashad,
I'm using the code in my Java API - which is extending BIRT report engine to generate custom reports. And my objective was to add a watermark image to report at the runtime - through the API.
If you are adding the image at the design time then you can do so using the Image control from the Palette and using the Embedded Image option. Alternatively, you can select the Dynamic Image. For that you will have to set the Image Data to the following expression.
importPackage(Packages.java.io);
importPackage(Packages.java.lang);
var imageFileName = "C:testJDJEditorsChoiceAward.jpg";
var file = new File(imageFileName);
var ist = new FileInputStream(file);
var lengthi = file.length();
bytesa = new ByteArrayOutputStream( lengthi);
var c;
while((c=ist.read()) != -1){
bytesa.write(c);
}
ist.close();
bytesa.toByteArray();
This will load the image at run time. Instead of hard-coded name, you can parameterize it -- by creating a report parameter (say, bgImageName) and using
var imageFileName = params["bgImageName"];
Hope this helps.
Cheers,
Amit
rashad01
Thanks amit .. I'll try this out..
ilaya.p86
i have added watermarks on report and its coming fine for pdf and docs but its not working for xls...
do u have any idea, pls share us...
thanks
ilaya.p86
CBR
BIRT doesn't support images in XLS. So it's not possible to add the watermark image to the XLS Output using the default birt excel emitter. Not sure if a third party excel emitter plugin supports images on masterpages for xls. You can google for tribix excel or search the dev share to find another excel emitter that can handle images of user yaytay
megha_m
Hi Amit,
I saw your code regarding the background image, in a similar manner I need to add a logo as header and footer in the pdf generated. How can I do that?
Since I am pretty new to BIRT APIs thing I just wanted to know in your code what kind of object is reportDesignHandle?
Thanks in advance.
Megha