Home
Analytics
dynamic text(clob dataset > html content) not showing the html embeded image base64
jiunarayan
<p>HI All,</p>
<p> </p>
<p>I have a html content in Database. I am showing html content in pdf through dynamic text pallete.</p>
<p>Inside the <span style="font-size:18px;">html content I have some embeded base64 image</span>. This html embeded base64 image is<span style="font-size:18px;"> not displaying in pdf</span>. but in preview tab its showing. But same html content in browser is showing the image.</p>
<p> </p>
<p>Please help me to display the html embeded image</p>
<p> </p>
<p> </p>
<p>Also attach rptdesign file, here I have hardcoded html content.
Find more posts tagged with
Comments
JFreeman
<p>The issue is that you are using HTML tags in an HTML element to display the base64 image. This code is all processed client side which is why the output is not displayed in a PDF output.</p>
<p> </p>
<p>In order to display the base64 image for PDF as well, you can use a dynamic image element with scripting in the onCreate of the image element to decode the base64.</p>
<p> </p>
<p>I was able to achieve this using the following code in the onCreate of the image element:</p>
<pre class="_prettyXprint _lang-js _linenums:1">
importPackage(Packages.javax.imageio);
importPackage(Packages.java.io);
importPackage(Packages.sun.misc);
decoder = new BASE64Decoder();
decodedBytes = decoder.decodeBuffer(this.getRowData().getColumnValue("CLOBData"));
this.data =decodedBytes;
bais = new ByteArrayInputStream( decodedBytes);
bufimg = ImageIO.read(bais);
this.setHeight(bufimg.getHeight() +"px");
this.setWidth(bufimg.getWidth() +"px");
</pre>
jiunarayan
<p>Thanks JFreeman.</p>
<p> </p>
<p>I tried what you provided the code to generate the image from encoded base64 content and yes it works.</p>
<p> </p>
<p>And it works only for Image Element (from Pallete) and clob data should be only encoded base64.</p>
<p> </p>
<p>Is there a way where I can display HTML content (table<span style="color:#00ff00;">s</span>,text<span style="color:#00ff00;">s</span>,base64Image<span style="color:#00ff00;">s</span>) all, as it is WYSIWYG. My objective is to show the html content WYSIWYG where the image will be in base64 encoded and also other html content?</p>
JFreeman
<p>I am not quite sure I am understanding your requirement.</p>
<p>Could you provide some additional details?</p>
<p> </p>
<p>The thing to keep in mind about using HTML tags in an HTML text element to decode a base64 image to be displayed is that that is a client side operation which means that it requires the web browser while viewing it before the decoding will occur. This means that when converting to PDF, which occurs server side, the browser/client side operation of decoding the image will not occur.</p>
<p> </p>
<p>If you can provide some additional details about your requirement, we can see if there are additional options available.</p>
jiunarayan
<p>Thanks for the response again.</p>
<p> </p>
<p>Your comments were very clear and I understood that PDF viewer does not have the capability to show HTML image tag with data uri(base64) so in Birt itself the HTML tag is converted to the requirement to display data uri. </p>
<p> </p>
<p>Now my requirement is I have HTML content (table,image,..) And expectation is WYSIWYG in PDF viewer also. How will I do, due to image base64 I am unable to apply WYSIWYG? How will I achieve?</p>
jiunarayan
<p>Hi (J FreeMan),</p>
<p> </p>
<p>Hope you got my requirement. So I am trying to figure out how to render the html content coming from the CLOB, where in that html content the image is a data URI(base64). As html follows the principle WYSISYG and my issue is the image section(as discussed) is not populating, so is there any way to display the image content in the same html content (CLOB)?</p>
JFreeman
<p>You can set the dimensions of the dynamic image element in it properties. Although the image itself will not display within the Layout in the design, the element will expand to reflect the bounds specified for its size which will carry over to PDF output as well. Within this configuration the layout will be WYSIWYG when run in the web viewer as well as to PDF output.</p>
Katerina
<p>Hi,</p>
<p>I have the same problem, with an html text field that contains (among other things) an img tag with data URI src (base64) which does not show in the produced PDF. Did you manage to solve this jiunarayan?</p>
<p>Using a dynamic image element in a specific place in the report does not seem to be a possibility, as I do not know the contents of the HTML text field, that may or may not contain such an image tag. My report contains only a text field of type Html, as in the attached example in the beginning of this thread, and gets as input whole html documents. </p>
JFreeman
<p>Displaying a base64 image through HTML code will not show in PDF output. As I described earlier, this is because the decoding of img elements is a client side operation that requires a browser to interpret and decode the image.</p>
<p> </p>
<p>As a workaround you, could read the code that will be displaying within the text field. Then, dynamically strip out the img element and copy the base64 text into a dynamic image element before the report is rendered. If no img elements are detected you could remove the dynamic image element from the report before it is generated. Alternatively, you could also dynamically create the dynamic image elements within the report as they are detected.</p>
Sandeep Lulla
<p>I want to dynamically create the image elements and add them to a grid as described above.</p>
<p> </p>
<p>Here is my code : </p>
<div>importPackage (Packages.org.eclipse.birt.report.model.api);</div>
<div>importPackage (Packages.org.eclipse.birt.report.model.api.elements);</div>
<div>importPackage(Packages.java.lang);</div>
<div>importPackage(Packages.java.net);</div>
<div>importPackage(Packages.javax.imageio);</div>
<div>importPackage(Packages.java.io);</div>
<div>importPackage(Packages.sun.misc);</div>
<div> </div>
<div>var designHandle = reportContext.getDesignHandle();</div>
<div> </div>
<div>grid = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("data_grid");</div>
<div>elementFactory = reportContext.getReportRunnable().designHandle.getElementFactory();</div>
<div> </div>
<div>rowParm = new RowOperationParameters(2,-1,1);</div>
<div>grid.insertRow(rowParm);</div>
<div>tblCell = grid.getCell(1,0);</div>
<div>decoder = new BASE64Decoder();</div>
<div>decodedBytes = decoder.decodeBuffer(base64Data); //assume base64Data is base64 string for the image</div>
<div>img1 = elementFactory.newImage("tblCell");</div>
<div>
<div>img1.setSource("expr");</div>
<div>img1.setValueExpression("");</div>
<div>img1.setOnCreate(function() {System.out.println("onCreate"); this.data=decodedBytes;});</div>
<div>
<div>bais = new ByteArrayInputStream( decodedBytes);</div>
<div>bufimg = ImageIO.read(bais);</div>
<div>img1.setHeight(bufimg.getHeight() +"px");</div>
<div>img1.setWidth(bufimg.getWidth() +"px");</div>
<div>tblCell.getContent().add(img1);</div>
</div>
</div>
<p> </p>
<p>But the image does not show up still. Also the onCreate of the image element is not called. The above example says this.data = decodedBytes will show the image. But i want to assign bytes from the parent container. But it still doesnt show up.</p>
<p> </p>
<p>Please help me resolve this.</p>
JFreeman
<p>Are you getting any errors when you run this code?</p>
<p>The first thing that jumps out at me is your setOnCreate() call. This method takes a string but you are not passing it a string.</p>
<p> </p>
<p>Also, where do you have this code placed in your report?</p>
<p> </p>
<p>Since, the setOnCreate method takes a string, I do not believe you are going to be able to decode the string outside of the dynamic images onCreate and pass it in. Instead I think you will have to pass the base64 string and perform the decoding in onCreate directly.</p>
Sandeep Lulla
<p>Thanks Jessee.</p>
<p> </p>
<p>I have put this code in the afterFactory method of the report.</p>
<p> </p>
<p>I am trying to setOnCreate() method because i do not know how many images are to be added and that is based on input from the dataset.</p>
<p> </p>
<p>So i am generating image element dynamically using </p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">img1 = elementFactory.newImage("tblCell");</span></p>
<p> </p>
<p>and adding it to the grid using <span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">tblCell.getContent().add(img1);</span>.</p>
<p> </p>
<p>I do not get any errors but the image does not appear on the result.</p>
<p> </p>
<p>I want to set the image data and then add it to the grid.</p>
<p> </p>
<p>Attaching the report design.</p>
<p> </p>
<p>Thanks</p>
<p>Sandeep</p>
JFreeman
<p>There are a couple of issues with your current setup.</p>
<p> </p>
<p>The first is having the code in afterFactory. That is too late in the generation phase to be dynamically adding the elements. Instead it needs to be moved up to beforeFactory.</p>
<p> </p>
<p>The second, is with the function you are passing into the onCreate of the image. You are passing an anonymous function which will not be executed. You either need to give the function a name and explicitly call it or pass the script outside of a function.</p>
<p> </p>
<p>With these changes, the image will be created and displayed properly.</p>
<p>Take a look at the attached, modified version of your sample report where I have made these changes.</p>
Sandeep Lulla
<p>Thanks Jesse. It worked.</p>
<p> </p>
<p>As we have written this code in beforeFactory, I have a question regarding how to manipulate the data from the dataset, since that data would be available only after beforeFactory as per <a data-ipb='nomediaparse' href='
http://www.eclipse.org/birt/documentation/integrating/scripting.php'>http://www.eclipse.org/birt/documentation/integrating/scripting.php</a></p>
;
<p> </p>
<p>Sandeep</p>
JFreeman
<p>What are you needing to do with the data from the data set?</p>
<p> </p>
<p>If you need to query it with some logic to determine which modifications to make, you can use the Design Engine API (DEAPI) to manually query the data set in beforeFactory and iterate the results.</p>
<p> </p>
<p>Take a look at the example report in this post: <a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/topic/35930-running-a-query-in-the-initalize/?p=133369'>http://developer.actuate.com/community/forum/index.php?/topic/35930-running-a-query-in-the-initalize/?p=133369</a></p>
;
<p> </p>
<p>it shows some different examples of how to use DEAPI to query a data set.</p>
sweetas
<p>I found a solution how to render embedded images in PDF. Please check my answer in this topic: <a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/topic/37123-html-embedded-images-in-pdf/?p=140347'>http://developer.actuate.com/community/forum/index.php?/topic/37123-html-embedded-images-in-pdf/?p=140347</a></p>
;