Hi,

I'm trying to figure out why the following code produces table cells 
that are far taller that their content. If I try reducing the cell 
height with setFixedHeight() the cell contents end up disapearing before 
I get remotely close to the content heights (the circles are 12 in 
diameter). Any ideas?

Thanks

Anthony

public static void main(String[] args) throws Exception {
         new Test().run();
}

public void run() throws Exception {

         Document document = new Document();
         PdfWriter writer = PdfWriter.getInstance(document, new 
FileOutputStream("new.pdf"));
         document.open();

         Font font = new Font(Font.HELVETICA, 9, Font.NORMAL, Color.BLACK);

         PdfPTable table = new PdfPTable(2);
         table.setHorizontalAlignment(Element.ALIGN_LEFT);
         table.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);

         PdfContentByte canvas = writer.getDirectContent();
         PdfTemplate template = canvas.createTemplate(12, 12);

         template.setLineWidth(1);
         template.setColorStroke(Color.BLACK);
         template.circle(6f, 6f, 5);
         template.stroke();

         Image img = Image.getInstance(template);

         MyPdfPCell cell = new MyPdfPCell();
         Phrase phrase = new Phrase(new Chunk(img, 0, 0));
         cell.addElement(phrase);

         table.addCell(cell);

         cell = new MyPdfPCell();
         cell.addElement(new Phrase("Test", font));
         cell.setPaddingLeft(5);
         table.addCell(cell);

         canvas = writer.getDirectContent();
         template = canvas.createTemplate(12, 12);

         template.setLineWidth(1);
         template.setBoundingBox(new Rectangle(12,12));
         template.setColorStroke(Color.BLACK);
         template.circle(6f, 6f, 5);
         template.stroke();

         img = Image.getInstance(template);

         cell = new MyPdfPCell();
         phrase = new Phrase(new Chunk(img, 0, 0));
         cell.addElement(phrase);

         table.addCell(cell);

         cell = new MyPdfPCell();
         cell.addElement(new Phrase("Test", font));
         cell.setPaddingLeft(5);
         table.addCell(cell);

         table.setWidthPercentage(new float[] { 15, 100}, 
document.getPageSize());

         document.add(table);

         document.close();
}

class MyPdfPCell extends PdfPCell {

         MyPdfPCell() {
             super();
             init();
         }
         MyPdfPCell(PdfPCell cell) {
             super(cell);
             init();
         }
         MyPdfPCell(Image image) {
             super(image);
             init();
         }
         MyPdfPCell(Image image, boolean fit) {
             super(image, fit);
             init();
         }
         MyPdfPCell(Phrase phrase) {
             super(phrase);
             init();
         }
         MyPdfPCell(PdfPTable table) {
             super(table);
             init();
         }

         private void init() {
             setPadding(0);
             setMinimumHeight(12);
             setUseBorderPadding(false);
             //setFixedHeight(16);
             setLeading(0, 0);
             setHorizontalAlignment(Element.ALIGN_LEFT);
             setVerticalAlignment(ALIGN_MIDDLE);
         }
     }


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