Hi,
As the subject indicates, I'm trying to draw inside a PdfPCell without
success! I have looked around for examples for how to achieve this and
message board posts and came across a number of suggestions. I looked
into TableCellEvents but this seems to me to be more geared towards
'decorating' cells. I would like my cell to contain a number of drawings
(simple shapes) and text mixed together along the same line. The code
below follows Bruno Lowagie's suggestion to another poster of drawing in
a template and then wrapping this in an Image and then a Chunk. It works
except that the circle ends up at the bottom of the page outside of the
cell. I was under the impression that positions where relative to
containers. I'm obviously doing something wrong but I'm having trouble
determining what!
Any help that any of you could provide would be greatly appreciated.
Thanks,
Anthony
PS. Here's my code :
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("test.pdf"));
document.open();
PdfPTable table = new PdfPTable(2);
table.setHorizontalAlignment(Element.ALIGN_LEFT);
PdfPCell cell = new PdfPCell(new Phrase("There should be a
circle and some text next to me :"));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(cell);
PdfContentByte canvas = writer.getDirectContent();
PdfTemplate template = canvas.createTemplate(50,50);
canvas.fillStroke();
canvas.setColorStroke(Color.RED);
canvas.circle(25f, 25f, 25);
Image img = Image.getInstance(template);
Phrase phrase = new Phrase(new Chunk(img, 0, 0));
phrase.add(new Chunk("it's a circle!"));
cell = new PdfPCell(phrase);
table.addCell(cell);
document.add(table);
document.close();
}
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php