The only thing you are doing wrong is using a Table
instead of PdfPTable. Perhaps Steve Appling has good
news for you.
--- Mahler Frank <[EMAIL PROTECTED]> wrote:
> Hello iText list!
>
> I experienced some severe problems regarding the
> Table class
> in itext-1.1 (and itext-paulo-143). As long as I
> create only one
> table in my pdf document, everything's fine.
>
> But the more tables I add, the more additional space
> within table
> cells is added that leads to cellcontent not
> centered within the
> cells, but somewhere below the cells (see attached
> pdf).
>
> I experienced with other fonts, but with no efforts.
>
> Please have a look at the code below - am I doing
> something wrong?
>
> Any help is greatfully appreciated.
>
> Best regards,
>
> Frank
>
>
----------8<----------8<----------8<----------8<----------8<-------
> package de.isenergy.iTextTest;
>
> import java.awt.Color;
> import java.io.FileOutputStream;
>
> import junit.framework.Test;
> import junit.framework.TestCase;
> import junit.framework.TestSuite;
>
> import com.lowagie.text.Cell;
> import com.lowagie.text.Document;
> import com.lowagie.text.Element;
> import com.lowagie.text.Font;
> import com.lowagie.text.PageSize;
> import com.lowagie.text.Paragraph;
> import com.lowagie.text.Rectangle;
> import com.lowagie.text.Table;
> import com.lowagie.text.pdf.BaseFont;
> import com.lowagie.text.pdf.PdfPTable;
> import com.lowagie.text.pdf.PdfWriter;
>
> import de.isenergy.iTextTest.BootTest;
>
> public class CreatePDFiTextError extends TestCase {
>
> Document document = null;
> PdfWriter writer = null;
> BaseFont bfPoloR = null;
> BaseFont bfPoloB = null;
>
> public CreatePDFiTextError() {
> super();
> }
>
> public CreatePDFiTextError(String arg0) {
> super(arg0);
> }
>
> private void createTable() throws Exception {
> Table table = null;
> Cell cell = null;
> Paragraph p = null;
>
> table = new Table(3);
> table.setBorder(Rectangle.NO_BORDER);
> table.setWidth(45);
> table.setWidths(new int[]{4,3,3});
> table.setAlignment(Table.ALIGN_LEFT);
> table.setPadding(1);
> table.setSpacing(2);
>
> Cell emptycell = new Cell();
> emptycell.setBorder(Rectangle.NO_BORDER);
>
>
emptycell.setVerticalAlignment(Element.ALIGN_MIDDLE);
> table.setDefaultLayout(emptycell);
>
> cell = new Cell(new Paragraph(8, "1st row", new
> Font(0, 8)));
> table.addCell(cell);
>
> cell = new Cell(new Paragraph(8, "tt.mm.jjjj", new
> Font(0, 8)));
> cell.setBackgroundColor(new Color(210,210,210));
> cell.setHorizontalAlignment(Element.ALIGN_CENTER);
> table.addCell(cell);
>
> cell = new Cell(new Paragraph(8, "hh:mm", new
> Font(0, 8)));
> cell.setBackgroundColor(new Color(210,210,210));
> cell.setHorizontalAlignment(Element.ALIGN_CENTER);
> table.addCell(cell);
>
> table.addCell(emptycell);
> table.addCell(emptycell);
> table.addCell(emptycell);
>
> cell = new Cell(new Paragraph(8, "2nd row", new
> Font(0, 8)));
> table.addCell(cell);
>
> cell = new Cell(new Paragraph(8, "1st field", new
> Font(0, 8)));
> cell.setBackgroundColor(new Color(210,210,210));
> cell.setHorizontalAlignment(Element.ALIGN_CENTER);
> table.addCell(cell);
>
> cell = new Cell(new Paragraph(8, "2nd field", new
> Font(0, 8)));
> cell.setBackgroundColor(new Color(210,210,210));
> cell.setHorizontalAlignment(Element.ALIGN_CENTER);
> table.addCell(cell);
>
> cell = new Cell(new Paragraph(8, "3rd row", new
> Font(0, 8)));
> table.addCell(cell);
>
> cell = new Cell(new Paragraph(8, "tt.mm.jjjj", new
> Font(0, 8)));
> cell.setBackgroundColor(new Color(210,210,210));
> cell.setHorizontalAlignment(Element.ALIGN_CENTER);
> table.addCell(cell);
> table.addCell(emptycell);
>
> cell = new Cell(new Paragraph(8, "4th row", new
> Font(0, 8)));
> table.addCell(cell);
>
> cell = new Cell(new Paragraph(8, "tt.mm.jjjj", new
> Font(0, 8)));
> cell.setBackgroundColor(new Color(210,210,210));
> cell.setHorizontalAlignment(Element.ALIGN_CENTER);
> table.addCell(cell);
>
> cell = new Cell(new Paragraph(8, "hh:mm", new
> Font(0, 8)));
> cell.setBackgroundColor(new Color(210,210,210));
> cell.setHorizontalAlignment(Element.ALIGN_CENTER);
> table.addCell(cell);
>
> cell = new Cell(new Paragraph(8, "ID", new Font(0,
> 8)));
> table.addCell(cell);
>
> cell = new Cell(new Paragraph(8, "ID field", new
> Font(0, 8)));
> cell.setBackgroundColor(new Color(210,210,210));
> cell.setHorizontalAlignment(Element.ALIGN_CENTER);
> table.addCell(cell);
> table.addCell(emptycell);
> document.add(table);
>
> document.add(new Paragraph(0, " "));
>
> }
>
>
> public void testCreate() throws Exception {
> Paragraph p = null;
>
> document = new Document(PageSize.A4.rotate());
>
> // bfArial =
> BaseFont.createFont("C:/windows/fonts/ARIAL.TTF",
> BaseFont.CP1252, BaseFont.EMBEDDED);
>
> writer = PdfWriter.getInstance(document, new
> FileOutputStream("C:/filename.pdf"));
>
> document.setMargins(40,40,15,15);
>
> document.addTitle("iText Test");
> document.addSubject("wrong alignment in table
> cells");
> document.addCreator("Java");
> document.addAuthor("Frank Mahler");
>
> document.open();
>
> p = new Paragraph("iText Test", new Font(bfPoloB,
> 24, Font.NORMAL, new Color(255,0,0)));
> document.add(p);
>
> p = new Paragraph(12,"");
> document.add(p);
>
> createTable();
> createTable();
> createTable();
> createTable();
> createTable();
>
> document.close();
>
>
=== message truncated ===
> ATTACHMENT part 2 application/pdf name=filename.pdf
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions