Hi
We have run into a problem using table.setComplete(false) to efficiently add a
table that spans multiple pages. This causes the table header to be missing
from some pages. The problem appears to occur when the last row added before
calling document.add(table) is the last row in a page, so the next set of rows
begin on a new page. In the example below the header is missing from the third
page.
This works as expected for itext versions before 5.1.0 but doesn't for the
latest versions. Is this a bug, or am I missing something?
Thanks
Mark
package test;import java.io.FileNotFoundException;
import java.io.FileOutputStream;import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.Font.FontFamily;
import com.itextpdf.text.PageSize;public class TableHeaderTest { private
void createDocument() { Document document = new
Document(PageSize.A4);
try {
PdfWriter.getInstance(document, new
FileOutputStream("example.pdf")); document.open();
PdfPTable table = new PdfPTable(2);
table.setWidths(new int[] { 15, 85 });
table.setWidthPercentage(100);
table.setHeaderRows(1);
table.addCell(new Phrase("Count", new Font(Font.FontFamily.TIMES_ROMAN, -1,
Font.BOLD ) ) );
table.addCell(new Phrase("Name", new
Font(Font.FontFamily.TIMES_ROMAN, -1, Font.BOLD ) ) );
table.setComplete(false); for ( int i=0 ; i < 200 ; i++
){ table.addCell( String.valueOf(i) );
table.addCell( "Testing with entry " + i );
if (i > 0 && i % 93 == 0) { // Last row on second
page.
document.add(table);
}
} table.setComplete(true);
document.add(table);
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (DocumentException e) {
e.printStackTrace();
}
finally {
document.close();
}
} public static void main(String[] args){
new TableHeaderTest().createDocument();
}}
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
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