PDFOne .NET如何为PDF文件嵌入和替换字体

作者:控件中国网   出处:控件中国网   2015-08-12 10:21:11   阅读:7

PDFOne .NET为开发人员提供了字体嵌入和替换的方法,为PDF嵌入字体首先得创建一个PDF字体对象,然后使用PDFDocument.EmbedFont(PDFFont fontToBeEmbedded)方法把字体嵌入到PDF里,具体代码如下:

PDFDocument doc = new PDFDocument();
doc.Load("DocWithoutEmbeddedFont.pdf");
Font fnt = new Font("Garamond", 24);
PDFFont pfnt = new PDFFont(fnt, PDFFontEmbedType.Full);
doc.EmbedFont(pfnt);
doc.OpenAfterCreate = true;
doc.Save("DocWithEmbeddedFont.pdf");
doc.Close();

当替换一种字体时,需要创建一个PDF字体对象,并设置 PDFFontEmbedType.Full,然后使用 PDFDocument.EmbedFont(PDFFont

fontToBeEmbedded, string originalFont) 进行替换,具体代码如下:
PDFDocument doc = new PDFDocument();
doc.Load("DocWithoutEmbeddedFont.pdf");
Font wf = new Font("Segoe UI", 24);
PDFFont pf = new PDFFont(wf, PDFFontEmbedType.Full);
doc.EmbedFont(pf, "Garamond");
doc.OpenAfterCreate = true;
doc.Save("DocWithReplacedFont.pdf");
doc.Close();

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat