在将图表JFreeChart添加到PdfiText时出现问题

问题描述

|| 当我在文档中添加1个图表时没有问题 当我添加第二张图表时,出现此错误... 线程\“ main \” com.itextpdf.text.exceptions.IllegalPdfSyntaxException中的异常:不平衡的保存/还原状态运算符。
chart1 = SpecialJFreeChartBuilder.createChart1(
                \"Site and Number of Requests \",results);

        document.newPage();

        PdfContentByte Add_Chart_Content = writer.getDirectContent();
        PdfTemplate template_Chart_Holder = Add_Chart_Content
                .createTemplate(width,height);
        Graphics2D Graphics_Chart = template_Chart_Holder.createGraphics(
                width,height,new DefaultFontMapper());
        Rectangle2D Chart_Region = new Rectangle2D.Double(0,540,380);
        chart1.draw(Graphics_Chart,Chart_Region);
        Graphics_Chart.dispose();
        Add_Chart_Content.addTemplate(template_Chart_Holder,0);

        chart2 = SpecialJFreeChartBuilder.createChart2(
                \"Site and totalAmount \",results);

        document.newPage();

        PdfContentByte Add_Chart_Content1 = writer.getDirectContent();
        PdfTemplate template_Chart_Holder1 = Add_Chart_Content1
                .createTemplate(width,height);
        Graphics2D Graphics_Chart1 = template_Chart_Holder1.createGraphics(
                width,new DefaultFontMapper());
        Rectangle2D Chart_Region1 = new Rectangle2D.Double(0,380);
        chart2.draw(Graphics_Chart1,Chart_Region1);
        Graphics_Chart.dispose();
        Add_Chart_Content.addTemplate(template_Chart_Holder1,0);
....                 document.close(); 谁能帮我 ....     

解决方法

        解决了这个问题... Graphics_Chart.dispose();必须是:Graphics_Chart1.dispose(); Graphics_Chart2.dispose();