如何解决java.awt.AWTError: 无法使用 ':0.0' 作为 DISPLAY 变量的值连接到 X11 窗口服务器不适用于生产服务器
我正在通过以下代码将 pdf 转换为图像,然后将图像转换回 pdf。
PDDocument pdDocument = new PDDocument();
PDDocument oDocument = PDDocument.load(new File(outputFile));//outputfile is the location and name of the pdf file
PDFRenderer pdfRenderer = new PDFRenderer(oDocument);
int numberOfPages = oDocument.getNumberOfPages();
PDPage page = null;
for (int i = 0; i < numberOfPages; i++) {
page = new PDPage(PDRectangle.LETTER);
BufferedImage bim = pdfRenderer.renderImageWithDPI(i,300,ImageType.RGB);
PDImageXObject pdImage = JPEGFactory.createFromImage(pdDocument,bim,0.1f);
PDPageContentStream contentStream = new PDPageContentStream(pdDocument,page);
float newHeight = PDRectangle.LETTER.getHeight();
float newWidth = PDRectangle.LETTER.getWidth();
contentStream.drawImage(pdImage,newWidth,newHeight);
contentStream.close();
pdDocument.addPage(page);
}
pdDocument.save(outputFile);
pdDocument.close();
此代码在我们的开发服务器上运行良好,但在我们的生产服务器上出现以下错误:
线程“main”中的异常java.awt.AWTError:无法连接到X11 窗口服务器使用“:0.0”作为 DISPLAY 变量的值。
由于此代码在我们的开发服务器上运行良好,因此无法对其进行测试。有人可以帮我解决这个问题或提供任何替代方法将 PDF 转换为单个图像吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。