Vb.net 当一行被拆分时,我是否可以使用iTextSharp单元格事件在下一页重复数据?
我在pdfptable中有一个很深的行。此行左侧的列包含一个子表,该子表中有许多行。我想深行分裂成多个页面,如果它太深,无法容纳一页。我可以将SplitLate设置为false,以确保行被拆分。但是,右侧深列的数据仅显示在第一页,我希望在第二页重复 一点调查表明,我可以使用单元格事件将文本放入单元格,并在第二页上重复。因此,我创建了一个单元格事件,如下所示:Vb.net 当一行被拆分时,我是否可以使用iTextSharp单元格事件在下一页重复数据?,vb.net,events,pdf-generation,itextsharp,Vb.net,Events,Pdf Generation,Itextsharp,我在pdfptable中有一个很深的行。此行左侧的列包含一个子表,该子表中有许多行。我想深行分裂成多个页面,如果它太深,无法容纳一页。我可以将SplitLate设置为false,以确保行被拆分。但是,右侧深列的数据仅显示在第一页,我希望在第二页重复 一点调查表明,我可以使用单元格事件将文本放入单元格,并在第二页上重复。因此,我创建了一个单元格事件,如下所示: Public Class PdfPCellEvent Implements iTextSharp.text.pdf.IPdfPCellEv
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
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)
phrase = New text.Phrase("Text", fontSmaller)
Dim cell As PdfPCell = New PdfPCell()
Dim cellEvent As New PdfPCellEvent(phrase)
cell.CellEvent = cellEvent
mainTable.AddCell(cell)
document.Add(mainTable)
我将其称为:
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
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)
phrase = New text.Phrase("Text", fontSmaller)
Dim cell As PdfPCell = New PdfPCell()
Dim cellEvent As New PdfPCellEvent(phrase)
cell.CellEvent = cellEvent
mainTable.AddCell(cell)
document.Add(mainTable)
这一切都在运行。我可以看到,在将mainTable添加到文档后,cell事件被调用了两次。我假定该行出现在每个页面上都会调用一次。我还可以看到正确的文本被传递到CellLayout中。但是,生成的pdf中不会显示任何文本。我做错了什么?我尝试了各种在CellLayout中添加文本的方法,但都没有成功。此代码段中缺少一些内容:
Dim cb As PdfContentByte = canvases(PdfPTable.TEXTCANVAS)
cb.BeginText()
cb.SetFontAndSize(m_font, 8)
cb.ShowText(m_text)
cb.EndText()
您正在创建文本块,但忘记指定坐标。我怀疑BT
/ET
序列被添加到了内容流中,但无法判断文本将显示在页面的哪个位置
在单元格布局中,您可以访问
定位为text.Rectangle
。您可以询问位置
变量以获取坐标。您可以在关于的代码段中使用这些坐标(使用SetTextMatrix()
方法),但如果不使用cb.BeginText()、cb.SetFontAndSize()、cb.SetTextMatrix()、cb.ShowText()、cb.EndText()
,则会更容易。改用ColumnText.ShowTextAligned()
。您可以将cb
实例作为参数传递,同时传递短语、对齐方式(左、右、中)、X、Y坐标和角度。此代码段中缺少一些内容:
Dim cb As PdfContentByte = canvases(PdfPTable.TEXTCANVAS)
cb.BeginText()
cb.SetFontAndSize(m_font, 8)
cb.ShowText(m_text)
cb.EndText()
您正在创建文本块,但忘记指定坐标。我怀疑BT
/ET
序列被添加到了内容流中,但无法判断文本将显示在页面的哪个位置
在单元格布局中,您可以访问定位为text.Rectangle
。您可以询问位置
变量以获取坐标。您可以在关于的代码段中使用这些坐标(使用SetTextMatrix()
方法),但如果不使用cb.BeginText()、cb.SetFontAndSize()、cb.SetTextMatrix()、cb.ShowText()、cb.EndText()
,则会更容易。改用ColumnText.ShowTextAligned()
。您可以将cb
实例作为参数传递,同时传递短语、对齐方式(左、右、中)、X、Y坐标和角度。此代码段中缺少一些内容:
Dim cb As PdfContentByte = canvases(PdfPTable.TEXTCANVAS)
cb.BeginText()
cb.SetFontAndSize(m_font, 8)
cb.ShowText(m_text)
cb.EndText()
您正在创建文本块,但忘记指定坐标。我怀疑BT
/ET
序列被添加到了内容流中,但无法判断文本将显示在页面的哪个位置
在单元格布局中,您可以访问定位为text.Rectangle
。您可以询问位置
变量以获取坐标。您可以在关于的代码段中使用这些坐标(使用SetTextMatrix()
方法),但如果不使用cb.BeginText()、cb.SetFontAndSize()、cb.SetTextMatrix()、cb.ShowText()、cb.EndText()
,则会更容易。改用ColumnText.ShowTextAligned()
。您可以将cb
实例作为参数传递,同时传递短语、对齐方式(左、右、中)、X、Y坐标和角度。此代码段中缺少一些内容:
Dim cb As PdfContentByte = canvases(PdfPTable.TEXTCANVAS)
cb.BeginText()
cb.SetFontAndSize(m_font, 8)
cb.ShowText(m_text)
cb.EndText()
您正在创建文本块,但忘记指定坐标。我怀疑BT
/ET
序列被添加到了内容流中,但无法判断文本将显示在页面的哪个位置
在单元格布局中,您可以访问定位为text.Rectangle
。您可以询问位置
变量以获取坐标。您可以在关于的代码段中使用这些坐标(使用SetTextMatrix()
方法),但如果不使用cb.BeginText()、cb.SetFontAndSize()、cb.SetTextMatrix()、cb.ShowText()、cb.EndText()
,则会更容易。改用ColumnText.ShowTextAligned()
。您可以将cb
实例作为参数传递,同时传递短语、对齐(左、右、中)、X、Y坐标和角度。谢谢,以下功能现在可以完美地工作:
Public Class PdfPCellEvent
Implements iTextSharp.text.pdf.IPdfPCellEvent
Private m_phrase As text.Phrase
Public Sub New(ByVal phrase As text.Phrase)
MyBase.New()
m_phrase = phrase
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)
Dim CenterX As Single = position.GetLeft(0) + (position.Width() / 2)
Dim CenterY As Single = position.GetBottom(0) + (position.Height() / 2)
ColumnText.ShowTextAligned(cb, text.Element.ALIGN_CENTER, m_phrase, CenterX, CenterY, 0)
End Sub
End Class
我称之为:
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
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)
phrase = New text.Phrase("Text", fontSmaller)
Dim cell As PdfPCell = New PdfPCell()
Dim cellEvent As New PdfPCellEvent(phrase)
cell.CellEvent = cellEvent
mainTable.AddCell(cell)
document.Add(mainTable)
文本现在显示在两页上,并在单元格中垂直和水平居中。谢谢,以下内容现在可以完美地工作:
Public Class PdfPCellEvent
Implements iTextSharp.text.pdf.IPdfPCellEvent
Private m_phrase As text.Phrase
Public Sub New(ByVal phrase As text.Phrase)
MyBase.New()
m_phrase = phrase
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)
Dim CenterX As Single = position.GetLeft(0) + (position.Width() / 2)
Dim CenterY As Single = position.GetBottom(0) + (position.Height() / 2)
ColumnText.ShowTextAligned(cb, text.Element.ALIGN_CENTER, m_phrase, CenterX, CenterY, 0)
End Sub
End Class
我称之为:
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
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)
phrase = New text.Phrase("Text", fontSmaller)
Dim cell As PdfPCell = New PdfPCell()
Dim cellEvent As New PdfPCellEvent(phrase)
cell.CellEvent = cellEvent
mainTable.AddCell(cell)
document.Add(mainTable)
文本现在显示在两页上,并在单元格中垂直和水平居中。谢谢,以下内容现在可以完美地工作:
Public Class PdfPCellEvent
Implements iTextSharp.text.pdf.IPdfPCellEvent
Private m_phrase As text.Phrase
Public Sub New(ByVal phrase As text.Phrase)
MyBase.New()
m_phrase = phrase
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)
Dim CenterX As Single = position.GetLeft(0) + (position.Width() / 2)
Dim CenterY As Single = position.GetBottom(0) + (position.Height() / 2)
ColumnText.ShowTextAligned(cb, text.Element.ALIGN_CENTER, m_phrase, CenterX, CenterY, 0)
End Sub
End Class
我称之为:
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
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)
phrase = New text.Phrase("Text", fontSmaller)
Dim cell As PdfPCell = New PdfPCell()
Dim cellEvent As New PdfPCellEvent(phrase)
cell.CellEvent = cellEvent
mainTable.AddCell(cell)
document.Add(mainTable)
文本现在显示在两页上,并在单元格中垂直和水平居中。谢谢,以下内容现在可以完美地工作:
Public Class PdfPCellEvent
Implements iTextSharp.text.pdf.IPdfPCellEvent
Private m_phrase As text.Phrase
Public Sub New(ByVal phrase As text.Phrase)
MyBase.New()
m_phrase = phrase
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)
Dim CenterX As Single = position.GetLeft(0) + (position.Width() / 2)
Dim CenterY As Single = position.GetBottom(0) + (position.Height() / 2)
ColumnText.ShowTextAligned(cb, text.Element.ALIGN_CENTER, m_phrase, CenterX, CenterY, 0)
End Sub
End Class
我称之为:
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
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)
phrase = New text.Phrase("Text", fontSmaller)
Dim cell As PdfPCell = New PdfPCell()
Dim cellEvent As New PdfPCellEvent(phrase)
cell.CellEvent = cellEvent
mainTable.AddCell(cell)
document.Add(mainTable)
文本现在显示在两页上,并在单元格中垂直和水平居中。谢谢,我现在已经开始工作,并在下面添加了更正的代码。很好,您用工作代码添加了答案!谢谢,我现在已经开始工作了,并在下面添加了正确的代码。很好,你用工作代码添加了一个答案!谢谢,我现在已经开始工作了,并在下面添加了正确的代码。很好,你用工作代码添加了一个答案!谢谢,我现在已经开始工作了,并在下面添加了正确的代码。太好了