Html2Image

Hi,
we want to generate business card images from html. Our business card template is outlook compatible. we have found no way (aspose.html, apose.words, aspose.pdf) to get the exactly same looking result. how can we convert attached html to png or jpeg with given width and height?
King regards
business card.zip (788 Bytes)

@dvtdaten

Thank you for contacting support.

You may convert HTML document to an image of any dimensions with Aspose.HTML for Java 19.3 using below code snippet:

HTMLDocument document = new HTMLDocument(dataDir + "business card.html");
HtmlRenderer renderer = new HtmlRenderer();
ImageDevice device = new ImageDevice(dataDir + "Test_out.png");
{
    device.getOptions().getPageSetup().setAnyPage(new Page(new Size(500, 700), new Margin(0, 0, 0, 0)));
    renderer.render(device, document);
}

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Hi,
if we want to convert this html-file html png with the given dimensions from the first html-tag, the output is too small.
output_real_table_dimensions .png (10.4 KB)
we have to multiply the given dimensions with 1.1 and resize the image again. The border isn’t rendered, the alignment of the text is wrong and kerning is also different.
output_table_dimensions x 1.1.png (9.7 KB)

we need an exact rendering of the given html…

@dvtdaten

Would you please share the code snippet you are using. We have used above code snippet exactly and generated image has been attached for your kind reference. karte_out.png

Hi,
we tested the code provided by you. As you can see in the attached Image comparison.png (25.8 KB), there are a few problems:

  • Table and Div borders and box shadows are not rendered
  • Kerning of Arial (and others) is different
  • we set zero margin, but there is whitespace around the image grafik.png (14.6 KB)
    (16.9 KB)

Code used:
HTMLDocument htmlDocument = new HTMLDocument(dataDir + this.inputFile);
HtmlRenderer htmlRenderer = new HtmlRenderer();
ImageDevice imageDevice = new ImageDevice(dataDir + this.outputFile);
imageDevice.getOptions().setHorizontalResolution(new Resolution(300, UnitType.DPI));
imageDevice.getOptions().getPageSetup().setAnyPage(new Page(new Size(322, 208), new Margin(0, 0, 0, 0)));
new License().setLicense(“Aspose.Total.Java.lic”);
htmlRenderer.render(imageDevice, htmlDocument);

Testfiles: testfiles.zip (12.2 KB)

@dvtdaten

Thank you for elaborating it further.

We have logged a ticket with ID HTMLJAVA-241 in our issue management system for further investigations. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

any updates?

@dvtdaten

Please note that the ticket has been logged under free support model and will be investigated on first come first serve basis. Therefore, it may take some months to resolve. As soon as we have some definite updates or ETA regarding ticket resolution, we will let you know.

Moreover, we also offer Paid Support , where issues are used to be investigated with higher priority. Our customers, who have paid support subscription, report their issue there which are meant to be investigated urgently. In case your reported issue is a blocker, you may please consider subscribing for Paid Support. For further information, please visit Paid Support FAQs.