I have two tables which must fit together to the same page. As I'm changing old 
code, I want to do it in abuot the sam way I had done it before.

I create a main table into which I insert each of my two tables (class Table) 
as a cell (with some space between). This main table used 'setTableFitsPage 
(true)' and so I got what I wanted. Because I now use class PdfPTable, I 
changed the code a little bit, but in the main table, I now only have the space 
between my two tables.

What's wrong? Here a 'summary' of my code:

================================================================================

import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPCell;

public class test_ck {
    public static Table getMainTable () throws BadElementException {
        Table retVal = new Table (1);

        retVal.setTableFitsPage (true);
        retVal.setBorder (Table.NO_BORDER);
        retVal.setDefaultVerticalAlignment (Table.ALIGN_MIDDLE);
        retVal.setAlignment (Table.ALIGN_LEFT);
        retVal.setPadding (0f);
        retVal.setWidth (100f);

        return retVal;
    }

    public static Table getTable () throws BadElementException {
        Table retVal = new Table (4);
        retVal.setBorder (0);
        retVal.setDefaultVerticalAlignment (Table.ALIGN_MIDDLE);
        retVal.setDefaultHorizontalAlignment (Table.ALIGN_LEFT);
        retVal.setAlignment (Table.ALIGN_LEFT);
        retVal.setWidth (100f);
        retVal.setWidths (new float[] {25f, 25f, 25f, 25f});

        Cell cell = new Cell("Title");
        cell.setColspan(4);
        retVal.addCell(cell);
        for (int inx = 0; inx < 8; inx++) {
            retVal.addCell(new Cell("field"));
        }

        return retVal;
    }

    public static PdfPTable getPdfPTable () throws BadElementException, 
DocumentException {
        PdfPTable retVal = new PdfPTable (4);
        retVal.setWidthPercentage (100f);
        retVal.setWidths(new float[] {25f, 25f, 25f, 25f});

        PdfPCell cell = new PdfPCell(new Paragraph("Title"));
        cell.setColspan(4);
        retVal.addCell(cell);
        for (int inx = 0; inx < 8; inx++) {
            retVal.addCell(new PdfPCell(new Paragraph("field")));
        }

        return retVal;
    }

    public static void addSpace (Table table) {
        Cell space = new Cell ("\n");
        table.addCell(space);
    }

    public static void main(String[] args) {
        Document document = new Document();
        Table mainTable = null;

        try {
            PdfWriter.getInstance(document, new FileOutputStream
("test_ck.pdf"));
            document.open();

            // -----------------------------------------------------------------
            // do it with Table

            mainTable = getMainTable();

            // table 1
            mainTable.addCell((new Cell(getTable ())));

            // add some space
            addSpace(mainTable);
            addSpace(mainTable);

            // table 2
            mainTable.addCell((new Cell(getTable())));

            document.add(mainTable);

            // -----------------------------------------------------------------
            // space

            document.add(new Paragraph ("\n\n\n\n\n"));
            mainTable = null;

            // -----------------------------------------------------------------
            // do it with PdfPTable

            mainTable = getMainTable();

            // table 1
            mainTable.addCell((new Cell(getPdfPTable ())));

            // add some space
            addSpace(mainTable);
            addSpace(mainTable);

            // table 2
            mainTable.addCell((new Cell(getPdfPTable())));

            document.add(mainTable);
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        document.close();
    }

}


================================================================================

Thank you
Christoph
  



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to