使用Aspose.PDF .NET 10.4、C#、.NET 4.5
我的应用程序的资源文件夹中有一个.TTF字体文件。它没有安装在系统中,我也不希望这样做。如何在文档中嵌入和使用字体?
发布于 2015-05-23 00:04:26
谢天谢地有ILSpy。我在Aspose.PDF动态链接库中搜索“字体”,最终找到了它。下面是完整的命名空间,这样你就知道从哪里获取方法和对象了。
//create the font from a ttf file
Aspose.Pdf.Text.Font myFont =
Aspose.Pdf.Text.FontRepository.OpenFont("C:\temp\MyFont-Regular.ttf");
myFont.IsEmbedded = true;
//new doc, add a new blank page
Document doc = new Document();
Page page = doc.Pages.Add();
//use the font in a style
TextState style = new TextState();
style.Font = myFont;
style.FontSize = 12;
style.FontStyle = FontStyles.Regular;
style.LineSpacing = 4;
TextFragment frag = new TextFragment(sb.ToString());
frag.TextState.ApplyChangesFrom(style);
frag.IsInLineParagraph = true;
page.Paragraphs.Add(frag);
//save it
doc.Save("C:\temp\fontTest.pdf");https://stackoverflow.com/questions/30399932
复制相似问题