You should add the circle to the template.

paulo 

-----Original Message-----
From: Anthony Webster [mailto:[email protected]] 
Sent: Wednesday, January 26, 2011 11:26 AM
To: [email protected]
Subject: [iText-questions] Problems drawing in a PdfPCell

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


Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter 
informação confidencial ou legalmente protegida. A incorrecta transmissão desta 
mensagem não significa a perca de confidencialidade. Se esta mensagem for 
recebida por engano, por favor envie-a de volta para o remetente e apague-a do 
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de 
usar, revelar ou distribuir qualquer parte desta mensagem. 

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain 
confidential or legally protected information. The incorrect transmission of 
this message does not mean the loss of its confidentiality. If this message is 
received by mistake, please send it back to the sender and delete it from your 
system immediately. It is forbidden to any person who is not the intended 
receiver to use, distribute or copy any part of this message.


------------------------------------------------------------------------------
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

Reply via email to