Image is not showing up when converting html to image - Java

Sample Html

<table style="margin-left:20px; padding-top:320px;font-size: 100px">
    <tr>

        <td >
            Price:18$
        </td>
        <td><img src="https://dummyimage.com/300" alt="test" width="200px"></td>
    </tr>
</table>```

@joshuaemerson

It seems that you are experiencing an issue with images not rendering when converting HTML to an image using Aspose. Unfortunately, Aspose.Imaging does not support rendering HTML content directly into images, as it does not recognize HTML tags.

To achieve the conversion of HTML to an image, you should consider using Aspose.HTML, which is specifically designed for this purpose. Aspose.HTML allows you to convert HTML documents into various image formats, such as BMP, JPEG, PNG, and TIFF.

Here’s a brief overview of how you can use Aspose.HTML to convert your HTML to an image:

  1. Initialize the HTML Document: Load your HTML content into an HTMLDocument.
  2. Set Rendering Options: Specify the output format and any other rendering options you may need.
  3. Render the HTML: Use the rendering methods provided by Aspose.HTML to convert the HTML to an image.

Here is a simple code example in C# to illustrate the process:

using Aspose.Html;
using Aspose.Html.Rendering.Image;

// Load the HTML document
var document = new HTMLDocument("path/to/your/file.html");

// Create an instance of ImageDevice
var device = new ImageDevice(new ImageRenderingOptions(ImageFormat.Png));

// Render the HTML document to an image
document.RenderTo(device, "output/image.png");

Make sure to replace "path/to/your/file.html" with the actual path to your HTML file and specify the desired output image format.

For more detailed guidance, you can refer to the tutorials available for converting HTML to various image formats using Aspose.HTML here and here.

If you have any further questions or need assistance, feel free to ask!

Sources:
[1]: How to render html in image using Aspose.Imaging
[2]: Converting HTML to Various Image Formats Tutorials
[3]: Generate JPG Images by ImageDevice in .NET with Aspose.HTML

Sample Java code i’m using to convert to image

com.aspose.html.HTMLDocument(“email-aspose–1.html”);
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(ImageFormat.Jpeg);
com.aspose.html.converters.Converter.convertHTML(document, options, streamProvider.lStream);
inputStream = streamProvider.lStream.stream().findFirst().orElse(null);

@joshuaemerson

Have you tried with the latest version of the API? Can you please share the generated image with us as well?

Hi, Yes, i’ve tried with latest version of API. Here is the generated image
image–aspose-1.png (51.7 KB)

@joshuaemerson

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): HTMLJAVA-1853

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.