我有一个问题,我有一个可能超出页面长度的表格 (PdfPTable)。我曾尝试查找如何将表格“拆分”到多个页面上,但 iTextSharp 在这方面的文档记录很差。有谁知道如何做到这一点而不选择页面上的任意 Y 位置并告诉它是否存在拆分?
我查看了SplitLate
andSplitRows
属性,但没有关于这些功能的文档。编辑他们什么都不做。
谢谢!
编辑
我希望将表格横向切成两半,因为表格将始终适合页面的宽度。这就是说我希望垂直不适合的行扩展到它下面的下一页。
编辑2
这是一些代码:
Public Sub BuildPrintableDocument
Dim doc As New Document(PageSize.LETTER, 0, 0, 0, BOTTOM_MARGIN)
Dim writer As PdfWriter = PdfWriter.GetInstance(doc, _
New FileStream("invoice.pdf", FileMode.Create)
Dim footer As New HeaderFooter(New Phrase("www.columbussupply.com", _
footerFont), False)
footer.Border = Rectangle.NO_BORDER
footer.Alignment = HeaderFooter.ALIGN_CENTER
doc.Footer = footer
doc.Open()
....
Dim items As PdfPTable = NewItemTable()
Dim count As Integer = 0
For Each oi As OrderItem In TheInvoice.Items
If oi.Status <> OrderItem.OrderItemStatus.Cancelled Then
Dim qty As New PdfPCell(New Phrase(oi.Quantity, mainFont))
qty.HorizontalAlignment = Element.ALIGN_CENTER
qty.Padding = ITEMS_PADDING
'...instantiate 3 other cells here (removed for repetitiveness)'
items.AddCell(qty)
items.AddCell(desc)
items.AddCell(price)
items.AddCell(total)
End If
Next
items.WriteSelectedRows(0, -1, LEFT_MARGIN, GetItemsStartY, _
writer.DirectContent)
End Sub
Protected Function NewItemTable() As PdfPTable
Dim items As PdfPTable = New PdfPTable(4)
Dim headers() As String = {"QTY", "DESCRIPTION", "PRICE", "TOTAL"}
For Each s As String In headers
Dim cell As New PdfPCell(New Phrase(s, mainFont))
cell.HorizontalAlignment = Element.ALIGN_CENTER
items.AddCell(cell)
Next
items.TotalWidth = ITEMS_TOTAL_WIDTH
items.SetWidths(New Single() {QTY_COL_WIDTH, DESC_COL_WIDTH, _
PRICE_COL_WIDTH, TOTALS_COL_WIDTH})
Return items
End Function