October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Extract Text and Images from PowerPoint Using C#

A practical C# guide to extracting paragraph text and embedded image files from every slide in an Open XML PowerPoint presentation.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a .pptx file, the Open XML SDK lets C# read slide text and embedded image files directly from the presentation package. Add the DocumentFormat.OpenXml NuGet package, open the file read-only, follow the presentation’s slide relationships in order, and then extract text runs or image parts from each slide. This workflow applies to Open XML presentations, not legacy binary .ppt files.

How the extraction works

A .pptx is a ZIP-based Open XML package containing related parts. The presentation part identifies slides through relationships, and each slide has its own part. That means reliable extraction follows the presentation’s slide ID list rather than guessing order from slide-part filenames. See Microsoft’s Open XML package overview and guide to working with presentation slides.

As an Amazon Associate I earn from qualifying purchases.

The Open XML SDK provides strongly typed classes for package parts and elements. Install the DocumentFormat.OpenXml NuGet package in the project, then use the namespaces shown below. Microsoft’s getting-started guide describes the package and general target guidance; check API details against the SDK version selected for your project.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Extract text from every slide

Use the slide ID list to preserve presentation order. For each slide ID, resolve its relationship through the presentation part, cast the related part to SlidePart, and collect DrawingML text. Joining text runs within each paragraph retains useful paragraph boundaries instead of flattening the entire deck immediately.

using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Presentation;
using A = DocumentFormat.OpenXml.Drawing;

static IEnumerable<(int SlideNumber, string[] Paragraphs)> ExtractSlideText(string filePath)
{
    using var document = PresentationDocument.Open(filePath, false);
    var presentationPart = document.PresentationPart;
    var slideIds = presentationPart?.Presentation?.SlideIdList?.Elements<SlideId>();

    if (presentationPart is null || slideIds is null)
        yield break;

    var slideNumber = 0;
    foreach (var slideId in slideIds)
    {
        slideNumber++;
        var relationshipId = slideId.RelationshipId?.Value;
        if (string.IsNullOrEmpty(relationshipId))
            continue;

        if (presentationPart.GetPartById(relationshipId) is not SlidePart slidePart)
            continue;

        var paragraphs = slidePart.Slide
            .Descendants<A.Paragraph>()
            .Select(p => string.Concat(p.Descendants<A.Text>().Select(t => t.Text)))
            .Where(text => !string.IsNullOrEmpty(text))
            .ToArray();

        yield return (slideNumber, paragraphs);
    }
}

The caller can write each returned paragraph as a separate line, store it with its slide number, or join the paragraphs for search. Paragraph-preserving output is easier to read; a single flat string may be more convenient for indexing but discards grouping. Microsoft’s single-slide text example uses the same relationship and paragraph/text traversal approach, and its all-slides example demonstrates traversing the slide list.

The sample opens the document with PresentationDocument.Open(filePath, false) for read-only access and disposes it with using. In Open XML SDK 3.0.0 and later, Microsoft says Close() was removed in favor of disposing the document; avoid adding an outdated explicit close call.

Save embedded images from slides

Images are separate package parts. A picture in slide markup references an image part by relationship ID. To retain which slide and picture each file came from, walk picture markup, read its embedded relationship ID, resolve that ID against the slide part, and copy the related image part’s stream to a file. This relationship-based method is more informative than dumping every image part without recording its picture reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Presentation;
using A = DocumentFormat.OpenXml.Drawing;
using P = DocumentFormat.OpenXml.Presentation;

static void ExportSlideImages(SlidePart slidePart, int slideNumber, string outputDirectory)
{
    Directory.CreateDirectory(outputDirectory);
    var imageNumber = 0;

    foreach (var picture in slidePart.Slide.Descendants<P.Picture>())
    {
        var relationshipId = picture.BlipFill?.Blip?.Embed?.Value;
        if (string.IsNullOrEmpty(relationshipId) ||
            slidePart.GetPartById(relationshipId) is not ImagePart imagePart)
            continue;

        imageNumber++;
        var extension = imagePart.ContentType switch
        {
            "image/png" => ".png",
            "image/jpeg" => ".jpg",
            "image/gif" => ".gif",
            "image/bmp" => ".bmp",
            "image/tiff" => ".tif",
            _ => ".bin"
        };
        var filePath = Path.Combine(outputDirectory,
            $"slide-{slideNumber}-image-{imageNumber}{extension}");

        using var input = imagePart.GetStream();
        using var output = File.Create(filePath);
        input.CopyTo(output);
    }
}

Call ExportSlideImages for each SlidePart as you traverse the presentation’s slide ID list. The example exports image relationships encountered in slide picture markup and gives each output a slide and image number. The filename extension is selected from the content type for common formats; unfamiliar types use .bin, so inspect the part’s content type if your downstream workflow needs a format-specific extension. Microsoft documents SlidePart.ImageParts as an enumerable collection of related ImagePart objects in the SDK 3.0.1 API reference. The stream-copy step here is implementation guidance: the API page establishes the collection, not a complete export routine.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What this method does—and does not—extract

  • Text nodes: The traversal returns DrawingML text descendants on the slides. It does not run OCR on words baked into a screenshot or other raster image.
  • Embedded image files: Extracted image parts are original media assets, not snapshots of how they appear after cropping, rotation, layering, or other slide formatting.
  • Full slide appearance: Reading slide text and image parts does not render the whole composition. The cited SDK documentation supports structured access to package parts, not a guarantee that every displayed feature—such as charts, SmartArt, linked images, or inherited/shared picture content—is fully represented by this extraction.

For a legacy .ppt binary presentation, this Open XML workflow is not established by the cited documentation; use a method specifically documented for that format rather than treating it as a renamed .pptx.

Best Value
Sale
Wireless Presenter, Hyperlink Volume Control Presentation Clicker RF 2.4GHz USB PowerPoint Clicker Presentation Remote Control Pointer Slide Advancer (Black)
  • 【PLUG & PLAY】 The clicker pointer for presentations is easy to use, just plug the usb receiver and it is ready to go, no need to download any software. (The USB fits into the bottom of the clicker. )
  • 【PRESENTATION CLICKER FEATURE】Presentation remote supports various functions:Page Forward/ Backward, Volume Control, Hyperlink, Switch Windows, Full/Black Screen.It is an efficient presentation tool for daily presentations
  • 【BRIGHT RED POINTER & 100FT LONG WIRELESS RANGE】 Powerpoint presentation clicker with bright red light that is easy to see against most backgrounds ((Not Recommended for LCD/LED/TV Screens);Wireless range of powerpoint presenter up to 100 foot, free to move around even in a large room
  • 【WITH SUPERIOR DETAILS】 ①One-piece magnetic usb storage, not easy to lose the usb ②Soft and rubber buttons ③Compact design & Space save and comfortable grip ④ Bumped-buttons design for easy slideshow control.⑤Operated by 1xAAA battery(Not included), with energy-saving auto-sleep function, one battery can be used for weeks

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.