org.xhtmlrenderer.util.XRRuntimeException 无法加载 XML 资源 iText PDF

发布于 2024-12-03 09:57:28 字数 1598 浏览 0 评论 0原文

我们有一个 struts 2 应用程序,我们在其中实现了下载/提取网页/ JSP 内容到 PDF 的功能。我们使用 iText 来实现同样的目的。 当我在本地开发环境中运行应用程序时,该功能运行良好,并且在单独的测试服务器上运行良好,即当我访问时 使用单独的服务器 URL 的应用程序。最近,我们已将应用程序迁移到测试版,并设置了域名 URL。迁移到域 URL 后, 下载/提取 PDF 功能抛出错误。下面给出的是代码和来自 server.log 的堆栈跟踪。 (仅供参考...我正在 JBoss 5 服务器上运行该应用程序。)

我迫切需要解决此问题,请求有人协助我解决此问题。

代码:这是我的操作类中调用的函数 - DownloadPriceSheetAction。

private String generatePDF(HttpServletRequest request) throws Exception {
        File tempFile = File.createTempFile(ApplicationConstants.PRICE_SHEET,
            ApplicationConstants.PDF);
    OutputStream os = new FileOutputStream(tempFile);

    StringBuilder stringURLBuilder = new StringBuilder();
    stringURLBuilder.append(request.getScheme());
    stringURLBuilder.append(ApplicationConstants.PDF_COLLEN);
    stringURLBuilder.append(ApplicationConstants.PDF_DOUBLE_SLASH);
    stringURLBuilder.append(request.getServerName());
    stringURLBuilder.append(ApplicationConstants.PDF_COLLEN);
    stringURLBuilder.append(request.getServerPort());
    stringURLBuilder.append(request.getContextPath());
    stringURLBuilder.append(ApplicationConstants.PDF_SLASH);
    stringURLBuilder.append(ApplicationConstants.PDF_ACTION);
    stringURLBuilder.append(getGenerateURL());

    logger.debug("\n URL = " + stringURLBuilder.toString() + "\n");

    ITextRenderer renderer = new ITextRenderer();
    renderer.setDocument(stringURLBuilder.toString());
    renderer.layout();
    renderer.createPDF(os);
    os.close();
    fileInputStream = new FileInputStream(tempFile);
    return ApplicationConstants.PDF;
}

We have a struts 2 application where we have implemented feature to download / extract contents of a web page/ JSP to PDF. We are using iText for the same.
That functionality works fine when I am running the application in my local, Dev environment and works fine on individual Test server i.e. when I am accessing
the application using individual server URLs. Recently we have migrated the app to Test and we have setup domain URL. After migrating to domain URL,
download/ extract PDF feature is throwing error. Given below is the Code & stack trace from server.log.
(FYI...I am running the app on JBoss 5 server.)

I urgently need to resolve this problem, request someone please assist me on this.

Code: This is the function called inside my action class - DownloadPriceSheetAction.

private String generatePDF(HttpServletRequest request) throws Exception {
        File tempFile = File.createTempFile(ApplicationConstants.PRICE_SHEET,
            ApplicationConstants.PDF);
    OutputStream os = new FileOutputStream(tempFile);

    StringBuilder stringURLBuilder = new StringBuilder();
    stringURLBuilder.append(request.getScheme());
    stringURLBuilder.append(ApplicationConstants.PDF_COLLEN);
    stringURLBuilder.append(ApplicationConstants.PDF_DOUBLE_SLASH);
    stringURLBuilder.append(request.getServerName());
    stringURLBuilder.append(ApplicationConstants.PDF_COLLEN);
    stringURLBuilder.append(request.getServerPort());
    stringURLBuilder.append(request.getContextPath());
    stringURLBuilder.append(ApplicationConstants.PDF_SLASH);
    stringURLBuilder.append(ApplicationConstants.PDF_ACTION);
    stringURLBuilder.append(getGenerateURL());

    logger.debug("\n URL = " + stringURLBuilder.toString() + "\n");

    ITextRenderer renderer = new ITextRenderer();
    renderer.setDocument(stringURLBuilder.toString());
    renderer.layout();
    renderer.createPDF(os);
    os.close();
    fileInputStream = new FileInputStream(tempFile);
    return ApplicationConstants.PDF;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文