I created a table with N columns header using setHeaderRows(N), when I add to the table N-1 records and deploy, nothing is displayed, i.e. if I create a table that has 5 columns header and just add 4 records or less to the table, nothing is displayed.
Sample Code
Document document = new Document(new Rectangle(605, 784), 28, 28, 42, 28);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("/temp/tabla.pdf"));
documento.open();
// Create table
PdfPTable tabla = new PdfPTable(5);
tabla.setComplete(false);
tabla.setWidthPercentage(100);
tabla.getDefaultCell().setBackgroundColor(BaseColor.WHITE);
tabla.setHeaderRows(5);
// Add Header Rows
for(int i=1; i<=5; i++)
{
celda = new PdfPCell();
Paragraph encabezado = new Paragraph("Header "+i);
celda.addElement(encabezado);
celda.setGrayFill(0.8f);
tabla.addCell(celda);
}
// Add some cells
for(int k=0; k<19; k++)
{
celda = new PdfPCell();
Paragraph contenido = new Paragraph("Cell "+k, helvetica11);
celda.addElement(contenido);
tabla.addCell(celda);
}
// In total add 4 rows
tabla.completeRow();
document.add(tabla);
document.close();
Normally the table cells are filled with data from a SQL query, which can return one or many records, I have filled the table with a single "for" cycle to show malfunction.
Someone could help me how to solve this problem? What parameter should I set? or any idea?
Your table consists of nothing but header rows. There is no real data in your table.
You should change:
tabla.setHeaderRows(5);
Into:
tabla.setHeaderRows(1);