Quite simple.
The tecnique I use to mix charts with other regular iText output like Phrases, Chunks
is to create an empty table to reserve space, and in an table event draw the table.
In the event I have all the needed data to position exactly the chart.
Here is a snippet of the code I use:
PdfPTable tbl = new PdfPTable(1);
tbl.setTableEvent(new EventoTbl());
// Separation with previous contents
PdfPCell cell = new PdfPCell(new Phrase(""));
cell.setFixedHeight(20);
cell.setBorder(Rectangle.NO_BORDER);
tbl.addCell(cell);
// Where the charts will be placed
cell = new PdfPCell(cell);
celda.setFixedHeight(200);
tbl.addCell(cell);
Here is the inner class that implements the event:
class EventoTbl implements PdfPTableEvent {
public void tableLayout(PdfPTable table, float[][] widths, float[]
heights, int headerRows, int rowStart, PdfContentByte[] canvases) {
if (heights.length != 3) {
return;
}
// ###Crear graficas
JFreeChart chart;
chart = ChartFactory.createLineChart(...);
float tamY = doc.getPageSize().height();
Graphics2D g2 =
ctx.cb.createGraphics(ctx.doc.getPageSize().width(), tamY);
chart.draw(g2, new Rectangle2D.Float(left(), tamY-heights[1],
doc.right()-doc.left(), heights[1]-heights[2]));
g2.dispose();
}
}
Hope it's useful to you.
Please, make it available to the iText community.
--------
David
-----Mensaje original-----
De: Martin Hald [mailto:[EMAIL PROTECTED]
Enviado el: mi�rcoles, 01 de octubre de 2003 8:37
Para: Carmona Perez, David
Asunto: iText and JFreeChart
Hi David,
I am interested in integrating JFreeChart and iText to show charts in a
rendered PDF. I have followed your posting (dated Augh 28, 2003) but am
unable to get the same result.
Would it be possible to share the source that used tables events and
PdfContentByte? I would be ever so grateful, and if you are open to it
perhaps I can wrap the code into an example that can be given back to iText
to be used in a cookbook.
Martin Hald
[EMAIL PROTECTED]
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions