We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment

Converting HTML to PDF throws “java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment”. Added java.awt.headless=true and now it throws a HeadlessException.


This started happening when I update to aspose.pdf-17.3.0-java. The previous version did not have this problem.

I have included my source and have attached the input file.

ArrayList fonts = new ArrayList();
fonts.add("/ScholarOne/ConversionEngine/fonts");
Document.setLocalFontPaths(fonts);
String fileNameWithOutExt = FilenameUtils.removeExtension(file.getPath());
String absolutePath = file.getAbsolutePath();
String filePath = absolutePath.
substring(0,absolutePath.lastIndexOf(File.separator));
HtmlLoadOptions htmloptions = new HtmlLoadOptions(filePath);
htmloptions.setInputEncoding(“UTF-8”);
// Load HTML file
Document doc = new Document(file.getPath(), htmloptions);
PageSize size = PageSize.getA4();
for (Page page : (Iterable) doc.getPages())
{
page.setPageSize(size.getWidth(), size.getHeight());
}
// Save PDF file
doc.save(fileNameWithOutExt + “.pdf”);

Hi Rob,


Thanks for contacting support.

Can you please share some details regarding your working environment, so that we can test the scenario and reply accordingly. We are sorry for your inconvenience.

Hi Rob,


Thanks for your patience.

I have tested the scenario of HTML file to PDF conversion using Aspose.Pdf for Java 17.4.0 using JDK 1.8.0_60 on MAC OSX 10.11.1 and I am unable to notice any issue. For your reference, I have also attached the output generated over my end.

[Java]
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12f1b} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px} p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400} span.s1 {font-variant-ligatures: no-common-ligatures} span.s2 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2} span.s3 {font-variant-ligatures: no-common-ligatures; color: #000000} span.s4 {font-variant-ligatures: no-common-ligatures; color: #d12f1b}

java.util.ArrayList fonts = new java.util.ArrayList();

fonts.add("/ScholarOne/ConversionEngine/fonts");

Document.setLocalFontPaths(fonts);


// String fileNameWithOutExt = FilenameUtils.removeExtension(file.getPath());


// String absolutePath = file.getAbsolutePath();

// String filePath = absolutePath.

// substring(0,absolutePath.lastIndexOf(File.separator));


HtmlLoadOptions htmloptions = new HtmlLoadOptions();

htmloptions.setInputEncoding("UTF-8");


// Load HTML file

Document doc = new Document("test.html", htmloptions);

PageSize size = PageSize.getA4();

for (Page page : (Iterable) doc.getPages())

{

page.setPageSize(size.getWidth(), size.getHeight());

}


// Save PDF file

doc.save("ResultantFile" + ".pdf");

Can you please test it on Linux. I am running on Oracle 6.5 Linux without an X Windows service running. Is X Windows necessary for the conversion?

Hi Rob,


Thanks for sharing the details.

We are working on setting up required environment and will keep you updated with our findings. Please be patient and spare us little time.

Any updates?

Hi Rob,


Thanks for your patience.

We have arranged the required media and working on setting up Oracle Linux environment so that we can test the scenario in our environment. We will share our findings shortly. We apologize for the delay and inconvenience.

Are you making progress? This is the only defect preventing us from moving forward.

Hi Rob,


Thanks for your patience.

The problem reported earlier is logged as PDFJAVA-36781 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.