SVG quality in PDFs vs. JasperPrintXML

Hi,

we produce JasperPrint Objects as normal.  But we store the printouts (as byte array) in database as JasperPrintXMLs as follows:

JRXmlExporter exporter = new JRXmlExporter();          
      exporter.setParameter(JRExporterParameter.CLASS_LOADER,new AfpsDruckFontExtensionTTFLoader(Thread.currentThread().getContextClassLoader()));            
      exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
      exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outXML);
      exporter.setParameter(JRXmlExporterParameter.IS_EMBEDDING_IMAGES, Boolean.TRUE);
      //exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING,new String("UTF-8"));
      exporter.exportReport();

This is necessarry as we can open the old output even with newer releases of JasperReports as this is class independed (we still have some as xml outputs from 0.5.3 in database when I remember right)

When we need a PDF file (for mail delivery or anything else) we convert this JasperPrintXML back to a JasperPrint as follows:

ByteArrayInputStream inXML = new ByteArrayInputStream(xml);
      JasperPrint jasperPrint = JRPrintXmlLoader.load(inXML);

and then use the JRPdfExporter with the JasperPrint again:

JRPdfExporter exporter = new JRPdfExporter();ByteArrayOutputStream outPDF = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
      exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outPDF); 
exporter.exportReport();

But in the resulting PDF the SVG is rendered like a normal Image (quite pixelated)....

When I generate the PDF from original JasperPrint Object (without the JasperPrintXML between) it's ok - even with zoom to 6400% in AcrobatReader.

So why the SVG quality got lost when storing the JasperPrint as XML (with embedded images) between?

The Ultimate guide tells:

The quality of this exporter is equal to the Graphics2D exporter because it preserves
100% of the initial document content and properties. There is no loss in document
quality when exporting to XML because the resulting XML content can be loaded back
into a JasperPrint object that will look the same as the original one.

So I actually expected that also SVG-Graphics are stored as Base64encoded Images in JRPXML and are loaded back correctly!??!

regards from Germany

C-Box

PS: currently working with 4.1.1



PPS: I attached two sample PDFs demonstrating the quality .. just zoom a bit to the little ant in the top of page1



Post Edited by CBox at 06/01/2012 07:10
C-Box's picture
20859
Joined: Jul 19 2006 - 5:58pm
Last seen: 5 months 2 weeks ago

2 Answers:

I think that the ultimate guide paragraph was written a long time ago, before JR had SVG images.

The XML exporter actually rasterizes all SVG images, and when you reload the report from XML the image is no longer vectorial.  To improve the quality of the rasterized images you can set a higher value for the net.sf.jasperreports.image.dpi property.

We are going to rethink the XML exporter functionality so that SVG images are preserved.

Regards,

Lucian

PS:  You can also consider directly storing serialized JasperPrint objects.  We are committed to ensure backward compatibility for such objects, and even if there were occasional problems with that they got fixed as soon as we learned about it.

lucianc's picture
76958
Joined: Jul 17 2006 - 1:10am
Last seen: 16 min 7 sec ago

Hi Lucian,

was there any bugfix within one of the latest versions (> 4.7.0) concerning saving SVG images in JasperPrintXMLs ?

(There is another customer who recognized that the qualitity got lost after saving the printouts -> see my first posting)

regards from Dresden/Germany

C-Box

C-Box's picture
20859
Joined: Jul 19 2006 - 5:58pm
Last seen: 5 months 2 weeks ago
Feedback
randomness