Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images in reports #127

Closed
nderwin opened this issue Oct 16, 2024 · 11 comments
Closed

Images in reports #127

nderwin opened this issue Oct 16, 2024 · 11 comments
Labels
enhancement New feature or request

Comments

@nderwin
Copy link
Contributor

nderwin commented Oct 16, 2024

Images do not appear to be loading in reports - either as a file in the project, as a static resource served by the project, or an external image from a URL. See https://github.com/nderwin-forks/quarkus-jasperreports/tree/feature/images-in-reports for examples.

The unit test is currently failing because the host URL needs to be dynamically passed to the report instead of it being hard-coded as http://localhost:8080.

@melloware
Copy link
Contributor

can you submit the PR as draft so I can look?

@nderwin
Copy link
Contributor Author

nderwin commented Oct 16, 2024

Sure (#128); in the 6.x version, I had solved this with changes to the repository service; the current one works much the same as mine did for external images, but that didn't seem to be working either.

If you fire up the integration-tests project in dev mode, then it'll produce the report, but all of the img tags have an empty string for the src attribute.

@melloware
Copy link
Contributor

Thanks i will take a look.

@melloware
Copy link
Contributor

melloware commented Oct 16, 2024

This is the issue: https://stackoverflow.com/questions/43903930/jasperreport-image-inside-report-jrxml-on-html-src-is-missing

HTMLReports you have to register image handlers? When I do that I now see text in the <img src="img_0_0_6.svg" style="height: 50px" alt=""/></td>

What happens with PDF Renderer?

And this one: https://stackoverflow.com/questions/33547588/how-to-display-a-svg-byte-array-as-an-image-in-a-jasperreport/39320863#39320863

@nderwin
Copy link
Contributor Author

nderwin commented Oct 16, 2024

I had just started looking at this, so not sure what the PDF renderer does. I'll also eventually need the XLSX output to work.

@melloware
Copy link
Contributor

ok i am looking at the samples. And they use SimpleHtmlExporter to export to a jrpint file in their the exporter it does this

private void setFileHandlers(File destFile)
	{
		File resourcesDir = new File(destFile.getParent(), destFile.getName() + "_files");
		String pathPattern = resourcesDir.getName() + "/{0}";
		resourceHandler = new FileHtmlResourceHandler(resourcesDir, pathPattern);
		imageHandler = resourceHandler;
		fontHandler = resourceHandler;
	}

So its registering a default File handler for images?

@melloware
Copy link
Contributor

Also when I step through the debugger i see it loading the images properly in JRImageLoader

@nderwin
Copy link
Contributor Author

nderwin commented Oct 17, 2024

Good news - PDF and XLSX output works fine as-is, but that makes sense because the images are embedded. HTML output will need some more work to provide an endpoint that serves the generated image files (like img_0_0_2.svg or img_0_0_4.gif).

@melloware
Copy link
Contributor

2 things.

  1. You should add one of these as a Hyperlink like... so we can kill two birds with one stone and test Hyperlink as well.

https://github.com/TIBCOSoftware/jasperreports/blob/a8ec0e6cbbf04d36878c8f783f10c2ff88afeff5/demo/samples/hyperlink/reports/HyperlinkReport.jrxml#L27C4-L31C14

  1. If you want to Add a WEBP file you have to add this dependency to runtime module.
<dependency>
			<groupId>com.twelvemonkeys.imageio</groupId>
			<artifactId>imageio-webp</artifactId>
			<version>3.9.4</version>
</dependency>

https://github.com/TIBCOSoftware/jasperreports/blob/a8ec0e6cbbf04d36878c8f783f10c2ff88afeff5/demo/samples/images/reports/ImagesReport.jrxml#L210-L229

@melloware melloware added the enhancement New feature or request label Oct 18, 2024
@nderwin
Copy link
Contributor Author

nderwin commented Oct 18, 2024

<maniacal laugh>
Figured out how to use the FileHtmlResourceHandler to dump the images for the HTML output into a temp folder, then provided an endpoint to serve them. WEBP can be another iteration.

@melloware
Copy link
Contributor

Closing this we don't need to test WEBP if that JAR or any other TwelveMonkeys JAR is on the classpath it just registers with javax.imageio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants