I had to put a JFreeChart in a PDF that used tables a couple of weeks ago and couldn't 
find any good instructions or code examples. Here's a sketchy outline of what I did 
that worked -- of course this can be improved upon, but it does show how I used a 
ByteArrayOutputStream to get the image (which is what I think you were trying to 
determine how to do):

Open a PdfWriter and open the document
Instantiate a table, cells and add cells to table
When you're ready for the chart, create the chart object:
        //get the data for the chart
        CategoryDataset data = geteBarChartData(bemsid);
        //get a chart rendering object
        ChartRenderingInfo info = new ChartRenderingInfo(new 
StandardEntityCollection());
        //Make the chart
         JFreeChart chart = makeChart(data, bShowLegend);
        //set up the image size for the chart
        int width = 550;
        int height = 250;
        //open a byte array output stream (baos)
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //use a utility that writes the chart to a JPEG using the 
ByteArrayOutputStream         
        ChartUtilities.writeChartAsJPEG(baos, chart, width, height, info);
        //Instantiate an image using the ByteArrayOutputStream
        Image barChartImage = Image.getInstance(baos.toByteArray());
        //flush and close the stream
        baos.flush();
        baos.close();

        //now I needed to add the Chart to a cell in a table
        detailCell = new Cell();
        detailCell.setColspan(5);
        detailCell.setBorder(cellBorder_);
        detailCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        detailCell.setVerticalAlignment(Element.ALIGN_TOP);
        //add the chart to a table cell 
        detailCell.add(barChartImage);
        //add the cell to the table -- or to the document if that's what you need to do
        table4_.addCell(detailCell); //bar chart


Hope this helps!

Harry Wegley

-----Original Message-----
Message: 2
Subject: RE: [iText-questions] Graphic and table in PDF
Date: Mon, 19 Jul 2004 11:20:58 -0400
From: "Lora Lantzy" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>

Thank you for the quick response.

Now I am confused as to how to add the Graphics2D object to the = template.  I 
appreciate the help!

Lora Lantzy


-----Original Message-----
From: Paulo Soares [mailto:[EMAIL PROTECTED]
Sent: Friday, July 16, 2004 5:15 PM
To: Lora Lantzy; [EMAIL PROTECTED]
Subject: Re: [iText-questions] Graphic and table in PDF

I suppose you are doing it through Graphics2D. Write the chart to a = template and 
wrap it in an Image.

Best Regards,
Paulo Soares

----- Original Message -----
From: "Lora Lantzy" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, July 16, 2004 17:07
Subject: [iText-questions] Graphic and table in PDF


I am trying to have both a graphic and table in a pdf, thus far I can = only get one 
or the other.  I am using JCharts to create the graphic and the iText Table for the 
text.  Has anyone done this successfully? If so I = would appreciate any help you can 
provide.  I have been working on this for a = few days and tried incorporating the 
example from the tutorial (Ch 10) but I can't get it to work.

Thank you,
Lora Lantzy



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idG21&alloc_id040&op=click
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to