首页 > 解决方案 > 将 html、xhtml 渲染为 PDF 时图像 Thymeleaf 不显示

问题描述

我有一个 html 代码,我想将其导出为 pdf,当我使用 URL http://localhost:8080/files/downloadFile/ {id}调用的函数时, PDF中的图像不会出现,当我使用相同的 url (localhost:8080/) 但是当我调用另一个项目中托管的相同函数时从另一个项目调用该函数 (localhost: 8082 ) 它出现http://localhost:8082/files/downloadFile {id}这是我的html代码。

    <div> ICI <img th:src="@{${pic}}">
    <div>HESS 
    <img th:src="${pic}">
    <img src="http://localhost:8080/files/downloadFile/bfd59122-592e-49f2-a951-41deeec62213">
    
    <img src="http://localhost:8082/files/downloadFile/bfd59122-592e-49f2-a951-41deeec62213">
    </div>
    </div>
 When parsing from html to pdf I display, the thymeleaf html code and it's presented like this.

<body >
    <div class="container" >
    <div>
    <span>SS</span>
    <div> ICI <img src="http://localhost:8080/files/downloadFile/bfd59122-592e-49f2-a951-41deeec62213">
    <div>HESS 
    <img src="http://localhost:8080/files/downloadFile/bfd59122-592e-49f2-a951-41deeec62213">
    <img src="http://localhost:8080/files/downloadFile/bfd59122-592e-49f2-a951-41deeec62213">
    </div>
    </div>
        
    </div>
        
    </div>
</body>

总结一下,当我从 localhost:8080 调用托管在localhost:8082但不在localhost :8080 中的方法时,src 工作正常。

另一句话,当我在浏览器中显示 Thymeleaf html 时,它工作正常。

标签: spring-bootimagethymeleafflying-saucer

解决方案


推荐阅读