a generic way to export your chart using ImageIO supported graphic format : (sample as PNG)
public void writeAsPNG( JFreeChart chart, OutputStream out, int width, int height )
{
try
{
BufferedImage chartImage = chart.createBufferedImage( width, height, null);
ImageIO.write( chartImage, "png", out );
}
catch (Exception e)
{
LOG.error( e );
}
}
a sample to create PDF using iText (
http://www.lowagie.com/iText)
public void writeAsPDF( JFreeChart chart, OutputStream out, int width, int height )
{
try
{
Rectangle pagesize = new Rectangle( width, height );
Document document = new Document( pagesize, 50, 50, 50, 50 );
PdfWriter writer = PdfWriter.getInstance( document, out );
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate( width, height );
Graphics2D g2 = tp.createGraphics( width, height, new DefaultFontMapper() );
Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height );
chart.draw(g2, r2D);
g2.dispose();
cb.addTemplate(tp, 0, 0);
document.close();
}
catch (Exception e)
{
LOG.error( e );
}
}