我只是做了以下,它的工作原理应该如此。 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