Here is a quick code to get a list of fonts used within the PowerPoint using Open XML SDK 2.5. This code works only when the fonts are explicitly set for any elements. Fonts set within the Slide Master or Slide Layout cannot be extracted using the code below but you need to have a complex algorithm to find which fonts will be applied based on the Slide Master and Slide Layout. The following code snippet is just a starting point.
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Presentation;
using A = DocumentFormat.OpenXml.Drawing;
using (PresentationDocument presentationDocument = PresentationDocument.Open("C:\\temp\\mypresentation.pptx", false))
{
PresentationPart presentationPart = presentationDocument.PresentationPart;
Presentation presentation = presentationPart.Presentation;
foreach (var slideId in presentation.SlideIdList.Elements<SlideId>())
{
SlidePart slidePart = presentationPart.GetPartById(slideId.RelationshipId) as SlidePart;
foreach (A.LatinFont font in slidePart.Slide.Descendants<A.LatinFont>())
{
// font.Typeface.Value contains the font name
}
}
}
Leave a Reply