[#11791] - Rendering SVG String -> Image read failed

Category:
Bug report
Priority:
High
Status:
New
Project: Severity:
Major
Resolution:
Open
Component: Reproducibility:
Always
Assigned to:
0

When i try to render a SVG image from String with the SimpleRenderToImageAwareDataRenderer i always get the error below:

net.sf.jasperreports.engine.JRException: java.io.IOException: The byte array is not a recognized imageformat.
at net.sf.jasperreports.engine.export.JRPdfExporter$InternalImageProcessor.processImageRetainShape(JRPdfExporter.java:1764)
at net.sf.jasperreports.engine.export.JRPdfExporter$InternalImageProcessor.process(JRPdfExporter.java:1621)
at net.sf.jasperreports.engine.export.JRPdfExporter$InternalImageProcessor.access$300(JRPdfExporter.java:1547)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportImage(JRPdfExporter.java:1487)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:1105)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:1068)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:932)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:552)
at com.jaspersoft.studio.editor.preview.actions.export.AExportAction.exportWithProgress(AExportAction.java:223)
at com.jaspersoft.studio.editor.preview.actions.export.AExportAction.doPreview(AExportAction.java:347)
at com.jaspersoft.studio.editor.preview.actions.export.AExportAction$3.run(AExportAction.java:191)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.io.IOException: The byte array is not a recognized imageformat.
at com.lowagie.text.Image.getInstance(Unknown Source)
at net.sf.jasperreports.engine.export.JRPdfExporter$InternalImageProcessor.processImageRetainShape(JRPdfExporter.java:1759)
... 11 more

my JRXML file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 7.1.0.final using JasperReports Library version 6.4.3 -->
<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="subReportSurvey" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3ff4ae82-790a-411d-a168-1178bb6e3524">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<import value="net.sf.jasperreports.renderers.SimpleRenderToImageAwareDataRenderer"/>
<parameter name="qtitle" class="java.lang.String"/>
<parameter name="qtext" class="java.lang.String"/>
<parameter name="qchart" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["<svg width=\"100\" height=\"100\"><circle cx=\"50\" cy=\"50\" r=\"40\" fill=\"red\" /></svg>"]]></defaultValueExpression>
</parameter>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="203" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="180" height="20" uuid="1fe3fd1c-ca6a-4584-b4b2-0b6acc5416c7"/>
<box rightPadding="10"/>
<textElement>
<font fontName="Arial" size="11" isBold="true"/>
<paragraph rightIndent="20"/>
</textElement>
<textFieldExpression><![CDATA[$P{qtitle}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="0" y="20" width="180" height="140" isRemoveLineWhenBlank="true" uuid="a4f154f5-a9e7-44c3-ae7e-2c95e80269cf"/>
<textElement>
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$P{qtext}]]></textFieldExpression>
</textField>
<image hAlign="Center" vAlign="Middle">
<reportElement x="180" y="0" width="380" height="160" uuid="fa8762b6-4501-4479-aeab-d11284bede5b"/>
<imageExpression><![CDATA[SimpleRenderToImageAwareDataRenderer.getInstance($P{qchart}.getBytes("UTF-8"))]]></imageExpression>
</image>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>

when i put the SVG string into a text.svg file and use the ResourceRenderer, it works. But i need to have it rendered from String.

v7.1
JRPdfExporter
benjamin.gutbrod's picture
Joined: Oct 6 2014 - 1:41am
Last seen: 5 days 15 hours ago

1 Comment:

#1

Putting the exact same string in an SVG file didn't work for me, I get the same error.

In any case, what you need to do is add xmlns="http://www.w3.org/2000/svg" to the <svg> tag, Batik expects the element to be in the SVG namespace.

Regards,
Lucian

Feedback