简体   繁体   中英

itext pdf doesn't show table when setHeaderRows

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, ie 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM