Hello we receive the following exception when trying to convert an html file to pdf using the Aspose.HTML library.
Aspose.HTML version 18.5
java.awt.HeadlessException
at sun.awt.HeadlessToolkit.getScreenSize(HeadlessToolkit.java:284)
at com.aspose.html.internal.p230.z8.(Unknown Source)
at com.aspose.html.Configuration.initializeServices(Unknown Source)
at com.aspose.html.Configuration.(Unknown Source)
at com.aspose.html.HTMLDocument.(Unknown Source)
at com.aspose.html.HTMLDocument.(Unknown Source)…
Conversion Code:
com.aspose.html.rendering.pdf.PdfRenderingOptions pdfOptions = null;
com.aspose.html.rendering.pdf.PdfDevice pdfDevice = null;
com.aspose.html.rendering.HtmlRenderer htmlRenderer = null;
com.aspose.html.HTMLDocument htmlDocument = null;
try {
pdfOptions = new com.aspose.html.rendering.pdf.PdfRenderingOptions();
Margin m = new Margin(9, 17, 9, 9);
Size s = new Size(816, 1056);
Page p = new Page(s,m);
pdfOptions.getPageSetup().setAnyPage(p);
pdfDevice = new com.aspose.html.rendering.pdf.PdfDevice(pdfOptions, newPdfFile.getPath());
htmlRenderer = new com.aspose.html.rendering.HtmlRenderer();
htmlDocument = new com.aspose.html.HTMLDocument(newHtmlFile.getPath());
htmlRenderer.render(pdfDevice, htmlDocument);
} catch(Exception e) {
//Exception code
} finally {
if (htmlDocument != null)
htmlDocument.dispose();
if (htmlRenderer != null)
htmlRenderer.dispose();
if (pdfDevice != null)
pdfDevice.dispose();
}