Take the 2-minute tour ×

i am able to render my charts to different file types:

 dRenderer = ce.getRenderer("dv.SVG");//or dv.PNG
 dRenderer.setProperty(IDeviceRenderer.FILE_IDENTIFIER, path);

but how to get the binary data as a stream? the charts will most likely be end in some one's browser. so a file on disk i relativly useless.

(it would be stupid to save many charts on disk before reading them again, wouldn't it?)

Answer in short:

it is possible to give an Outputstream instead of a path string as "FILE_IDENTIFIER" (works with both "dv.SVG" and "dv.PNG")

share|improve this question

3 Answers 3

up vote 1 down vote accepted

If you are using SVG set the file identifier to the output stream and make sure to set the content type(response.setContentType( "image/svg+xml" );

        RunTimeContext rtc = new RunTimeContext( );
        rtc.setULocale( ULocale.getDefault( ) );

        Generator gr = Generator.instance( );
        GeneratedChartState gcs = null;
        Bounds bo = BoundsImpl.create( 0, 0, 600, 400 );
        gcs = gr.build( idr.getDisplayServer( ), chart, bo, null, rtc, null );

        idr.setProperty( IDeviceRenderer.FILE_IDENTIFIER, out ); 
                new EmptyUpdateNotifier( chart, gcs.getChartModel( ) ) );

        gr.render( idr, gcs );

See this link

share|improve this answer
thx for complete example on eclipse forum. to give a outputstream as "FILE_IDENTIFIER" is simple but not obvious ;-). –  dermoritz Sep 10 '12 at 6:56

I don't know BIRT that much, but what you can do is set the renderer to render the image in a BufferedImage and get the bytes out of it.

dRenderer = ce.getRenderer("dv.PNG");

BufferedImage img = new BufferedImage(size1, size2, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D)img.getGraphics();
dRenderer.setProperty(IDeviceRenderer.GRAPHICS_CONTEXT, g2d);
dRenderer.setProperty(IDeviceRenderer.CACHED_IMAGE, img);

// render

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "png", baos);
byte[] imgBytes = baos.toByteArray();

I don't think it will work for SVG though. But there seems to be a newer API to generate reports with BIRT, where you can passe Rendering Options to the renderer, especially an option to set an OutputStream, you will give it a ByteArrayOutputStream and there you go, you can serve it to your web client.

share|improve this answer
thx the png part is solved. but i cant find something to get svg as an object (String or something else)? I can't find anything in "IDeviceRenderer" - do you have further tips? –  dermoritz Sep 7 '12 at 11:03

If you want to return your PNG directly to a browser, you need some kind of server-side machinery. Here you can see how to do it with a REST service

share|improve this answer

Your Answer


