I have a very deep row in a pdfptable. The columns in the left-hand side of this row contain a sub table which has many rows within it. I would like the deep row to split onto more than one page if it is too deep to fit on one page. I can set SplitLate to false to ensure that the row splits. However, the data for the deep columns on the right hand side only shows on the first page and I would like it to be repeated on the second page.
A bit of investigation suggested that I could use a cell event to put the text into the cells and have it repeated on the second page. So I created a cell event as follows:
Public Class PdfPCellEvent
Implements iTextSharp.text.pdf.IPdfPCellEvent
Private m_text As String
Private m_font As text.pdf.BaseFont
Public Sub New(ByVal text As String, font As text.pdf.BaseFont)
MyBase.New()
m_text = text
m_font = font
End Sub
Public Sub CellLayout(cell As PdfPCell, position As text.Rectangle, canvases() As PdfContentByte) Implements IPdfPCellEvent.CellLayout
Dim cb As PdfContentByte = canvases(PdfPTable.TEXTCANVAS)
cb.BeginText()
cb.SetFontAndSize(m_font, 8)
cb.ShowText(m_text)
cb.EndText()
End Sub
End Class
I then call this as follows:
Dim cell As PdfPCell = New PdfPCell()
Dim bfReport As BaseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, False)
Dim cellEvent As New PdfPCellEvent("Text", bfReport)
cell.CellEvent = cellEvent
mainTable.AddCell(cell)
document.Add(mainTable)
This all runs. I can see that the cell event is being called twice after the mainTable is added to the document. I presume it is being called once for each page the row appears on. I can also see that the correct text is being passed into CellLayout. However no text appears in the resulting pdf. What am I doing wrong? I have tried various ways of adding the text in CellLayout but none have worked.