Draw the Graphic2D to a template and use Image.getInstance(PdfTemplate) to
make it look like an image.

Best Regards,
Paulo Soares

----- Original Message ----- 
From: "Dirk Materlik" <[EMAIL PROTECTED]>
To: "iText" <[EMAIL PROTECTED]>
Sent: Monday, September 13, 2004 18:01
Subject: [iText-questions] Obtaining a Graphics2D for a PdfPTable-Cell


> Hello everyone,
>
> I'm trying to create a 2-column table in a PDF that has text in its
> left column and graphics in its right. I have a Java class that
> generates the graphics, into a java.awt.Graphics-object. So I would
> like to add a PdfPCell of specified height into a table and obtain a
> Graphics2D-Object for this cell only to have my existing class draw
> into it.
>
> I have come up with the following solution:
>
> Rectangle pageSize = document.getPageSize();
> PdfPCell c = new PdfPCell(new Phrase(""));
> c.setFixedHeight(CELL_HEIGHT);
> c.setCellEvent(new PdfPCellEvent() {
>        public void cellLayout(PdfPCell cell, Rectangle position,
> PdfContentByte[] canvases) {
>             Graphics2D g =
> canvases[PdfPTable.TEXTCANVAS].createGraphics(pageSize.width(),
> pageSize.height());
>             g.translate(position.left(), pageSize.height() -
> position.top());
>             rend.render(g, new Insets(0, 0, 0, 0),
>                  new Dimension((int) position.width(), (int)
> position.height()), <...some more parameters...>);
>        }
> });
> table.addCell(c);
>
> However, while prototypes indicate that I will be able to make this
> work the way I need it to, it strikes me as somewhat inelegant to draw
> on top of everything in a second pass.
>
> Thus my question: Is this the "recommended" solution for a problem like
> this? Or does anyone have a better idea?
>
> thanks,
> Dirk.
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
> Project Admins to receive an Apple iPod Mini FREE for your judgement on
> who ports your project to Linux PPC the best. Sponsored by IBM.
> Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php
> _______________________________________________
> iText-questions mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/itext-questions



-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM. 
Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to