On April 27, 2024, our Sign-in and Create Account options will be unavailable from 9am-12pm ET. During this maintenance window, developer account access and free trial registration will be unavailable.

inline base64 image in html output

JasonW
edited 2013 11 in DevShare Downloads #1
The beforeFactory script reads a image url and base 64 encodes the image. It then creates an image src tag
importPackage(Packages.javax.imageio);
importPackage(Packages.java.io);
importPackage(Packages.java.net);
importPackage(Packages.java.lang);
importPackage(Packages.org.apache.commons.codec.binary)
importPackage(Packages.java.lang);
var myurl = URL("http://tomcat.apache.org/images/tomcat.gif");
var img = ImageIO.read(myurl);
bas = new ByteArrayOutputStream();
ImageIO.write(img, "gif", bas);
bas.flush();
encodedimga = Base64.encodeBase64(bas.toByteArray());
encodedimg = new String( encodedimga, "utf-8");
bas.close();
imgsrc = "data:image/gif;base64,"+encodedimg+"\"";
<br />
A text item is then added to the report with the following expression.
&lt;img src=&lt;VALUE-OF&gt;imgsrc&lt;/VALUE-OF&gt; +" alt="what ever" /&gt;