我有一個代碼,它在Visual Studio(它可能是vb或c#)中使用itextsharp在表內寫入一個三角形字符。 爲此,我使用了包含它的threbuchet字體。它工作正常,但我想將三角形塗成紅色。當試圖使用iTextSharp.text.FontFactory.GetFont
(我認爲這很好得到顏色)時,沒有任何符號被寫入pdf。如何使用itextsharp在vb,c中對utf char字體進行着色#
是否有其他方法可以在New iTextSharp.text.Font(bf, 8)
內對字體進行着色?
這是代碼
' table
Dim nTbl As PdfPTable = New PdfPTable(2)
nTbl.HorizontalAlignment = PdfContentByte.ALIGN_CENTER
nTbl.SetTotalWidth({40, 60})
' this works and adds the triangle char
Dim FONT As String = "fonts\trebucbd.ttf"
Dim bf As BaseFont = BaseFont.CreateFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)
Cell = New PdfPCell(New Phrase("Δ", New iTextSharp.text.Font(bf, 8)))
Cell.HorizontalAlignment = 1
Cell.VerticalAlignment = 1
nTbl.AddCell(Cell)
' this does not work, when trying to colour triangle
Cell = New PdfPCell(New Phrase("Δ", iTextSharp.text.FontFactory.GetFont("fonts\trebucbd.ttf", 8, iTextSharp.text.Font.NORMAL, New iTextSharp.text.Color(128, 0, 0))))
Cell.HorizontalAlignment = 1
Cell.VerticalAlignment = 1
nTbl.AddCell(Cell)
我有「字體」文件夾trebuchet字體我需要告訴它在哪裏? – cMinor
iText不會自動尋找字體,你必須告訴它在哪裏看。或者,您也可以使用'FontFactory.RegisterDirectory()'註冊整個文件夾。根據該文件夾中的字體數量,這可能會減慢程序速度。 –