2010-08-02 26 views
0

有沒有辦法將字體分配給添加到ITextsharp中表格單元格的列表。我相信它一定是直截了當的,但我錯過了它。ITextSharp,將字體分配給List中的單元格?

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) 

有誰知道我該如何改變這個,以便列表/單元格具有我在頂部設置的特定字體。

乾杯

回答

5

iTextSharp.text.ListItem對象具有iTextSharp.text.Font屬性你可以設置。

+0

血腥地獄,我直接應用一個字符串到列表而不是使用ListItem,非常感謝 – Israfel 2010-08-03 08:17:52

0

請注意,諸如新PdfPCell或新短語等聲明不會與iTextSharp.text.List的add方法一起使用,但它們都與PdfPTable相當。 我使用了iTextSharp.text.List作爲我的軟件的pdf打印出來的方式之一,我希望這對你也有用。

這是一個用vb.net(visual studio 2010和windows 7平臺)和iTextSharp最新版本開發的軟件之一的程序。用於pdf打印out.It演示如何我們可以manupulate 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() 
相關問題