I have a report designed with iReport 1.3.0. This report includes several images, which are loaded dynamically. Then I use JasperRunManager.runReportToPdfFile
to create the PDF. Everything in the PDF looks fine except for the images, which appear scaled.
Can anyone tell me what am I doing wrong?
Thanks.
If you save the report as HTML, you will notice that the logo appears correctly.
Image files such as PNG are raster images: stored as individual pixels.
Whereas PDF files are primarily vectorized: the elements inside are stored as descriptions of how to draw them. This allows PDFs to scale and be legible at any size.
Using a raster image in a vector format will likely result in a pixelated effect.
You have a few options to make the images match the quality of the text, in order of ease:
The image will look sharp until around 400% zoom.
The image will look sharp at every resolution. Replace the normal <image...>
XML with the following code (be sure to adjust the width and height accordingly):
<image hAlign="Center" vAlign="Middle">
<reportElement x="0" y="0" width="179" height="66"/>
<imageExpression class="net.sf.jasperreports.engine.JRRenderable"><![CDATA[net.sf.jasperreports.renderers.BatikRenderer.getInstance(new java.io.File("/path/to/logo.svg"))]]></imageExpression>
</image>
To convert a GIF to SVG, first try a quick web-based tool, such as: http://vectormagic.com
Once converted to SVG, you will have to use the code listed above to display the logo.
See:
As of version 4.0.1 raster image resolution should be preserved and you can also improve the resolution of charts when using other export options (xls, rtf, html etc). The default is only a very low 72 dpi.
In iReport Options > JasperReport Properties edit
net.sf.jasperreports.image.dpi 300
http://jasperforge.org/projects/jasperreports/tracker/view.php?id=3411
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With