Jump to content
Changes to the Jaspersoft community edition download ×

Recommended Posts

By: Haissam Zaky - haissam


2006-07-08 11:19


I am kind confused and new to jasperreport, little guidance will be appreciated.


Does jasperreport support SVG? I am using jasperreports-0.6.5

I am trying to create a pdf document and include svg images.

I am creating the JasperDesign in my code and not thru the jrxml file.


Is that possible?

Thank you


I am getting illegal argument exception

From the class PdfGraphics2D,


Method private boolean drawImage (Image img, Image mask, AffineTransform xform, Color bgColor, ImageObserver obs) {


My code :



JRDesignExpression expression = new JRDesignExpression();


expression.setText("ImageLoader.createRendableImage("1")" );





public static final JRRenderable createRendableImage (String refId){



File svgImageFile = new File ("myImages/Orc.svg");

while (offset < bytes.length

&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {

offset += numRead;



JRRenderable pxRenderer =


pxRenderer =

new JRWrappingSvgRenderer( pxRenderer, new Dimension(100, 80), null);

return pxRenderer;




By: Maxim - lazy-max


2006-07-09 03:32

Answer here:




By: Haissam Zaky - haissam


2006-08-13 15:36


Thank you very much for your reply,

I did follow the link and I was able to render the SVG image in the report.

In my work I needed to create the report with PNG images and other time with svg image

I noticed that with the SVG image I cant control neither the stretch or the alignment of the image in the border, as a work around I modified a little the

Run method in the SVGThreadRenderer class. To get the same result when I am using png or svg images. Please see below



Summary of my experience if you want high quality SVG images in a pdf document,

Use batik to return pdf render image (pdf document with svg inside) the file will be smaller than a pure svg and the quality is the same. And to include it in the file, just use the itext library to include the pdf (with image) as image in your final document.






// added code *****************************************************



double imageActuelWidth = 0;

double imageActuelHeight =0 ;


NodeList nodeList = docSvg.getElementsByTagName("svg");

for (int i = 0; i < nodeList.getLength(); i++) {

Node child = nodeList.item(i);

// System.out.println(child.getNodeName());

System.out.println("child width: " + child.getAttributes().getNamedItem("width").getNodeValue());

imageActuelWidth = Double.valueOf(child.getAttributes().getNamedItem("width").getNodeValue());

System.out.println("child height: " + child.getAttributes().getNamedItem("height").getNodeValue());

imageActuelHeight = Double.valueOf(child.getAttributes().getNamedItem("height").getNodeValue());





double rectangleWidth = _rectangle.getWidth();

double rectangleHeight = _rectangle.getHeight();


// we do this caluclation because

// with png and not svg , when we render a

// png image even if we ask for 100 x 80 pixel we will get a png image with different //dimensions


// ex: a png picture w=142 , h=348 and we request an image 100p X 80 p you will get an // image with w=33 h=80, we take the ratio of the bigger between

// the width and the height and multiply by the smaller


if (imageActuelHeight > imageActuelWidth ){ // if 348 > 142

// adjust the desired width instead of 100 to 142 * 80/348 = 33

rectangleWidth = Math.ceil (imageActuelWidth * rectangleHeight / imageActuelHeight);

} else { // else adjust the height

rectangleHeight = Math.ceil (imageActuelHeight * rectangleWidth / imageActuelWidth);


// added code *****************************************************


// Ratio

Rectangle2D rectBounds = gvtTree.getBounds();

double ratioX = rectangleWidth / rectBounds.getWidth();

double ratioY = rectangleHeight / rectBounds.getHeight();



double ratio = ratioX < ratioY ? ratioX : ratioY;

if(ratio > 1)

ratio = 1;


double rectWidth = rectBounds.getWidth() * ratio;

double rectHeight = rectBounds.getHeight() * ratio;





// Top Left point

double startX = _rectangle.getX() + (rectangleWidth - rectWidth)/2;

double startY = _rectangle.getY() + (rectangleHeight - rectHeight)/2;


// Save original transform

AffineTransform saveAT = _graphics.getTransform();


// Perform transformation

_graphics.transform(new AffineTransform(ratio, 0, 0, ratio, startX, startY));


// Render




// Restore original transform



vpInput = null;

vpTranscoder = null;

vpFactory = null;




} catch(Exception e) {





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