Home
Analytics
Image not making it to PDF Export
mmacmillan74
<p>Hi Everyone,</p>
<p> </p>
<p>I have a rather involved issue that I need help with.</p>
<p> </p>
<p>We have a text box on a report design. What happens is the report gets executed and a script onRender gets executed that encrypts an image (that the path is in the database). Sends to client as a url and executes a java script that then decrypts the image and use alternatiff to display the image in the textbox. Now for PDF export this will not work as it does not go to the client for the .js to decrypt and the textbox will not display the bytes. I have put code in that if it is a PDF export then generate the URL with image path as the SRC, but the report will not treat the textbox as an image and resolve the path.</p>
<p> </p>
<p>Is there anyway that anybody knows around this or ideas?</p>
<p> </p>
<p>Thanks,</p>
Find more posts tagged with
Comments
JFreeman
<p>What is the code you are using to "generate the URL with image path as the SRC"?</p>
<p>If the output is PDF, you may need to change the script to add an image element instead of using a text box.</p>
mmacmillan74
<p>Here is what I am using. I have obfiscated for proprietary reasons:</p>
<p> </p>
<p><span style="font-size:medium;"><span style="font-family:calibri;">importPackage( Packages.<app> ); (Scrubbed as proprietary)</span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;">{</span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;">imagelocation = "Image Location from Database";</span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;">if (reportContext.getOutputFormat() == "html"){</span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;"> if (imagelocation == null) {</span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;"> this.text = "<IMG name=\"test\" src=\"birt/AppImages/DefaultImage.gif\" height=\"150\" alt=\"Loading...\" title=\"Default Image\" >";</span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;"> } else {</span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;"> imagelocation = imagelocation.replace(/\\/g,"/");</span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;"> imagelocationplusID = imagelocation + "[" + reportContext.getPersistentGlobalVariable("<this is a variable that was set on the report initialize script>") + "]";</span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;"> encodedresult = "We encode the image location here";</span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;"> this.text = "<IMG name=\"test\" src=\"webcontent/birt/AppImages/thumbnailcheck.gif\" onLoad=\"<This is called via javascript to decode the image location for use with alternatiff> <Javascript method to get default image>(this,\'" + encodedresult + "\')\" onerror=\"<javascript method(this)\" height=\"150\" alt=\"Loading...\" title=\"Default Image\" >"; </span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;"> }</span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;"> } else {</span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;"> imageFilenameWithPath = <Get the front image path using the imagelocation variable>;</span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;"> this.text = "<IMG name=\"test\" src=" + imageFilenameWithPath + " onerror=\"<Javascript method to get default image>(this)\" >"; </span></span></p>
<p> </p>
<p><span style="font-size:medium;"><span style="font-family:calibri;"> } </span></span></p>
<p><span style="font-size:medium;"><span style="font-family:calibri;">}</span></span></p>
<p> </p>
<p><span style="font-size:medium;"><span style="font-family:calibri;">The else block is where I want to put the src to the image filename path for the text box but I venture to guess that a text box won't grab an image by default for obvious reasons. Do you know a quick way to change it to a image widget and set path?</span></span></p>
<p> </p>
<p><span style="font-size:medium;"><span style="font-family:calibri;">Thanks!!</span></span></p>
JFreeman
<p>Take a look at the sample report attached this post: <a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/topic/35862-dynamic-textclob-dataset-html-content-not-showing-the-html-embeded-image-base64/?p=137690'>http://developer.actuate.com/community/forum/index.php?/topic/35862-dynamic-textclob-dataset-html-content-not-showing-the-html-embeded-image-base64/?p=137690</a></p>
;
<p> </p>
<p>It's not 100% what you need but it should help you get started.</p>
<p>It has code that shows dynamically creating an image element and adding to a grid in the report. That particular example is for decoding a base64 image however there should only be a few changes required for a URL based image.</p>
mmacmillan74
<p>Thank you so much for the reply! That is for decoding base64 and placing in src. I am trying to just use the path to the image itself. Is there an example of that. </p>
<p> </p>
<p> imageFilenameWithPath = <Get the front image path using the imagelocation variable>;</p>
<p><span style="font-size:medium;"><span style="font-family:calibri;">this.text = "<IMG name=\"test\" src=" + imageFilenameWithPath + " onerror=\"<Javascript method to get default image>(this)\" >"; </span></span></p>
<p> </p>
<p><span style="font-size:medium;"><span style="font-family:calibri;">I don't know why that is not working. I see the code you wanted me to look at..how can I modify that to just do the path?</span></span></p>
<p> </p>
<p><span style="font-size:medium;"><span style="font-family:calibri;">I see:</span></span></p>
<p> </p>
<p>imgData1=str.split("<IMG src=\"data:image/png;base64,"); Do I need to modify this to remove the base64?</p>
<p> </p>
<p>Do I just use the setURL message that is commented out and skip all the base64 decoding?</p>
<p> </p>
<p>img1 = elementFactory.newImage(</p>
<p>"tblCell");</p>
<p>//img1.setURL("<a data-ipb='nomediaparse' href='
http://vk.com/images/gifts/256/44.jpg'>http://vk.com/images/gifts/256/44.jpg")</a></p>
;
<p>img1.setSource(</p>
<p>"expr");</p>
<p>img1.setValueExpression(</p>
<p>"");</p>
<p>img1.setOnCreate(</p>
<p>"System.out.println(\"onCreate\"); this.data=decodedBytes;");</p>
<p>System.out.println(</p>
<p>"Hello1");</p>
<p> </p>
<p><span style="font-size:medium;"><span style="font-family:calibri;">Any ideas. Thanks a lot!!</span></span></p>
JFreeman
<p>You can dynamically add an image element that is URL based like this:</p>
<pre class="_prettyXprint _lang-js">
var grid = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("myGridName");
var tblCell = grid.getCell(0,0);
var elementFactory = reportContext.getReportRunnable().designHandle.getElementFactory();
var img1 = elementFactory.newImage("tblCell");
img1.setSource("url");
img1.setOnCreate("this.URL = \"http://vk.com/images/gifts/256/44.jpg\";");
tblCell.getContent().add(img1);
</pre>
<p>That will create the image and add it to the first cell in the grid that is being hooked.</p>
<p> </p>
<p>I have also attached a simple sample report with this code in place for reference.</p>