For those interested in exporting charts to Acrobat PDF format, developer Jim Moore has kicked off development of a PDFGraphics2D class using iText. In a very short space of time, he and a few other developers have got something that works pretty well, and it looks like this class will be a part of the standard iText package shortly. As soon as that happens, I will add a demo application to the JFreeChart package that shows how to use JFreeChart with iText.
iText is at: http://www.lowagie.com/iText
By the way, PDFGraphics2D can be used with any code that currently uses Graphics2D (as JFreeChart does), so it will be a pretty useful piece of code for a wide range of applications.
Regards,
DG.
Export to PDF...
Pls send a sample program to convert in to pdf
I am a student exploring JFreeChart and i want to convert char t in to pdf. pls reply soon.
with subject : Chart to PDF
expecting your reply
pradheept@hotmail.com
tpradheep@yahoo.com
with subject : Chart to PDF
expecting your reply
pradheept@hotmail.com
tpradheep@yahoo.com
Based on David's Demonstration application, here's a method to save a JFreeChart as a PDF file:
Have fun! 
Code: Select all
/**
* Save chart as PDF file. Requires iText library.
*
* @param chart JFreeChart to save.
* @param fileName Name of file to save chart in.
* @param width Width of chart graphic.
* @param height Height of chart graphic.
* @throws Exception if failed.
* @see <a href="http://www.lowagie.com/iText">iText</a>
*/
public void saveChartToPDF(JFreeChart chart, String fileName, int width, int height) throws Exception {
if (chart != null) {
BufferedOutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(fileName));
//convert chart to PDF with iText:
Rectangle pagesize = new Rectangle(width, height);
com.lowagie.text.Document document = new com.lowagie.text.Document(pagesize, 50, 50, 50, 50);
try {
PdfWriter writer = PdfWriter.getInstance(document, out);
document.addAuthor("JFreeChart");
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, eight);
chart.draw(g2, r2D, null);
g2.dispose();
cb.addTemplate(tp, 0, 0);
} finally {
document.close();
}
} finally {
if (out != null) {
out.close();
}
}
}//else: input values not availabel
}//saveChartToPDF()

-
- Posts: 14
- Joined: Wed Sep 12, 2007 7:05 pm
-
- Posts: 14
- Joined: Wed Sep 12, 2007 7:05 pm
found solution.
jwenting,
i think i found a better solution:
it renders the graphic as a vector image. now my graphics looks pretty on pdf 
thanks for your reply.
i think i found a better solution:
Code: Select all
JRAbstractRenderer jfcRenderer = new JFreeChartRenderer(chart);

thanks for your reply.