【问题标题】:Use https ressources to generate pdf (with Flying Saucer / itext)使用https ressources生成pdf(带飞碟/itext)
【发布时间】:2021-03-25 09:18:45
【问题描述】:

我想用外部资源(jpg、css)从 html 创建一个 pdf。

这是用于生成 pdf 文件对象的代码,带有飞碟和 itext:

ITextRenderer iTextRenderer = new ITextRenderer();
iTextRenderer.setDocumentFromString(xhtmlString);
iTextRenderer.layout();

File file = new File("test.pdf");
FileOutputStream os = new FileOutputStream(file);
iTextRenderer.createPDF(os);
os.close();

不幸的是,所有与 https 链接的资源都被忽略了,而 http 资源运行良好。

编辑:

我扩展 ITextUserAgent 来拦截 https 调用资源,我得到了这个错误:

sun.security.provider.certpath.SunCertPathBuilderException:无法 找到请求目标的有效认证路径

所以我需要一个证书来获取那些 https 资源。

Here和我的问题一模一样。

【问题讨论】:

    标签: java itext flying-saucer


    【解决方案1】:

    Here 是指向从 HTTPS 服务器加载数据的 java-native 方式的链接。

    现在,您正在使用 Flying Saucer 的 XML 解析实现,在其文档中似乎没有引用太多 HTTPS 支持。我会使用上面的解决方法,然后直接将 DOM 传递给 Renderer。

    【讨论】:

      猜你喜欢
      • 2016-06-26
      • 1970-01-01
      • 1970-01-01
      • 2013-07-30
      • 2017-11-25
      • 2012-01-05
      • 2010-10-11
      • 2019-01-07
      • 2017-08-04
      相关资源
      最近更新 更多