We are replacing existing font with new fond & removing unused font in pdf file. Using below code for this. It is working as expected if the pdf file has single page. Getting invalid font name exception when the pdf has 2 pages. We are using 24.5.1 version with proper license.
var pdf = new Document(pdfStreamIN);
TextFragmentAbsorber absorber = new TextFragmentAbsorber(new TextEditOptions(TextEditOptions.FontReplace.RemoveUnusedFonts));
absorber.TextSearchOptions.IgnoreResourceFontErrors = true;
pdf.Pages.Accept(absorber);
// Iterate through all the TextFragments
foreach (TextFragment textFragment in absorber.TextFragments)
{
// If the font name is ArialMT, replace font name with Arial
if (textFragment.TextState.Font.FontName == “Helvetica-Bold”)
{
textFragment.TextState.Font = FontRepository.FindFont(“ArialMT,Bold”);
}
if (textFragment.TextState.Font.FontName == "Helvetica")
{
textFragment.TextState.Font = FontRepository.FindFont("ArialMT");
}
}
pdf.Save(pdfStreamOUT, SaveFormat.Pdf);