【发布时间】:2010-11-24 18:23:46
【问题描述】:
我有一个问题,我的表格 (PdfPTable) 可能会超出页面的长度。我曾尝试查找如何将表格“拆分”到多个页面上,但 iTextSharp 在这方面的文档记录很差。有谁知道如何做到这一点,而无需在页面上选择任意 Y 位置并告诉它是否存在拆分?
我查看了SplitLate 和SplitRows 属性,但没有关于它们的作用的文档。 编辑他们什么都不做。
谢谢!
编辑
我希望将表格横向切成两半,因为表格将始终适合页面的宽度。这就是说我希望垂直不适合的行扩展到它下面的下一页。
EDIT2
这里有一些代码:
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
【问题讨论】:
标签: split itextsharp page-break pdfptable