java.awt.HeadlessException

I am getting following Exception when I ran in Linux server,

java.awt.HeadlessException<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

at sun.awt.HeadlessToolkit.getScreenSize(HeadlessToolkit.java:261)

at com.aspose.pdf.internal.p13.z9.m1(Unknown Source)

at com.aspose.pdf.internal.p13.z47.(Unknown Source)

at com.aspose.pdf.internal.p212.z15.m1(Unknown Source)

at com.aspose.pdf.internal.p212.z15.m1(Unknown Source)

at com.aspose.pdf.internal.p216.z1.m1(Unknown Source)

at com.aspose.pdf.z72.m1(Unknown Source)

at com.aspose.pdf.ADocument.m1(Unknown Source)

at com.aspose.pdf.ADocument.(Unknown Source)

at com.aspose.pdf.Document.(Unknown Source)

)

I am trying to convert html to pdf via setting HtmlOptions.

Its work in Windows, but It fails in Linux enviornment.

I even tried to set the page width and height, and also made -Djava.awt.headless to true. also Set the enviornment properties for the same, and it didnt work. Its giving same exception again.

I am using Latest Aspose PDF 9.7.0 - JDK 1.6 jar

I tried to load the Sample HTML file but its not allowing to load in this forum. Can you please help me over this.

Thanks,

Jagat

Any Updates?

Hi Jagat,


Thanks for your inquiry. Please note on non-Windows OSs you need to set font folder path of your system before performing any operation using Aspose.Pdf for Java. For example, I have installed Microsoft truetype fonts on my Ubuntu 13.10 server and setting local font path as following. Please set font folder path according to your system, hopefully it will fix the issue. If issue persist then please share your environment details and HTML file. You may archive and attach your html file to the post.

// Set font folder path
String path = “/usr/share/fonts/truetype/msttcorefonts/”;
// seting the user list for standard font directories
java.util.List list = com.aspose.pdf.Document.getLocalFontPaths();
list.add(path);

HtmlLoadOptions loadOptions = new HtmlLoadOptions();
loadOptions.getPageInfo().getMargin().setBottom(10);
loadOptions.getPageInfo().getMargin().setTop(20);
Document doc = new Document(“test.html”, loadOptions);
doc.save(“output.pdf”);

Please feel free to contact us for any further assistance.

Best Regards,
jagat.prakash.mahato:
I tried to load the Sample HTML file but its not allowing to load in this forum. Can you please help me over this.
Hi Jagat,

In order to upload HTML file, you may consider renaming the file extension to TXT or anything else.

I tried the option as mailed by Tilal Ahmed but still having issues..

// Set font folder path<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

String path = "/usr/share/fonts/truetype/msttcorefonts/";

// seting the user list for standard font directories

java.util.List list = com.aspose.pdf.Document.getLocalFontPaths();

list.add(path);

HtmlLoadOptions loadOptions = new HtmlLoadOptions();

loadOptions.getPageInfo().getMargin().setBottom(10);

loadOptions.getPageInfo().getMargin().setTop(20);

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

doc.save("output.pdf");

Added the html with txt extension

Hi Jagat,


Thanks for sharing your sample HTML file. I have tested the scenario over Ubuntu 13.10, setting font folder as suggested above and unable to notice the exception. Did you set the font folder as per your system and even then getting the exception? If issue persist then please share the exact exception after font folder setting and your system environments. So we will investigate it further and provide you information accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Its the same exception again,

I am using Linux Red Hat, and location I am setting path as /usr/share/fonts/ .

Can you please let us know why we need this to be set, how is font affecting screen size?

java.awt.HeadlessException
at sun.awt.HeadlessToolkit.getScreenSize(HeadlessToolkit.java:261)
at com.aspose.pdf.internal.p13.z9.m1(Unknown Source)
at com.aspose.pdf.internal.p13.z47.(Unknown Source)
at com.aspose.pdf.internal.p212.z15.m1(Unknown Source)
at com.aspose.pdf.internal.p212.z15.m1(Unknown Source)
at com.aspose.pdf.internal.p216.z1.m1(Unknown Source)
at com.aspose.pdf.z72.m1(Unknown Source)
at com.aspose.pdf.ADocument.m1(Unknown Source)
at com.aspose.pdf.ADocument.(Unknown Source)
at com.aspose.pdf.Document.(Unknown Source)

Also added the following in the VM arguments as below

-Djava.awt.headless=true

The API doc

http://docs.oracle.com/javase/7/docs/api/java/awt/Toolkit.html#getScreenSize

suggest we get Exception for below when set to true.

getScreenSize

HeadlessException - if GraphicsEnvironment.isHeadless() returns true

Please reply ASAP.

Thanks,

Jagat

Please provide update ASAP. I think this may be Aspose PDF Bug under headless server enviornment.

Hi Jagat / Leo,


We are sorry for the delayed response. We have logged an investigation ticket PDFNEWJAVA-34641 in our issue tracking system for further investigation of Headless Mode. We will keep you updated about the issue resolution progress within this forum thread.

We are sorry for the inconvenience caused.

Best Regards,

Any update on this issue? Our January release needs this bug fix. Thanks.

Hi Leo,


Thanks for your inquiry. I am afraid we have recently noticed the issue. Currently it is pending for investigation due to the issues already under investigation/resolution. However we have recorded your concern and request our development team to share an ETA for the issue at their earliest. We will keep you updated about the issue resolution progress.

We are sorry for the inconvenience caused.

Best Regards,

Hi Aspose Team,

We are also facing the same issue in linux/solaris environment with the below exception while converting html to pdf. The error occurs on both the envrioment after setting the font path.

Any update on this issue will be much appreciated. We are unable to use this product at the moment and looking for an alternate.

java.awt.HeadlessException
at sun.awt.HeadlessToolkit.getScreenSize(HeadlessToolkit.java:261)
at com.aspose.pdf.internal.p13.z9.m1(Unknown Source)
at com.aspose.pdf.internal.p13.z47.(Unknown Source)
at com.aspose.pdf.internal.p212.z15.m1(Unknown Source)
at com.aspose.pdf.internal.p212.z15.m1(Unknown Source)
at com.aspose.pdf.internal.p216.z1.m1(Unknown Source)
at com.aspose.pdf.z72.m1(Unknown Source)
at com.aspose.pdf.ADocument.m1(Unknown Source)
at com.aspose.pdf.ADocument.(Unknown Source)
at com.aspose.pdf.Document.(Unknown Source)

Thanks,
OTC

Hi Omkumar,


Thanks for your feedback. We have noted your updated information and passed our development, they will consider it in investigation as well. Moreover, we have also raised the issue priority in our issue tracking system and will update you as soon as we made a significant progress towards issue resolution.

Thanks for your patience and cooperation.

Best Regards,

We are seeing the same issue in a Windows environment.

Hi there,


Thanks for your feedback. We have noticed the same issue in windows environment as well. Our development team will consider it, we will notify you as soon as we made some progress towards issue investigation and resolution.

We are sorry for the inconvenience caused.

Best Regards,

Hi again,

(continuing the threads of “kgh”)

We are urgently awaiting a resolution on this issue.

To put things in context, we originally were using the legacy generator, based on the Pdf object, for constructing a PDF from HTML. However, we ran into problems finding installed fonts on our Linux server. See Font-related issue

We switched to the “DOM approach” on your recommendation, but the HeadlessException prevents any progress at this point.

Given our requirements, we are pretty well blocked at this point. So please update us soon on the prospects of a solution.

Thanks and regards.

Hi Chris,


Thanks for your feedback. We have recorded your concern and coordinating with our development team to get an ETA as soon as possible. We will keep you updated with the progress.

Thanks for your patience and cooperation.

Best Regards,

Hi again,

We are anxiously awaiting a resolution to this issue. The lack of a solution is seriously impacting our product release planning. Please provide us with an update on when we can expect a solution.

Thanks and regards.

Hi Chris,


Thanks for your patience.

<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;
color:#333333;background:white”>Our development team is working hard
on resolving this issue but I am afraid due to complexity of this issue, its not yet resolved. As soon as I have some updates regarding its resolution, I
would be more than happy to update you with the status of correction. Please be
patient and spare us little time.<o:p></o:p>

<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;mso-fareast-font-family:
“Times New Roman”;color:#333333;background:white;mso-ansi-language:EN-US;
mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>We are sorry for this delay
and inconvenience

Hi again,

Our management would like a more definite time estimate for having a resolution to this issue. We realize that proper software development should not be too rushed, but we need to come to terms with our own time-critical commitments. The current situation not only prevents basic results, but it leaves open questions that we would want to resolve quickly or else seek an alternative solution.

One additional concern is support for HTML to PDF conversion. We have a simple test case, involving some straightforward CSS, which when applied to your older API, results in a null pointer exception. We are anxious to try out your newer code to assess whether the better-supported approach will be adequate for our requirements.

So please, give us a more definite estimate, one that you are confident of, and with which we can realistically plan.

Thanks and regards.