Hi Paulo, it seems there's a problem with the PdfWriter.fitsPage method for PdfPTables has a little bug. The attached JAVA program creates a table that should be kept together on one page. To do this it calls the fitsPage method of the PdfWriter to check the remaining space at the current page. In the following expample - which implements a test case, submitted by an UJAC user - fitsPage returns true, but the table doesn't really fit the page and when the table is added to the document, the last table row is displayed on the next page.
Best regards, Christian -- Christian Lauer <[EMAIL PROTECTED]>
package ujac.test.itext;
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Chunk;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
public class FitsPageTest {
public static void main(String[] args) {
try {
FileOutputStream os = new FileOutputStream("test.pdf");
Document document = new Document(PageSize.A4, 25, 25, 25, 25);
PdfWriter documentWriter = PdfWriter.getInstance(document, os);
document.open();
Font font = new Font(Font.HELVETICA, 10);
Paragraph p = new Paragraph();
p.setSpacingAfter(378);
document.add(p);
PdfPTable tab = new PdfPTable(new float[] {100});
tab.setWidthPercentage(100);
for (int i = 0; i < 25; i++) {
PdfPCell c = new PdfPCell(new Phrase(Integer.toString(i)));
tab.addCell(c);
}
if (!documentWriter.fitsPage(tab)) {
document.newPage();
}
document.add(tab);
document.close();
documentWriter.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
test.pdf
Description: Adobe PDF document
