JasperReport scales images when exporting to PDF, thereby losing quality

I have a report developed with iReport 1.3.0. This report contains several images that are loaded dynamically. Then I use JasperRunManager.runReportToPdfFile to create the PDF file. Everything in the PDF looks great, except for images that look scaled.

Can someone tell me what I am doing wrong?

Thanks.

+6
jasper-reports ireport
source share
2 answers

About Images

If you save the report as HTML, you will notice that the logo is displayed correctly.

Image files, such as PNG, are bitmap images: they are saved as separate pixels.

While PDF files are mostly vectorized: elements inside are stored as descriptions of how to draw them. This allows PDF files to scale and be legible in any size.

Using a bitmap in vector format is likely to result in a pixel effect.

Possible solutions

You have several options so that the images match the quality of the text in order of simplification:

  • Create a logo version with a resolution of 1200 dpi, increased by 400%.
  • Create a version of the SVG logo.
  • Convert image to vector format.
  • Zoom in 300% and change the resolution to 288 dpi.

Version 1200 DPI

The image will look sharp up to 400% zoom.

SVG version

The image will look sharp at every resolution. Replace plain <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> 

Convert GIF to SVG

To convert GIF to SVG, first try a quick web tool, for example: http://vectormagic.com

After converting to SVG, you will need to use the above code to display the logo.

Resolution and Scale

Cm:

+9
source share

Starting with version 4.0.1, the resolution of the bitmap should be preserved, and you can also improve the resolution of charts using other export options (xls, rtf, html, etc.). By default, only a very low 72 dpi is used.

In iReport Settings> Editing JasperReport Properties

net.sf.jasperreports.image.dpi 300

http://jasperforge.org/projects/jasperreports/tracker/view.php?id=3411

+2
source share

All Articles