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

Free Support Forum - aspose.com

java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it

Library version: aspose.pdf-17.4.jar

Sample program:
import com.aspose.pdf.*;

public class Sample {

public static void main(String[] args) {

	String strTempViewPathForHtml = "/share/Aspose_Trouble_Shooting/resources/RateQuote.html";
	String strTempViewPathForPDF = "/share/Aspose_Trouble_Shooting/resources/RateQuote.pdf";

	try {

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

		License licenseWord = new License();	
		licenseWord.setLicense("Aspose.Total.Java.lic");
		HtmlLoadOptions loadOptions = new HtmlLoadOptions();
		loadOptions.getPageInfo().getMargin().setBottom(0);
		loadOptions.getPageInfo().getMargin().setTop(0);
		Document doc = new Document(strTempViewPathForHtml, new HtmlLoadOptions());
		doc.save(strTempViewPathForPDF);
	} catch (Exception e) {
		e.printStackTrace();
	}
}

}

OS Name: RHEL Linux 6.9
OS Version: 2.6.32-696.3.2.el6.x86_64
Apache Tomcat: 8.5.4
JVM Version: 1.8.0_131-b11
JVM Vendor: Oracle Corporation

The following exception is thrown:
java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at com.aspose.pdf.internal.p341.z5(Unknown Source)
at com.aspose.pdf.internal.p312.z5.m1(Unknown Source)
at com.aspose.pdf.internal.p296.z3.m1(Unknown Source)
at com.aspose.pdf.internal.p312.z5.(Unknown Source)
at com.aspose.pdf.internal.p296.z3(Unknown Source)
at com.aspose.pdf.z89.m1(Unknown Source)
at com.aspose.pdf.z89.m1(Unknown Source)
at com.aspose.pdf.z89.m1(Unknown Source)
at com.aspose.pdf.z89.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)
at Sample.main(Sample.java:28)

As seen in the sample program, we added the System.setProperty(“java.awt.headless”, “true”) at one point, but the same results occurred.

@travis.steinmetz,
You are using an old version 17.4 of Aspose.Pdf for Java API, kindly download try with the latest version 17.8 of Aspose.Pdf for Java API and let us know how that goes into your environment. If this does not help, then please send us your source HTML file. We will investigate and share our findings with you.

The 17.8 version along with the java.awt.headless JVM parameter worked.

@travis.steinmetz,
It is nice to hear from you that the problem has been resolved. Please let us know in case of any further assistance or queries.