Home
Analytics
Display images usign "View Report as PDF"
cbagnoli
Greetings.
I would like to display photographs of workers in a report. These are stored in the database in 'base64' format.
Using 'Dynamic Text': '<img src="data:image/jpg;base64,' + row["foto"] + '" alt="Sin Foto" />', I can view the photos with HTML but not PDF. It is noted in the list the phrase 'Sin Foto'.
I would like to know how to include these images dynamically, without the presence of the original photo file (*. jpg, png, etc.).
Thank you.
Find more posts tagged with
Comments
JasonW
If the column value is a string you should be able to use a image item and set its type to dynamic image and use an onCreate script like:
importPackage(Packages.javax.imageio);
importPackage(Packages.java.io);
importPackage(Packages.sun.misc);
decoder = new BASE64Decoder();
decodedBytes = decoder.decodeBuffer(this.getRowData().getColumnValue("base64imagecolumn"));
this.data =decodedBytes;
bais = new ByteArrayInputStream( decodedBytes);
bufimg = ImageIO.read(bais);
this.setHeight(bufimg.getHeight() +"px");
this.setWidth(bufimg.getWidth() +"px");
Jason
cbagnoli
Thanks Jason for your quick response.<br />
<br />
Indeed the field type is text.<br />
Following your instructions I copied the lines of code shown in the image item 'On create', but when I run the 'Preview' I get the following errors:<br />
The following items have errors:<br />
<br />
Image (id = 3061):<br />
+ There are errors evaluating script "importPackage(Packages.javax.imageio);<br />
importPackage(Packages.java.io);<br />
importPackage(Packages.sun.misc);<br />
decoder = new BASE64Decoder();<br />
decodedBytes = decoder.decodeBuffer(this.getRowData().getColumnValue("base64imagecolumn"));<br />
this.data =decodedBytes;<br />
bais = new ByteArrayInputStream( decodedBytes);<br />
bufimg = ImageIO.read(bais);<br />
this.setHeight(bufimg.getHeight() +"px");<br />
this.setWidth(bufimg.getWidth() +"px");":<br />
The choice of Java constructor decodeBuffer matching JavaScript argument types (null) is ambiguous; candidate constructors are: <br />
class [B decodeBuffer(java.lang.String)<br />
class [B decodeBuffer(java.io.InputStream) (/report/body/table[
@id="
;2431"]/detail/row[
@id="
;3059"]/cell[
@id="
;3060"]/image[
@id="
;3061"]/method[
@name="
;onCreate"]#5) <br />
<br />
And when I run it in PDF format displays:<br />
The resource of this report item is not reachable.<br />
<br />
Carlos.
JasonW
Carlos
is the image element in a table? It looks like you used the wrong column name for:
this.getRowData().getColumnValue("base64imagecolumn"));
Look at the binding tab and get the name of the column that has the image and replace base64imagecolumn with the correct column name.
Jason
cbagnoli
Sorry Jason,
Effectively I replaced it. Where said "base64imagecolumn" I wrote "foto".
decodedBytes = decoder.decodeBuffer(this.getRowData().getColumnValue("foto"));
The content of this field was coded with PHP as follows: base64_encode (file_get_contents($photo));
But now, the 'preview' is generating the same errors and generated PDF file can not be opened.
Thanks in advance and see you tomorrow.
Carlos.
cbagnoli
Thank you very much.
Subject closed.
For some strange reason, I had to reload the pictures of workers in the database, and this solved the problem.
I only added a few details to your guidelines to avoid an error message if the worker had no photo. And sized to fit the template. This was:
if (this.getRowData().getColumnValue("foto") != null) {
importPackage(Packages.javax.imageio);
importPackage(Packages.java.io);
importPackage(Packages.sun.misc);
decoder = new BASE64Decoder();
decodedBytes = decoder.decodeBuffer(this.getRowData().getColumnValue("foto"));
this.data = decodedBytes;
bais = new ByteArrayInputStream(decodedBytes);
bufimg = ImageIO.read(bais);
this.setHeight("90px");
this.setWidth("80px");
}
Until next time.
Carlos.
wsm
<p>I have the same problem, when i view my report as HTML or in the web viewer, images are displayed correctly, but when i export the report as pdf i get this error message "The resource of this report item is not reachable.</p>
<p>I use Text item to show m image like this: <IMG src=<VALUE-OF>row["imageBase64"]</VALUE-OF> alt=""/></p>
<p> </p>
<p>Can anyone help me?</p>
<p> </p>
<p>Thanks</p>
<p> </p>
<p>Regards</p>
JFreeman
<p>As Jason indicated in the first reply on this thread, you will need to use use a dynamic image element instead.</p>
<p> </p>
<p>Take a look at this other thread on the topic for another code example: <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=132877'>http://developer.actuate.com/community/forum/index.php?/topic/35862-dynamic-textclob-dataset-html-content-not-showing-the-html-embeded-image-base64/?p=132877</a></p>
;