ItextSHARP table splitting problem
I created a sample project using itextsharp. In this I mentioned Footer and table, I generate rows on a loop for a given number, if the table splits to another page then I have one blank page that has no data. Seems to be undefined.
Here is the code:
PdfWriter.GetInstance(document, New FileStream(ConfigurationManager.AppSettings("PDFPath") & fileName, FileMode.Create))
Dim FooterFont As Font = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD)
Dim FooterTxt As Phrase = New Phrase(Format(Now, "MM/dd/yyyy") )
Dim footer As New HeaderFooter(FooterTxt, True)
footer.Border = iTextSharp.text.Rectangle.TOP_BORDER
document.Footer = footer
document.Open()
Dim tblbody As New iTextSharp.text.Table(2)
tblbody.SpaceInsideCell = 1
tblbody.WidthPercentage = 100
tblbody.Border = 0
for i as integer=0 to 150
Dim cell = New Cell(New Phrase(i, New Font(Font.TIMES_ROMAN, 12, "" & CellStyle & "", iTextSharp.text.Color.BLACK)))
cell.Colspan = Span
cell.Border = CellBorder
cell.HorizontalAlignment = CellAlign
cell.VerticalAlignment = iTextSharp.text.Rectangle.ALIGN_MIDDLE
tblbody.AddCell(cell)
next
document.NewPage()
for i as integer=0 to 150
Dim cell = New Cell(New Phrase(i, New Font(Font.TIMES_ROMAN, 12, "" & CellStyle & "", iTextSharp.text.Color.BLACK)))
cell.Colspan = Span
cell.Border = CellBorder
cell.HorizontalAlignment = CellAlign
cell.VerticalAlignment = iTextSharp.text.Rectangle.ALIGN_MIDDLE
tblbody.AddCell(cell)
next
document.close()
I also ran into the same issue these days. The reason why it has a blank page might be one cell that crosses too many lines and it cannot fit a cell on one page and not split it into two pages (when CellsFitPage = true
). Thus, installation CellsFitPage = false
can fix this problem. But what if we want to CellsFitPage = true
? Then we may need to create many small cells and set their border to 0, which makes them look like one long cell, and the page can split them (split many cells into different pages, rather than split one long cell).
source to share