Convert HTML to PDF on Linux server using Java

Hello,

I’m using GroupDocs.Conversion Java version 17.7.1 and I’m getting an error jawa.awt.HeadlessException on our headless Linux server. Are there any limitations with running GroupDocs Java API on headless Linux servers?

[4/26/18 8:38:33:674 EDT] 00000105 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet [com.pyrasol.ecm.services.ConvertDocumentToPDF] in application [PyramidServices_war]. Exception created : [java.awt.HeadlessException
at sun.awt.HeadlessToolkit.getScreenSize(HeadlessToolkit.java:295)
at com.groupdocs.conversion.internal.c.a.pd.internal.p339.z5.(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.internal.p308.z5.m1(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.internal.p299.z1.m1(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.internal.p308.z5.(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.fU.a(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.fU.a(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.fU.a(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.fU.a(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.ADocument.a(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.ADocument.(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.Document.(Unknown Source)
at com.groupdocs.conversion.domain.a.k.r(Unknown Source)
at com.groupdocs.conversion.domain.a.k.a(Unknown Source)
at com.groupdocs.conversion.domain.a.a(Unknown Source)
at com.groupdocs.conversion.domain.b.a(Unknown Source)
at com.groupdocs.conversion.domain.b.a(Unknown Source)
at com.groupdocs.conversion.handler.ConversionHandler.b(Unknown Source)
at com.groupdocs.conversion.handler.ConversionHandler.b(Unknown Source)
at com.groupdocs.conversion.handler.ConversionHandler.convert(Unknown Source)
at com.pyrasol.ecm.services.ConvertDocumentToPDF.doPost(ConvertDocumentToPDF.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1233)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:782)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:481)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1114)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:949)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1817)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892)
]
[4/26/18 8:38:33:676 EDT] 00000105 LocalTranCoor E WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
[4/26/18 8:38:33:676 EDT] 00000105 webapp E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[com.pyrasol.ecm.services.ConvertDocumentToPDF]: java.awt.HeadlessException
at sun.awt.HeadlessToolkit.getScreenSize(HeadlessToolkit.java:295)
at com.groupdocs.conversion.internal.c.a.pd.internal.p339.z5.(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.internal.p308.z5.m1(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.internal.p299.z1.m1(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.internal.p308.z5.(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.fU.a(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.fU.a(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.fU.a(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.fU.a(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.ADocument.a(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.ADocument.(Unknown Source)
at com.groupdocs.conversion.internal.c.a.pd.Document.(Unknown Source)
at com.groupdocs.conversion.domain.a.k.r(Unknown Source)
at com.groupdocs.conversion.domain.a.k.a(Unknown Source)
at com.groupdocs.conversion.domain.a.a(Unknown Source)
at com.groupdocs.conversion.domain.b.a(Unknown Source)
at com.groupdocs.conversion.domain.b.a(Unknown Source)
at com.groupdocs.conversion.handler.ConversionHandler.b(Unknown Source)
at com.groupdocs.conversion.handler.ConversionHandler.b(Unknown Source)
at com.groupdocs.conversion.handler.ConversionHandler.convert(Unknown Source)
at com.pyrasol.ecm.services.ConvertDocumentToPDF.doPost(ConvertDocumentToPDF.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1233)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:782)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:481)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1114)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:949)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1817)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892)

Here is the code block responsible for the conversion:

new License().setLicense(ConnectionHandler.class.getClassLoader().getResourceAsStream(“GroupDocs.Conversion.lic”));
ConversionHandler conversionHandler = new ConversionHandler(new ConversionConfig());
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setOutputType(OutputType.Stream);
response.getOutputStream().write(conversionHandler.convert(parts.get(0).getInputStream(), filename, saveOptions).toBytes());

Attached is an HTML file that works on Windows server, but throws this error on a headless Linux server

Thank you,

Robert HunterWorking.zip (1.5 KB)

@rhunter,

Thank you for the inquiry and posting your concerns.
In order to further investigate this issue at our end, we need following details:

  • Linux server details (e.g. version, flavor)
  • Which IDE you are using?
  • A simplified example project to reproduce this issue

Aside this, please integrate latest version of the API, follow this code example in your project and share your experience.

We are no longer able to reproduce the issue after upgrading to the latest version. Thank you for your assistance!

@rhunter,

You are welcome.