iText for .NET Paragraph Element重叠其自己的文本

时间:2014-11-06 06:18:38

标签: vb.net pdf itext paragraph

我正在动态创建PDF报告,有时内容太长而且(应该)跨越多个页面。我正在使用Paragraph元素,它只是覆盖了它的单元格空间。

Just like here

代码:

'Table SPECS
Dim tab As New PdfPTable(1)
tab.TotalWidth = 502.0F
tab.LockedWidth = True
tab.SpacingBefore = 140.0F

Dim phrase As Phrase = Nothing
Dim cell As New PdfPCell(New Phrase())
phrase = New Phrase() 
phrase.Add(New Chunk(dr("Subject").ToString() & vbLf, font))
cell = PhraseCell(phrase, PdfPCell.ALIGN_RIGHT)
cell.VerticalAlignment = PdfCell.ALIGN_TOP
cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL
cell.HorizontalAlignment = PdfCell.ALIGN_CENTER
cell.PaddingLeft = 5.0F
cell.PaddingBottom = 2.0F
cell.PaddingTop = 0.0F
cell.Border = 0
tab.AddCell(cell)

Dim p As Paragraph = New Paragraph(dr("Contents"), font)
p.SpacingBefore = 140.0F
Dim Col As New ColumnText(writer.DirectContent)
Col.SetSimpleColumn(50, doc.Bottom + 160, 540, doc.Top - 160)
Col.RunDirection = PdfWriter.RUN_DIRECTION_RTL
Col.AddText(p)
cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL
cell.PaddingLeft = 5.0F
cell.PaddingBottom = 2.0F
cell.PaddingTop = 0.0F
cell.Border = 0
Col.Go()
doc.Add(tab)
doc.Close()

如何正确实现?

1 个答案:

答案 0 :(得分:0)

您可以使用itextSharp的SpacingAfter属性来修复问题。 请在此处查看完整代码: http://agalaxycode.blogspot.in/2015/01/paragraph-overlapping-problem-in-itextSharp.html