Jump to content
Changes to the Jaspersoft community edition download ×

Does anyone use Batik to import SVG ? Urgent

Recommended Posts

By: macoute - macoute

Does anyone use Batik to import SVG ? Urgent

2004-10-27 08:05

Does anyone use Batik to import SVG in JasperReports?


In the template, I declare an image as follow:


<band height="205" isSplitAllowed="true" >

<image scaleImage="Clip" hAlign="Center" hyperlinkType="Reference">






<graphicElement stretchType="NoStretch" pen="2Point" fill="Solid" />

<imageExpression class="net.sf.jasperreports.engine.JRRenderable"><![CDATA[((Scriptlet)$P{REPORT_SCRIPTLET}).getRenderer($F{Path})]]></imageExpression> </image>



The Scriptlet.java source:


import net.sf.jasperreports.engine.JRDefaultScriptlet;

import net.sf.jasperreports.engine.JRScriptletException;


import net.sf.jasperreports.engine.JRRenderable;


public class Scriptlet extends JRDefaultScriptlet {


/** Creates a new instance of Scriptlet */

public Scriptlet() {



public JRRenderable getRenderer(String svgFilename) {

return new SVGRenderer(svgFilename);




The SVGRenderer.java source:


import java.awt.Graphics2D;

import java.awt.geom.Rectangle2D;

import java.awt.geom.Dimension2D;

import java.awt.Color;


import org.csiro.svg.dom.*;

import org.csiro.svg.parser.*;

import org.csiro.svg.viewer.*;


public class SVGRenderer extends JRAbstractSvgRenderer {

private String svgfilename;


/** Creates a new instance of JSVGRenderer */

public SVGRenderer(String svgfilename) {

this.svgfilename = svgfilename;



public void render(Graphics2D grx, Rectangle2D rectangle) {



try {

SVGParser parser = new SVGParser();

SVGDocumentImpl doc = parser.parseSVG(svgfilename);

SVGSVGElementImpl root = (SVGSVGElementImpl)doc.getRootElement();

Canvas canvas = new org.csiro.svg.viewer.Canvas();

canvas.setSize((int)rectangle.getWidth(), (int)rectangle.getHeight());



canvas.setView(0,0,root.getWidth().getBaseVal().getValue(), root.getHeight().getBaseVal().getValue());


} catch (SVGParseException e) {

System.out.println("Parse exception while parsing SVG file: " + e.getMessage());






This solution use SvgToolkit components,

but I want to use batik, because SvgToolkit not implement

the new svg specification.


Thanks a lot.



By: found nothing - found-nothing

RE: Does anyone use Batik to import SVG ? Urgent

2005-05-22 05:57

hello macoute

I'm a newer in Jasperreport ,latestly,I'm doing a report ,It's necessary to use scriptlet ,but I dont know how to use it ! today I have red your article in sourceforge ! but I'm not know well how ,can you give me a whole Example about scriptlet !!

thank you very much !!!!

my e-mail is tomcat5257@yahoo.com

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...