Get a list of fonts from PowerPoint using Open XML SDK

By | September 14, 2017 | 0 Comment
Category: MS Powerpoint Tags: , ,

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 

About Vishal Monpara

Vishal Monpara is a full stack Solution Developer/Architect with 13 years of experience primarily using Microsoft stack. He is currently working in Retail industry and moving 1's and 0's from geographically dispersed hard disks to geographically dispersed user leveraging geographically dispersed team members.

Leave a Reply

Your email address will not be published. Required fields are marked *