I have two tables which must fit into the sam page. So I did create a main table
(class Table) and used its metod 'setTableFitsPage (true)'; then I inserted my 2
table (class Table, too) as cells into the main table (with som space between).
That worked.
Now I use class PdfPTable. I didn't want to change my code a lot, and after
inserting the tables, I only got the space between them. I didnt find something
which would be equivalent to '<Table>.setTableFitsPage' in PdfPTable.
I send you a simplified piece of code to show you what was running and what I'm
trying to do now (it's executable). What's wrong?
Thank you very much for any hint
Christoph
=======================================================================
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();
}
}
-------------------------------------------------------
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