Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jasperreports images are always blurry

A simple report with only a png in it.

Png's dpi is 96, which looks pretty sharp. However, every time i export the report, be it to .docx or to pdf, only an awfully blurry image appears.

i've tried setting

net.sf.jasperreports.image.dpi 

to 300, and to 96

both in ireports and directly on the report's jrxml as a property.

Nothing works.

exception

I've lost many days googling this matter but still no answers.

Update 1

I've been able to trace the cause of this strange behavior to itext. It seems that it has to do something with it.

Update 2

Here's the jrxml code

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="carta_policia" pageWidth="612" pageHeight="792" columnWidth="572" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="fbda9a68-7549-438c-a8ad-b3aedaf0b2d4">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <property name="ireport.background.image" value="C:\Users\thou\workspace\cujillo\WebContent\resources\reports\fondo.png"/>
    <property name="ireport.background.image.properties" value="false,true,0.25,0,0,0,0,0,0"/>
    <property name="net.sf.jasperreports.image.dpi" value="96"/>
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["C:/Users/thou/workspace/cujillo/WebContent/resources/reports/"]]></defaultValueExpression>
    </parameter>
    <parameter name="R_RADICADO" class="java.lang.String"/>
    <parameter name="SUBREPORT_DATA_SOURCE" class="net.sf.jasperreports.engine.JRDataSource"/>
    <parameter name="R_ASUNTO" class="java.lang.String"/>
    <parameter name="R_LOCALIDAD" class="java.lang.String"/>
    <parameter name="R_IMAGE_RENDERER" class="net.sf.jasperreports.engine.JRRenderable" isForPrompting="false"/>
    <parameter name="R_PRINT_BACKGROUND" class="java.lang.String"/>
    <background>
        <band height="752"/>
    </background>
    <title>
        <band height="371" splitType="Stretch">
            <image scaleImage="RealSize">
                <reportElement uuid="dbadb500-4011-415b-bd98-4236532783c4" x="234" y="147" width="75" height="63"/>
                <imageExpression><![CDATA["C:\\Users\\thou\\workspace\\cujillo\\WebContent\\resources\\reports\\alcaldia mayor.png"]]></imageExpression>
            </image>
            <image scaleImage="Clip">
                <reportElement uuid="ecf7dbe3-4369-41a8-ba49-db98ba5ef478" x="309" y="151" width="75" height="63"/>
                <imageExpression><![CDATA["C:\\Users\\thou\\workspace\\cujillo\\WebContent\\resources\\reports\\alcaldia mayor.jpg"]]></imageExpression>
            </image>
        </band>
    </title>
    <pageHeader>
        <band splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="104" splitType="Stretch"/>
    </detail>
    <columnFooter>
        <band splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="11" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="209" splitType="Stretch"/>
    </summary>
</jasperReport>
like image 562
demonz demonz Avatar asked Apr 30 '13 18:04

demonz demonz


People also ask

Why do we use JasperReports?

JasperReports is a powerful open source reporting tool that has the ability to deliver rich content onto the screen, to the printer, or into PDF, HTML, XLS, RTF, ODT, CSV, TXT and XML files. It is entirely written in Java and can be used in a variety of Java-enabled applications to generate dynamic content.

What language does jaspersoft use?

The default expression language is Java, but if you are not a programmer, we recommend that you design your projects with JavaScript or Groovy because those languages hide a lot of the Java complexity.

Where do I put JasperReports properties?

jasper. properties is looked up by jasper reports in the classpath, so it can be directly in the WEB-INF/classes folder, or in the root folder of any of the jars in WEB-INF/lib.


1 Answers

Although we've raised the DPI setting in our presentations, I've implemented a custom exporter, which exports charts as powerpoint shapes and not as raster images. At least for .docx it's feasible to implement something similar.

Before I've started the shape export classes, I've tried to use EMF (1,2) as an image format, but this is quite limited, e.g. it doesn't embed fonts.

I haven't searched further in the direction, but maybe you can transform an intermediate SVG image to something (raster/vector) which can be embedded into .docx/.pdf.

Have you checked the images inside .docx-Zip-file? ... are the plain images also blurry or just when they are displayed by Word/LibreOffice. And of course the images should change after you changed the DPI setting - if not, try to put a jasperreports.properties in the classpath

like image 124
kiwiwings Avatar answered Oct 18 '22 21:10

kiwiwings