Hi!
I have a .pptx file with custom fonts. I want no make all used fonts as embedded programmatically. These fonts are not installed on my machine and I haven’t any details about it (names, etc.)
So I want to do the same thing like this option in the PowerPoint on my screenshot
image.png (29.4 KB)
I’ve even found the code which probably should do that:
private static void EmbedFonts(Presentation presentation)
{
var allFonts = presentation.FontsManager.GetFonts().ToList();
var embeddedFonts = presentation.FontsManager.GetEmbeddedFonts().ToList();
foreach (var font in allFonts)
{
if (embeddedFonts.All(x => x.FontName != font.FontName))
{
embeddedFonts.Add(font);
try
{
presentation.FontsManager.AddEmbeddedFont(font, EmbedFontCharacters.OnlyUsed);
}
catch (Exception)
{
Console.WriteLine($"Font is not found: {font.FontName}");
}
}
}
}
However, if some font in this cycle is not installed on my machine I’ve get the InvalidOperationException with text “font is not found” from FontsManager.AddEmbeddedFont(…)
So it looks like FontsManager.AddEmbeddedFont <-- doesn’t work if a font is not installed locally. Is it correct? For me it’s the key point because I don’t know any information about my custom fonts and I’m not be able to download/install it. I want to take these fonts from presentation itself like PowerPoint magically do that and then make it embedded.
PowerPoint do exactly what I need but I wonder to do the same thing programmatically for my clients. Please, provide any information about this feature, thx