Jump to content
Changes to the Jaspersoft community edition download ×

Does anyone use Batik to import SVG ? Urgent


2005 IR Help

Recommended Posts

By: macoute - macoute

Does anyone use Batik to import SVG ? Urgent

2004-10-27 07:59

Does anyone use Batik to import SVG in JasperReports?

 

In the template, I declare an image as follow:

<detail>

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

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

<reportElement

x="0"

y="0"

width="200"

height="200"/>

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

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

</band>

 

 

The Scriptlet 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) {

//grx.draw(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.setBackground(Color.white);

canvas.setSVGDocument(doc);

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

canvas.doPaint(grx);

} 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: macoute - macoute

RE: Does anyone use Batik to import SVG ? Urg

2004-10-27 08:01

The scriptlet source is hereafter:

 

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 void afterReportInit() throws JRScriptletException {

this.setVariableValue("SVG", new SVGRenderer());

}*/

 

public JRRenderable getRenderer(String svgFilename) {

return new SVGRenderer(svgFilename);

}

}

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...