0

我有一些文字

1   a
    b
    c
    d

使用 iTextSharp 我如何显示这个(在单独的行中,一个接一个)?

我的代码:

Dim pdftableSLD As PdfPTable = New PdfPTable(3)
pdftableSLD.DefaultCell.Padding = 3
pdftableSLD.WidthPercentage = 96
pdftableSLD.DefaultCell.BorderWidth = 1
pdftableSLD.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT
pdftableSLD.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE
pdftableSLD.DefaultCell.FixedHeight = 40.0F
pdftableSLD.HorizontalAlignment = 1
Dim widthsSLD As Single() = {0.5F, 1.25F, 2.5F}
pdftableSLD.SetWidths(widthsSLD)

Dim stuName As PdfPCell = New PdfPCell(FormatPhrase(""))
stuName.Colspan = 4
stuName.Border = Rectangle.BOTTOM_BORDER
stuName.NoWrap = True
stuName.HorizontalAlignment = Element.ALIGN_CENTER
pdftableMain.AddCell(stuName)

在此表中,我必须显示上面指定的文本。

4

1 回答 1

1

您的样本看起来像表格,因此可能需要一张表格。想到了两条PdfPTable路径以及一条使用路径Paragraph

选项 1 - 创建一个普通的 2x4 表

''//Create a two column table divided 20%/80%
Dim tbl1 As PdfPTable = New PdfPTable({20, 80})

''//Add cells
tbl1.AddCell("1")
tbl1.AddCell("a")

tbl1.AddCell("")
tbl1.AddCell("b")

tbl1.AddCell("")
tbl1.AddCell("c")

doc.Add(tbl1)

选项 2 - 创建一个 2x4 表,第一个单元格跨越 4 行

''//Create a two column table divided 20%/80%
Dim tbl2 As PdfPTable = New PdfPTable({20, 80})

''//Add a cell that spans four rows
tbl2.AddCell(New PdfPCell(New Phrase("1")) With {.Rowspan = 4})

''//Add cels normally
tbl2.AddCell("a")
tbl2.AddCell("b")
tbl2.AddCell("c")

doc.Add(tbl2)

选项 3 - 使用带有制表位的段落

''//Create a normal paragraph
Dim P As New Paragraph()

''//Add first "column"
P.Add("1")

''//Add a tab
P.Add(Chunk.TABBING)

''//Add second "column"
P.Add("a")

''//Soft return
P.Add(vbNewLine)

''//Repeat, starting subsequent items with a tab
P.Add(Chunk.TABBING)
P.Add("b")
P.Add(vbNewLine)

P.Add(Chunk.TABBING)
P.Add("c")
P.Add(vbNewLine)

doc.Add(P)
于 2013-10-30T13:15:41.687 回答