图像不使用Spring Boot,飞碟和Thymeleaf在PDF模板中显示 [英] image not displaying in PDF template using Spring Boot, flying saucer and Thymeleaf
问题描述
我使用Spring Boot,飞碟,百里香创建了一个来自html模板的pdf文件。但是图片没有显示在我的文件中。
项目结构: a href =https://i.stack.imgur.com/L6ZEC.jpg =nofollow noreferrer>
代码html: $ b
< div class =col-xs-6 invoice-col-2>
< img src =../ static / images / mastercard.pngalt =mastercard>< / img>
< / div>
当我将img标记更改为:
< img src =../ static / images / mastercard.pngalt =mastercardth:src =@ {static / images / mastercard.png}> < / IMG>
创建PDF文件时,出现错误:
org.thymeleaf.exceptions.TemplateProcessingException:除非您实现org.thymeleaf.context,否则链接基础static / images / mastercard.png不能是上下文相对(/)或页面相对.IWebContext接口(上下文类为:org.thymeleaf.context.Context)
尝试使用Spring的 classpath:
前缀。无论您是从 .jar
还是在您的IDE中运行,都会直接从类路径加载文件。这里是一个例子:
< img alt =mastercardth:src =@ {classpath:static / images / mastercard.png}/>
可以找到有关 classpath:
的更多信息在官方文档中。
I create a file pdf from html template using Spring Boot, flying saucer, thymeleaf. But image is not displaying in my file.
Project structure:
code html:
<div class="col-xs-6 invoice-col-2">
<img src="../static/images/mastercard.png" alt="mastercard"></img>
</div>
When I change img tag to:
<img src="../static/images/mastercard.png" alt="mastercard" th:src="@{static/images/mastercard.png}"></img>
When I create PDF file, I get an error:
org.thymeleaf.exceptions.TemplateProcessingException: Link base "static/images/mastercard.png" cannot be context relative (/) or page relative unless you implement the org.thymeleaf.context.IWebContext interface (context is of class: org.thymeleaf.context.Context)
Try using Spring's classpath:
prefix. This loads your file directly from the classpath, no matter if you are running from a .jar
or within your IDE. Here is an example:
<img alt="mastercard" th:src="@{classpath:static/images/mastercard.png}" />
More information about classpath:
can be found in the official documentation.
这篇关于图像不使用Spring Boot,飞碟和Thymeleaf在PDF模板中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!