【问题标题】:How to load resources from classpath in itext7?如何从itext7中的类路径加载资源?
【发布时间】:2018-12-13 11:25:21
【问题描述】:

如何使用 iText 7 从类路径中加载图像、css 和字体等资源?

以前我使用ITextRenderer 这样做:

ITextRenderer renderer = createITextRenderer();
renderer.setDocumentFromString(htmlContent, "classpath:/templates/");

我用ConverterProperties 尝试过,但它不起作用。

ConverterProperties properties = new ConverterProperties().setBaseUri("classpath:/templates/");
HtmlConverter.convertToPdf(htmlContent, outputStream, properties);

【问题讨论】:

    标签: itext itext7 html2pdf


    【解决方案1】:

    在 Spring Boot 应用程序中,可以使用 TomcatURLStreamHandlerFactory 注册类路径协议处理程序。可以按照问题中的说明设置 baseURI。

    org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.register();
    ConverterProperties properties = new ConverterProperties().setBaseUri("classpath:/templates/");
    

    【讨论】:

      猜你喜欢
      • 2011-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-22
      • 2018-09-23
      • 2010-10-26
      相关资源
      最近更新 更多