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.
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).
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.
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.