Extract Text from PowerPoint using C#

This short guide describes how to extract text from PowerPoint using C#. It has details to set the IDE, a list of steps, and a sample code for developing a PowerPoint to text converter using C#. You will learn to access various content in the presentation/slides for fetching text from it.

Steps to Convert PowerPoint to Text using C#

  1. Set the environment to use Aspose.Slides for .NET for converting PPTX to TXT
  2. Open the PPTX file into memory using the Presentation Class, using the defined input file path
  3. Call the SlideUtil.GetAllTextFrames() method for extracting all text frames from every slide
  4. Set the flag to extract text frames from the master and layout slides, also
  5. Declare the StringBuilder object for holding the extracted text content
  6. Parse each text frame and access its paragraphs
  7. Loop through each paragraph and append its text portions in new lines in the StringBuilder
  8. Write the final accumulated text in a TXT file on the disk

These steps explain the development of the PPTX to text converter using C#. Load the presentation, get the collection of all the text frames, create a StringBuilder object, and iterate through each frame in the collection. For each frame, access the paragraphs collection, in each paragraph, get the collection of the portions, fetch text from the portion, and append it to the StringBuilder object.

Code to Convert PPTX to TXT using C#

This code demonstrates how to extract text from PPTX using C#. There is another quick way of fetching text from the entire presentation using the PresentationFactory.Instance.The GetPresentationText(inputPath, TextExtractionArrangingMode.Unarranged) method writes each slide’s content to a UTF-8-encoded output file. Four text components will be written for each slide, including the main body text, speaker notes, master slide text, and layout text.

This article has taught us how to extract all text from a presentation. To convert a PowerPoint to MP4 video, refer to the article Convert PowerPoint to Video using C#.