如何强制 jasper 报告中的图像 url 导出为 HTML?
报告使用 Web 服务器上的图像(但不一定是应用程序的 Web 服务器)。该报表具有如下图像元素表达式:
"http://www.example.de/images/" + $F{picture}
当我使用 JRXhtmlExporter
将报表导出为 HTML 并在浏览器中显示生成的 HTML 时,图像不可见。当我用 firebug 检查 img 标签时,src 参数与表达式不同,而是一些生成的文件夹和生成的文件名。如果通过 JasperExportManager.exportReportToPdfStream()
将报告导出为 PDF,则图像会在生成的 PDF 文件中正确显示。
我将 JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR
设置为 Boolean.FALSE
,但没有帮助。
如何强制导出时图像 url 保持不变?
注意:“Is Lazy”选项 iReport 做了我想要的。
A report uses images on a web-server (but not necessarily the application's web-server). The report has an image element expression as follows:
"http://www.example.de/images/" + $F{picture}
When I export the report to HTML using the JRXhtmlExporter
and display the generated HTML in a browser, the image is not visible. When I inspect the img tag with firebug the src parameter is not the same as the expression but some generated folder and generated file name. If the report is exported to PDF via JasperExportManager.exportReportToPdfStream()
the image is displayed correctly in the resulting PDF file.
I set JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR
to Boolean.FALSE
, but it didn't help.
How can I force that the image url stays the same while exporting?
Note: The "Is Lazy" option the iReport does what I want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关键是将 isLazy 属性设置为 true (如 中的 @ThomasKessler 所示)这个答案)。这对我有用,可以完美地生成三个报告(PDF、XLS、HTML)。
我执行以下操作:
.jrxml
在我配置的 .properties 文件中(针对每个环境):
在 Servlet 中,我有 3 种方法:生成PDF报告、生成XLS报告和生成HTML报告。在最后一个中,我有:
在行中:
我设置了报表的所有参数,包括 LOGO_URL,设置属性值。
就我而言,我使用这种通用方法来生成我需要的所有报告。 Report.extractJasperParams 方法使用请求的映射来反映应生成哪个报告并相应地设置参数,但您可以根据您的特定需求对其进行简化。
Configurator.getPoperties() 方法用于简化 Properties 文件(在我的例子中是包含一些加密值的文件)的加载。
The key is setting the isLazy property to true (as indicated by @ThomasKessler in this answer). This works for me and generates the three reports (PDF, XLS, HTML) flawlessly.
I do the following:
.jrxml
In a .properties file I have configured (for each environment):
In a Servlet, I have 3 methods: generatePDFReport, generateXLSReport and generateHTMLreport. In this last one, I have:
And in the line:
I set all the parameters of the report, including LOGO_URL, setting the properties value.
In my case I use this generic method to generate all the reports I need. The method Report.extractJasperParams uses the request's map to reflect which report should be generated and sets the parameters accordingly, but you can simplify it for you specific needs.
The method Configurator.getPoperties() is to simplify the loading of the Properties file (in my case a file with some encrypted values).
我想说,标准解决方案是实施一种提供图像的方法。请参阅 JasperReports 附带的示例:
demo/samples/webapp
。但是,如果您愿意传递一个参数,以便可以对 HTML 使用延迟加载,但不能对 PDF 使用延迟加载,那么这当然也可以。
I would say that the standard solution is to implement a way to serve up your images. Refer to this sample that ships with JasperReports:
demo/samples/webapp
.But if you're willing to pass in a parameter so that you can use Lazy Loading for the HTML but not for PDF, then that will certainly work as well.
我也遇到了同样的问题,并使用新的 Jasper API 解决了该问题。 这里是与其对应的博客文章。使用新 API 和 web.xml 中的 ImageServlet 配置解决了该问题。
I also faced the same problem and resolved the issue with the new Jasper API. Here is the blog article corresponding to it. The problem was resolved using the new API and by using ImageServlet configuration in the web.xml.