Home
Analytics
How to set a background image on the MasterPage?
PhilippArndt2
I like to set a background image for my report.
With the property editor it is only possible to set an image located in file system. Selection of attached images is not possible.
How can I set this image with java script?
Find more posts tagged with
Comments
mwilliams
Hi PhilippArndt2,
In the initialize script of your report, you can put the following script:
reportContext.getReportRunnable().getDesignInstance().getMasterPage("MasterPageName").getStyle().backgroundImage = "FileLocation";
Hope this helps.
PhilippArndt2
Hi mwilliams,
Thank you, exactly what I'm looking for
mwilliams
No problem. Glad to help. Let us know whenever you have questions.
sribk2012
<p>I have been searching around for this for last two days and I tried all I could but till now it is not working for me.</p><p> </p><p><em class='bbc'>Here is my problem.</em></p><p> </p><p><em class='bbc'>I want to setup multiple master pages and use those in my report. I'm using page break I'm able to set different master pages for each of my Grids. </em></p><p> </p><p><em class='bbc'>Issue: For each of the master pages I want to set different background images. and I want to set it at master pages. When i use Advanced-> Background->Background Image the background image is shown in designer but not in realtime or preview.</em></p><p> </p><p><em class='bbc'>Not sure if I'm missing anything. Then I tried above method discussed in this topic but no success.. </em></p><p> </p><p><em class='bbc'>Already I'm lagging by 2 days
.. need some help</em></p>
sribk2012
<p>Observation:</p><p> </p><p>when I set</p><p> </p><p>.... ("MasterPageName").getStyle().backgroundColor I see color changing</p>
sribk2012
<p>Anyone?.</p>
sribk2012
<p>hey!.. finally working.. **** image path was the issue.. BIRT sucks.. no error nothing</p>
mwilliams
<p>I'm sorry you were having issues getting you report to work properly. I'm glad you were able to find the issue though. Did you ever check the logs or run in debug mode when trying to find your issue?</p>
robilco
<p>Incidentially, I have added the capability to use embedded images as background images to my own patched version of BIRT</p><p> </p><p><a data-ipb='nomediaparse' href='
http://www.birt-exchange.org/forum/index.php/topic/27458-embedded-image-as-background-image/'>http://www.birt-exchange.org/forum/index.php/topic/27458-embedded-image-as-background-image/</a></p><p>and</p><p><a
data-ipb='nomediaparse' href='
https://bugs.eclipse.org/bugs/show_bug.cgi?id=386245'>https://bugs.eclipse.org/bugs/show_bug.cgi?id=386245</a></p><p> </p><p>Patch
contained in 2nd link</p>
mwilliams
<p>Thanks for the information! You might also make a devShare article for this, so it's easier to search!
</p>
revyve
<p>I know this is an old topic... but I was interested in trying to apply this fix since I ran into this, but didn't understand how to apply that patch. Any guidance or pointing me to the right resources / threads would be awesome. Thank you so much</p>
<p> </p>
<p>P.S. I'm using Eclipse/BIRT 4.4.2</p>
<p> </p>
<p>If this now works and patch is not relevant could you advise on how I use an embedded image in the background? thanks so much - complete noob to BIRT...</p>
JFreeman
<p>That bug report is still open and has not be resolved yet.</p>
<p>If you are also needing to use embedded images as background images, I would recommend voting for that bug report.</p>
<p> </p>
<p>Regarding the patch, that is a proposed, user submitted patch that does not look to have been fully tested or verified yet. As such, it is not a fully built patch, it is instead the source code details of the patch for various class files. In order to implement that patch, if you want to try it, you will need to download the 4.4.2 BIRT source code, make the changes to the class files in the patch and recompile with the changes in place.</p>
<p> </p>
<p>Do you have a specific requirement that is forcing you to use embedded images?</p>
revyve
<p>Yeah, I've been tasked with creating some reports and putting in a cover page that has our corporate branding on it (which has gradients all over the place... sigh). But they want the report title pulled from SQL on the first page...</p>
<p> </p>
<p>So current design is a master page with background... and then second master page for body of report.</p>
<p> </p>
<p>then I hope to reuse this initial report as template for all the various reports I need to create with sql and such.</p>
<p> </p>
<p>So I'd like to see if I can actually figure out how to compile this. I'm not having much luck trying to track down how to accomplish that though. it's not as intuituve as I'd hoped. everything I've downloaded has been jar files with .class files. but I don't know how to edit the class files themselves?</p>
<p> </p>
<p>Is there a guide or walkthrough on how to accomplish this? I'm willing to do the work just can't find out how to do it. (and I've been searching all day... sigh)</p>
<p> </p>
<p> </p>
<p>worst case is I might try and photoshop the background and just break up the cells and hope it all lines up properly. and make sure the title part has a solid background or something. </p>
<p> </p>
<p> </p>
<p>Hope that makes sense and thanks for the reply</p>
JFreeman
<p>Okay we dug into this a bit more and have found a way to set an embedded image as the background image on the master page with a bit of script in beforeFactory:</p>
<pre class="_prettyXprint _lang-js">
var myByteArray = reportContext.getDesignHandle().findImage("myEmbeddedImageName.jpg").getData(reportContext.getDesignHandle().getModule());
var encodedStr = java.util.Base64.getEncoder().encodeToString(myByteArray);
reportContext.getDesignHandle().findMasterPage("myMasterPageName").setStringProperty("backgroundImage",("data:image/png;base64," + encodedStr));
</pre>
<p>The one caveat is that package java.util.Base64 is only available in Java 8+ so you will need to make sure you are running on a Java 8 JVM for it to work.</p>
<p> </p>
<p>With a Java 8 JVM, this will read the embedded image as a Byte Array, convert it into a base64 string, and then pass that base64 string into the backgroundImage properly on the master page.</p>
<p> </p>
<p>I have also attached a report design created in 4.4.2 with this code in place for reference.</p>
revyve
<p>So I tried your report in both 442 and 4.5 but still not getting a background image when I just run the report as a word doc. I also made sure that it was using java 8 by adding the -vm line to the .ini file and pointing it to the 1.8jdk and removing all previous versions of java. So sorry, not sure what I'm doing wrong here. </p>
<p> </p>
<p>Thank you so much for helping me with this.</p>
JFreeman
<p>I suppose there is more than one caveat of this approach. This method relies on client side processing to decode the image from the generated base64 string. This means it will be limited to rending options where the client side decoding can execute such as the web viewer or HTML output. It will not work with outputs such as DOC, PDF, or XLS.</p>
<p> </p>
<p>Is it possible for you to store and obtain the image from a location other than embedded within the report design?</p>
revyve
<p>Thanks! Yeah I'm looking into the web option, but not very hopeful that I'll get access to a web server. We'll see. What I started doing that kinda sucks is to just put the text on the background image in photoshop and pull that in a cell as a normal embedded image and that's working. Just means instead of writing some dynamic text to put in a report title I have to create a cover page for each report... but... it does work so in interests of time that's probably how I'll proceed. Thank you for looking into this for me and for your time and effort. Can't say it enough. Very appreciative. Thank you</p>
JFreeman
<p>You're welcome.</p>
<p> </p>
<p>If you can get access to the images and store them locally within your designers project directory, then you could use the URI option to set the images as the background images. Then when you publish the reports to be run, you will just have to publish the images to the server as well.</p>
<p> </p>
<p>If you can get the images, I think that would be a better option than having to manually photoshop something together for each report.</p>
OmJee
<p> <span>var</span> encodedStr = javax.xml.bind.DatatypeConverter.printBase64Binary(myByteArray);</p>
<p> </p>
<p> </p>
<p>by using above methods you can setup image, i fixed ur reports it works fine now.</p>
Naresh.A
<p>I have to set the image to the background of the master page in birt 4.6 version</p>
<p> </p>
<p>In report its showing the background image properly..</p>
<p> </p>
<p>When i place the report and image in the application ...</p>
<p> </p>
<p>When i run the application image is not showing in the report ...</p>
<p> </p>
<p>anaresh2011@gmail.com</p>