HeadlessException when converting HTML to PDF (Java)

Hello,

We are moving our tests from Jenkins to GitLab CI. Since GitLab doesn’t provide graphical environment, some of our tests started to fail with HeadlessException.

Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.aspose.html.utils.YV$1.invoke(Unknown Source)
	at com.aspose.html.utils.YV.getWindowSize(Unknown Source)
	at com.aspose.html.utils.ajH.<init>(Unknown Source)
	at com.aspose.html.utils.UB.a(Unknown Source)
	at com.aspose.html.utils.UC.b(Unknown Source)
	at com.aspose.html.utils.Ra.a(Unknown Source)
	at com.aspose.html.utils.QY.g(Unknown Source)
	at com.aspose.html.utils.RW.acZ(Unknown Source)
	at com.aspose.html.utils.RW.adK(Unknown Source)
	at com.aspose.html.utils.YM.a(Unknown Source)
	at com.aspose.html.rendering.HtmlRenderer.render(Unknown Source)
	at com.aspose.html.rendering.HtmlRenderer.render(Unknown Source)
	at com.aspose.html.rendering.HtmlRenderer.render(Unknown Source)
	at com.aspose.html.rendering.Renderer.render(Unknown Source)
	at com.aspose.html.rendering.Renderer.render(Unknown Source)
	at com.aspose.html.utils.hz.a(Unknown Source)
	at com.aspose.html.utils.hz.a(Unknown Source)
	at com.aspose.html.utils.hz.a(Unknown Source)
	at com.aspose.html.converters.Converter.convertHTML(Unknown Source)
	at AsposeHtmlHeadlessTest.main(AsposeHtmlHeadlessTest.java:14)
Caused by: java.awt.HeadlessException
	at java.desktop/sun.java2d.HeadlessGraphicsEnvironment.getScreenDevices(HeadlessGraphicsEnvironment.java:52)
	at com.aspose.html.utils.bmp.<clinit>

Please see attached a sample code to reproduce the problem.

OS: Windows 11
Java version: tried 17.0.9 and 21.0.5 64-bit
Aspose HTML 24.11

System.setProperty("java.awt.headless", "true");

String input = "test.html";
String output = "test.html.pdf";

HTMLDocument doc = new HTMLDocument(input);
Converter.convertHTML(doc, new PdfSaveOptions(), output);

sample.zip (605 Bytes)

@igor.rogov

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-1902

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.