ItextSHARP表拆分问题

2 split itext

我使用itextsharp创建了一个示例项目.在那里我提到了页脚和一个表,我按循环为给定的数字生成行,如果表拆分到另一页然后,我有一个没有给定数据的空白页.它似乎未定义.

这是代码:

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()
Run Code Online (Sandbox Code Playgroud)

小智 5

将此设置设置为您的表格:

tblbody.SplitLate = false; tblbody.SplitRows = true;