Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8076117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:11:44+00:00 2026-06-05T15:11:44+00:00

I am trying to convert a HTML string into a .PNG file. Thanks to

  • 0

I am trying to convert a HTML string into a .PNG file. Thanks to Nick Johnson who pointed me to GAE Conversion API see previous post Here.

I use the GAE Conversion API
which works but my images in my HTML string doesn’t display.

In the Documentation on GAE Conversion API there is a reference to Adding Assets and a mention of static/icon.gif which I think may address my problem but that documentation is incomplete.

Can anyone please assist?

My HTML conversion to .PNG works but all images e.g

<img src="http://mydomain.com/image.gif> doesn’t print yet http://mydomain.com/image.gif is available.

Thanks

PB

Update 1:
According to the documentation, I should create seperate asset for each image and name must match the 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();
        }

winningNumbers 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 notification.getMessage() 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">&nbsp;</td> 
                <td colspan="3" valign="top" class="bbottomYellow">&nbsp;</td> 
            </tr> 
            <tr> 
                <td valign="top" bgcolor="#00A452">&nbsp;&nbsp;<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">&nbsp;<strong>&nbsp;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>

Notification class signature is:

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; //e.g email, fax etc
    public NotificationClientType getClient() {
        return client;
    }
    public void setClient(NotificationClientType client) {
        this.client = client;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
    public String getApi_key() {
        return api_key;
    }
    public void setApi_key(String api_key) {
        this.api_key = api_key;
    }
    public String getSecret_key() {
        return secret_key;
    }
    public void setSecret_key(String secret_key) {
        this.secret_key = secret_key;
    }
    public String getDeliveryAddress() {
        return deliveryAddress;
    }
    public void setDeliveryAddress(String deliveryAddress) {
        this.deliveryAddress = deliveryAddress;
    }
    public Result getResult() {
        return result;
    }
    public void setResult(Result result) {
        this.result = result;
    }

Some Feedback.
No difference in result. I guess return out.toByteArray() solved NPE which I accidentally caused.

The expected result is below: The same HTML string sent as email yields:
expected result

GAE conversion result is:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:11:45+00:00Added an answer on June 5, 2026 at 3:11 pm

    The documentation says that the name of the asset should match the src attribute of the img tag.

    Here is a python code I tried in the interactive console, and it actually produced the two images

    from google.appengine.api import urlfetch
    from google.appengine.api import conversion
    
    url = "http://a0.twimg.com/profile_images/77186109/favicon_reasonably_small.png"
    asset = conversion.Asset("text/html", '<b>some data</b><br/><img src="a.png"/><img src="%s"/><br/>Foo' % url, "test.html")
    conversion_obj = conversion.Conversion(asset, "image/png")
    
    img_response = urlfetch.fetch(url)
    image1 = conversion.Asset('image/png', img_response.content, "a.png")
    image2 = conversion.Asset('image/png', img_response.content, url)
    conversion_obj.add_asset(image1)
    conversion_obj.add_asset(image2)
    
    result = conversion.convert(conversion_obj)
    print result.error_text
    
    print repr(result.assets[0].data)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert an html file to xml. It is working for
I'm trying convert all special chars into HTML safe entities on their way into
I am trying to convert a html String and set it to a TextView
When trying to convert excel file to Html using org.apache.poi.ss.examples.html.ToHtml.create(...), the call crashes with
I am trying to convert HTML numeric character references to a string. Example: &#12452;&#12473;
I'm trying to convert a string into an int so that I can keep
I'm trying to convert a string date value from a submitted form into an
For the longest time now I've been trying to convert HTML pages containing large
I'm trying to convert my knockoutJs html code to HAML, trying to achieve something
Intro I am in the process of trying to convert my first HTML/CSS design

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.