我只是做了以下,它的工作原理應該如此。 Wingdings字體在兩個詞之間顯示爲帶右下投影的方框。唯一的問題是,我實際上無法使Wingdings字體實際嵌入自己,我相信它是一個iTextSharp隱式規則,因爲它假設無處不在。我嘗試了WINGDNG2.TTF
,並且嵌入正確。
你可能沒有正確添加短語?或者你是在沒有Wingdings的機器上打開它?
''//Create a new document
Dim Doc As New iTextSharp.text.Document(PageSize.LETTER, 20, 20, 20, 20)
''//Store the document on the desktop
Dim writer = PdfWriter.GetInstance(Doc, New FileStream(Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "Output.pdf"), FileMode.Create, FileAccess.Write, FileShare.Read))
''//Open the PDF for writing
Doc.Open()
''//Insert a page
Doc.NewPage()
''//Add a regular text block using the default font
Dim Phrase = New Phrase("Hello")
Doc.Add(Phrase)
''//Create our base font
Dim base As BaseFont = BaseFont.CreateFont("C:\Windows\Fonts\wingding.ttf", BaseFont.CP1252, BaseFont.EMBEDDED)
''//Create our usable font
Dim wd As Font = New Font(base, 12, iTextSharp.text.Font.NORMAL, BaseColor.BLACK)
''//Add a text block using Wingdings
Phrase = New Phrase("q", wd)
Doc.Add(Phrase)
''//Add a trailing text block using the default font again
Phrase = New Phrase("Bye")
Doc.Add(Phrase)
''//Close the PDF
Doc.Close()
我建議你特別檢查`base` ...`getFontFamilyName()`和`getPostscriptFontName()`。 `getEncoding()`也不會傷害。確保你得到了你要求的字體。 – 2011-02-18 16:52:18
此外,您正在使用什麼版本的iTextSharp。克里斯的基本相同的代碼工作正常...讓我懷疑配置問題。版本,字體路徑,類似的東西。 – 2011-02-18 16:53:06