ITextSharp,在单元格中为List分配字体?

时间:2010-08-02 15:44:07

标签: itextsharp

有没有办法将字体分配给添加到ITextsharp中的表格单元格的列表。我确信它一定要直截了当,但我很想念它。

Dim tblSignature As New PdfPTable(1)
        tblSignature.WidthPercentage = 90.0F

        Dim _baseFont As BaseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED)

        Dim _bFont As New Font(_baseFont, 4, Font.ITALIC, Color.RED)

        Dim cell As New PdfPCell(New Phrase(TheItem.Value, _bFont))

        TheParagraph.Font = _bFont


        Dim list As New List(list.UNORDERED, 25.0F)
        list.SetListSymbol("[  ]")


        If ListItems.Count > 0 Then
            For Each ListItem In .ListItems
                //I have tried adding as chunk/phrase and applying font but no joy
                //Item not added to cell
                //list.Add(New Chunk(ListItem, _bFont))

                list.Add(ListItem)
            Next

            list.IndentationLeft = 5.0F

            cell.AddElement(list)
        End If

        cell.Colspan = 6
        cell.HorizontalAlignment = 0
        cell.PaddingBottom = 5.0F
        cell.PaddingLeft = 5.0F
        cell.PaddingRight = 5.0F

        '' add to doc
        tblSignature.AddCell(cell)

        TheParagraph.Add(tblSignature)

有谁知道我如何更改此内容,以便列表/单元格具有我在顶部设置的特定字体。

干杯

2 个答案:

答案 0 :(得分:5)

iTextSharp.text.ListItem对象具有您可以设置的iTextSharp.text.Font属性。

答案 1 :(得分:0)

请注意,新的PdfPCell或新词组等声明不适用于iTextSharp.text.List的add方法。但它们都适用于PdfPTable。 我用以下方式将iTextSharp.text.List用于我的软件pdf打印。我希望这对你也有用。

这是一个程序,用于我用vb.net(visual studio 2010和windows 7平台)和iTextSharp最新版本开发的软件之一。  for pdf print out.It演示了如何使用iTextSharp.text.List的字体属性。

 Dim doc1 As New Document()

        Dim pathpdf As String = "C:/temp"

        'path = ServerMapPath("PDFs");
        PdfWriter.GetInstance(doc1, New FileStream(pathpdf + "/Doc1.pdf", FileMode.Create))
        ' Now to begin actually working with the document, open it, , add a new list,and, then close it:

        doc1.Open()


Dim fnt1 As Font = FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Font.NORMAL)


Dim fnt2 As Font = FontFactory.GetFont(FontFactory.HELVETICA, 14, iTextSharp.text.Font.BOLD)


Dim fnt3 As Font = FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.NORMAL)


Dim lst3 As New iTextSharp.text.List()


lst3.SetListSymbol("")


'add a list item in bold letters.

Dim m_DataHeadOnly As String

m_DataHeadOnly = "This is the itextsharp font setting with list"

lst3.Add(New iTextSharp.text.ListItem(m_DataHeadOnly, fnt2))


doc1.add(lst3)

doc1.close()