Reputation:
I have created a sample project using itextsharp. In that I have mentioned the Footer and a table, I generate rows by loop for the given number, if the table splits to another page then, I have one blank page which has no given data. It seems 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()
Upvotes: 2
Views: 5853
Reputation: 1
I also encountered same issue these days. The reason why it have a blank page might be there is a single cell that crosses too many rows and it neither can't put the cell in a single page nor split it into two pages(when CellsFitPage = true
). So by setting CellsFitPage = false
can solve that problem. But what if we want CellsFitPage = true
? Then we might need to create many small cells and set their border with to 0, which would make them look like a single long cell and the page can split them (split many cells into different pages rather than split a single long cell).
Upvotes: 0
Reputation: 41
Unforetunately the SplitLate and SPlitRows are only available on the PdfPTable.
You can set the tblbody.TableFitsPage and he CellsFitPage = false;
Posted for others as I spent a lot of time trying to figure this out.
Upvotes: 4
Reputation: 61
Set this settings to your table:
tblbody.SplitLate = false; tblbody.SplitRows = true;
Upvotes: 6