【发布时间】:2016-09-30 12:28:16
【问题描述】:
我已经编写了以下代码来在 PDF 中编写文本,我想在一些文本之后换行。
Dim document As Document
document = New Document(PageSize.A4, 5.0F, 20.0F, 20.0F, 20.0F)
Try
Dim writer As PdfWriter
writer = PdfWriter.GetInstance(document, New FileStream(filename, FileMode.Create))
document.Open()
Dim spacing As Integer
spacing = 0
Dim curY, lineHeight As Double
curY = document.Top
lineHeight = 0
Const maxPerLine As Integer = 3
For i As Integer = 0 To 5
Dim table As PdfPTable
table = New PdfPTable(4)
table.DefaultCell.Border = Rectangle.NO_BORDER
table.TotalWidth = 200.0F
table.LockedWidth = True
Dim cell As PdfPCell
cell = New PdfPCell(New Phrase("hello \n" + i + "\n" + "wass up ?" ))
cell.Colspan = 4
cell.HorizontalAlignment = 0
cell.Border = Rectangle.NO_BORDER
cell.Padding = 30.0F
table.AddCell(cell)
table.WriteSelectedRows(0, -1, document.Left + spacing, curY, writer.DirectContent)
spacing = spacing + 200
lineHeight = Math.Max(lineHeight, table.TotalHeight)
If 0 = (i + 1) Mod maxPerLine Then
curY = curY - lineHeight
spacing = 0
lineHeight = 0
End If
Next
Catch ex As Exception
Finally
document.Close()
End Try
我已经尝试过使用段落,但我仍然无法在新行中输入文本。
我已经阅读了他们写的 iTextSharp 的文档,如果你想换行然后使用 "\n" 但它不起作用。
如何在一些文字后换行?
【问题讨论】: