/**//* * $Id: JFreeChartExample.java 1778 2005-06-02 11:05:39Z blowagie $ * $Name$ * * This code is part of the 'iText Tutorial'. * You can find the complete tutorial at the following address: * http://itextdocs.lowagie.com/tutorial/ * * This code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * itext-questions@lists.sourceforge.net */ package com.lowagie.examples.directcontent.graphics2D; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.io.FileNotFoundException; import java.io.FileOutputStream; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Rectangle; import com.lowagie.text.pdf.DefaultFontMapper; import com.lowagie.text.pdf.PdfContentByte; import com.lowagie.text.pdf.PdfTemplate; import com.lowagie.text.pdf.PdfWriter; /** *//** * JFreeChart example. */ publicclass JFreeChartExample ...{
/** *//** * Creates some PDFs with JFreeCharts. * @param args no arguments needed */ publicstaticvoid main(String[] args) ...{
System.out.println("JFreeChart example"); /** *//** the following line is a workaround for JDK 1.5 (fix by Adriaan Joubert) */ org.jfree.text.TextUtilities.setUseDrawRotatedStringWorkaround(false); convertToPdf(getBarChart(), 400, 600, "barchart.pdf"); convertToPdf(getPieChart(), 400, 600, "piechart.pdf"); convertToPdf(getXYChart(), 400, 600, "xychart.pdf"); } /** *//** * Converts a JFreeChart to PDF syntax. * @param filename the name of the PDF file * @param chart the JFreeChart * @param width the width of the resulting PDF * @param height the height of the resulting PDF */ publicstaticvoid convertToPdf(JFreeChart chart, int width, int height, String filename)
项目要求,没办法,生成的jsp页面要打印。于是要生成pdf大概查了一下itext主站的实例如下 :/**//* * $Id: JFreeChartExample.java 1778 2005-06-02 11:05:39Z blowagie $ * $Name$ * * This code is part of the iText Tutorial. * You can find th