JFreeChart几则实例之itext生成PDF篇

本文档介绍如何在项目中利用JFreeChart生成图表,并结合iText库将这些图表嵌入到PDF文件中,解决日文显示和分页后图片坐标处理的问题。通过实例代码展示关键步骤,包括生成PDF和添加语言支持。
摘要由CSDN通过智能技术生成

项目要求,没办法,生成的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 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.
 
*/

public   class  JFreeChartExample  {
    
    
/**
     * Creates some PDFs with JFreeCharts.
     * 
@param args no arguments needed
     
*/

    
public static void 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(), 
400600"barchart.pdf");
        convertToPdf(getPieChart(), 
400600"piechart.pdf");
        convertToPdf(getXYChart(), 
400600"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
     
*/

    
public static void convertToPdf(JFreeChart chart, int width, int height, String filename) 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值