Spire.PDF 支持替换PDF文档中使用的字体。下面的部分展示了如何使用Spire.PDF将现有PDF文档中使用的所有字体替换成另一种字体。
C#
//加载 Pdf 文档
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(PDF file);
//用 UsedFonts 属性获取文档中使用的所有字体
PdfUsedFont[] fonts = doc.UsedFonts;
//创建一个新的字体
PdfFont newfont = new PdfFont(PdfFontFamily.TimesRoman, 18f, PdfFontStyle.Italic | PdfFontStyle.Bold);
//遍历文档中使用的字体,替换成创建的新字体
foreach (PdfUsedFont font in fonts)
{
font.Replace(newfont);
}
//保存文档
doc.SaveToFile(Result file);
VB.NET
'加载 Pdf 文档 Dim doc As PdfDocument = New PdfDocument doc.LoadFromFile("test.pdf ") '用 UsedFonts 属性获取文档中使用的所有字体
Dim fonts() As PdfUsedFont = doc.UsedFonts
'创建一个新的字体 Dim newfont As PdfFont = New PdfFont(PdfFontFamily.TimesRoman,18!,(PdfFontStyle.Italic Or PdfFontStyle.Bold)) '遍历文档中使用的字体,替换成创建的新字体
For Each font As PdfUsedFont In fonts
font.Replace(newfont)
Next
'保存文档 doc.SaveToFile(Result,file)
替换字体前截图:
替换字体后截图: