I am trying to convert an HTML string to a .PNG file. Thanks to Nick Johnson , who pointed me to the GAE Conversion API , see previous post here .
I use the GAE conversion API which works, but my images in my HTML line are not displayed.
The GAE Conversion API documentation has a link to Adding Assets and a mention of static/icon.gif , which I think may address my problem, but this documentation is incomplete.
Can anyone help?
My HTML to .PNG conversion works, but all images like
<img src="http://mydomain.com/image.gif> is not yet printed http://mydomain.com/image.gif .
thanks
RV
Update 1: According to the documentation, I have to create a separate resource for each image, and the name must match src attr.
List<Asset>assets = new ArrayList<Asset>(); try { Asset asset = new Asset("text/html", notification.getMessage().getBytes("UTF-8"), "testfile.html"); assets.add(asset); } catch (UnsupportedEncodingException e) { e.printStackTrace(); }
winNumbers is just a number expecting 5 0r 6 numbers
for (String n : winningNumbers) { String url = "http://www.someURL.com/img/balls/" + n +".gif"; Asset e = new Asset("image/gif", loadGIFByte(url), url); assets.add(e); } Document document = new Document(assets); //Here I want to convert everything, the images and html to a .PNG MIMETYPE. Conversion conversion = new Conversion(document, "image/png"); ConversionService service = ConversionServiceFactory.getConversionService(); ConversionResult conversionResult = service.convert(conversion); private byte[] loadGIFByte(String urlGIF) { System.out.println("Loading GIF for "+ urlGIF); OutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[1536]; int count = 0; try { URL u = new URL(urlGIF); InputStream reader = u.openStream(); while ((count = reader.read(buf)) >= 0) { out.write(buf, 0, count); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return buf; } }
Update 2:
A typical .getMessage () notification should return;
<html> <head> <style type="text/css"> /** Add css rules here for your application. *//** Example rules used by the template application (remove for your app) */h1 { font-size: 2em; font-weight: bold; color: #777777; margin: 40px 0px 70px; text-align: center;}.sendButton { display: block; font-size: 16pt;}/** Most GWT widgets already have a style name defined */.gwt-DialogBox { width: 400px;}.dialogVPanel { margin: 5px;}.serverResponseLabelError { color: red;}/** Set ids using widget.getElement().setId("idOfElement") */#closeButton { margin: 15px 6px 6px;}.usefulLinksUL{list-style-type:none;margin:0;padding:0;display:block;font-weight:bold;#background-color:#FFD700;width:180px;}.usefulLinksAnchor{a:link,a:visited;text-decoration:none;a:hover,a:active;}.note {font-size: 80%;background-color: #FEF49E;/**background-color: #d8da3d;*/border: 1px solid #D0C98D;-webkit-box-shadow: -8px 5px 5px rgba(0, 0, 0, 0.3);}.note-title {margin: 5px 5px 0 5px;padding: 4px;-moz-border-radius: 5px;-webkit-border-radius: 5px;background-color: #D0C98D;color: white;font-weight: bolder;}.note-content {margin: 5px;background: transparent;border: none;overflow: hidden;}.container { width:50px; overflow:hidden }.cube { width:150px; height:150px; float:left;}#rounded-corner{ font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif; font-size: 12px; margin: 5px; /*width: 180px;*/ text-align: left; border-collapse: collapse;}#rounded-corner thead th.rounded-company{ background: #b9c9fe url('img/latestResult/left.png') left -1px no-repeat;}#rounded-corner thead th.rounded-q4{ background: #b9c9fe url('img/latestResult/right.png') right -1px no-repeat;}#rounded-corner th{ padding: 8px; font-weight: normal; font-size: 13px; color: #039; background: #b9c9fe;}#rounded-corner td{ padding: 8px; background: #e8edff; border-top: 1px solid #fff; color: #669;}#rounded-corner tfoot td.rounded-foot-left{ background: #e8edff url('img/latestResult/botleft.png') left bottom no-repeat;}#rounded-corner tfoot td.rounded-foot-right{ background: #e8edff url('img/latestResult/botright.png') right bottom no-repeat;}#rounded-corner tbody tr:hover td{ background: #d0dafd;}.latestLotto{ background-color: #C3D9FF; border: 1px solid #87B3FF; cursor: default; }.bbottomyello {border-bottom: 1px solid #CFA55B;}.onGreenBackground {font-family: Arial, Helvetica, sans-serif;font-size: 11px;color: white;font-style: normal;}.btopbottomYellow {border-top: 1px solid #FFCB05;border-bottom: 1px solid #FFCB05;}.bbottomYellow {border-bottom: 1px solid #FFCB05;}h3 {font-family: Arial, Helvetica, sans-serif;font-size: 11px;color: #EB0900;} </style> </head> <body> <table width="100%" height="123" border="0" cellpadding="0" cellspacing="0" bgcolor = "#FFFFFF"> <tbody><tr> <td width="47%" class="bbottomyello"><img src="http://mylottoshop.appspot.com//img/lotto_top_left_home.gif" alt=""></td> <td width="16%" class="bbottomyello"> </td> <td colspan="3" valign="top" class="bbottomYellow"> </td> </tr> <tr> <td valign="top" bgcolor="#00A452"> <span class="onGreenBackground"><span class="onGreenBackground">Wednesday, June 13 2012</span></span></td> <td colspan="4" bgcolor="#00A452" class="onGreenBackground">Latest Results: Confirmed</td> </tr> <tr> <td height="23" colspan="5" class="btopbottomYellow"> <strong> Winning Numbers</strong></td> </tr> <tr> <td height="31" colspan="2" class="bbottomYellow"> <div align="center"> <img src="http://mylottoshop.appspot.com//img/balls/9.gif" width="30" height="40"> <img src="http://mylottoshop.appspot.com//img/balls/20.gif" width="30" height="40"> <img src="http://mylottoshop.appspot.com//img/balls/14.gif" width="30" height="40"> <img src="http://mylottoshop.appspot.com//img/balls/16.gif" width="30" height="40"> <img src="http://mylottoshop.appspot.com//img/balls/43.gif" width="30" height="40"> <img src="http://mylottoshop.appspot.com//img/balls/41.gif" width="30" height="40"> </div> </td> <td width="12%" height="31" valign="middle" class="bbottomYellow"><h3>Bonus<br> Ball:</h3></td> <td width="14%" class="bbottomYellow"> <div align="center"><img src="http://mylottoshop.appspot.com//img/balls/13.gif" width="34" height="40"></div></td> </tr> </tbody></table></body> </html>
Signature of notification class:
public class Notification implements Serializable{ private static final long serialVersionUID = -8464293752450599178L; private Result result; private NotificationClientType client; private String message; private String api_key; private String secret_key; private String deliveryAddress;
Some feedback. No difference in the result. I assume return.toByteArray () solved the NPE, which I accidentally called.
Expected result below: the same HTML line sent by email: 
GAE conversion result:
