Jasper Reports PDF image quality (blurry and poor) solution

Recently I had to create a PDF Jasper Report that contained a lot of small images (I needed to represent checkboxes); however upon generating the PDF the image quality was really awful since for some reason they were been scaled (even though I had configured the report to show them in real size and the image was the same dimensions as its placeholder)

I spent quite some time searching for a solutions, one popular one was to add the following parameter either to the report as a property or in the jasperreports.properties in the CLASSPATH to be picked up by the engine but to no avail.

In the end after searching and reading different threads I found 2 solutions that work :

1. Convert your PNG to SVG

You can convert your PNGs to SVGs either by using something like Adobe Ilustrator or something similar or you can also head up to this website : PNG to SVG converter and follow the instructions

You can then place your SVGs in the appropriate folder in your application where you can pass the path of the image as a parameter when filling the report; you will also have to modify the source of your JRXML like so to use the SVG format in your report :







However this approach stopped working when I upgraded to JasperReports 5.6.1

2. Create a larger version of your PNG

This is the final solution I used since the previous one stopped working when I upgraded

This one is pretty straight-forward just create an image 400% larger than the image place-holder (hopping you have an original image that is bigger otherwise you'll end up loosing quality in the process).

For example if you take the example before where the image place holder dimensions where 15px - 15px I created an image whose dimensions where 60px - 60px and that was it.

1 comment:

  1. Thank you so much for this solution. Tried everything but nothing worked till I found this.

    ReplyDelete