Extract Pictures from PowerPoint with C# REST API

This article guides on how to extract pictures from PowerPoint with C# REST API. You will learn to automatically retrieve images on PowerPoint with C# REST Interface using a .NET-based cloud SDK. It will share details to extract all the images or fetch selected images from the presentation.

Prerequisite

Steps to Extract PowerPoint Pics with C# REST API

  1. Initialize the SlidesApi object to extract pictures using the Client ID and secret
  2. Upload the PowerPoint file with images to Aspose cloud storage
  3. Download all the images from the PowerPoint presentation in a ZIP file using the DownloadImagesDefaultFormat() method
  4. Save the ZIP file containing all extracted images to the local storage
  5. Download a single image from the PowerPoint presentation
  6. Save the extracted single image as a PNG file to the local storage

These steps describe how to fetch PowerPoint presentation images with C# .NET-based API. Initialize the SlidesApi object, upload the presentation to the server, download all the images as a ZIP stream from the API response, and save them on the disk. Use the DownloadImageDefaultFormat() method to fetch the desired image only by providing the image index in the presentation.

Code to Extract Pictures in Presentations with C# RESTful Service

// Importing the Aspose.Slides.Cloud.Sdk library to work with PowerPoint files in the cloud
using Aspose.Slides.Cloud.Sdk;
using System.IO; // Importing System.IO for file handling operations
namespace PresentationProcessor
{
class ExtractImages
{
static void Main(string[] args)
{
// Creating an instance of the SlidesApi class using API credentials (API Key and App SID)
var slideService = new SlidesApi("API Key", "SID");
// Defining the name of the input PowerPoint file
string inputFileName = "PresentationWithPics.pptx";
// Uploading the PowerPoint file to Aspose cloud storage
var uploadResult = slideService.UploadFile(inputFileName, new MemoryStream(File.ReadAllBytes(inputFileName)));
// Downloading all images from the PowerPoint presentation in a ZIP file
var stream_zip = slideService.DownloadImagesDefaultFormat(name: "PresentationWithPics.pptx");
// Saving the ZIP file containing all extracted images to the local storage
using (var fileStream = new FileStream("AllImages.zip", FileMode.Create, FileAccess.Write))
{
stream_zip.CopyTo(fileStream); // Copying the downloaded ZIP stream to a file
}
// Downloading a single image (indexed as 1) from the PowerPoint presentation
var singleImage = slideService.DownloadImageDefaultFormat(name: "PresentationWithPics.pptx", index: 1);
// Saving the extracted single image as a PNG file to the local storage
using (var fileStream = new FileStream("singleImage.png", FileMode.Create, FileAccess.Write))
{
singleImage.CopyTo(fileStream); // Copying the image stream to the file
}
}
}
}

This code demonstrates how to extract pictures from PowerPoint with C# Low Code API. The DownloadImagesDefaultFormat() method takes the presentation file name and returns a ZIP stream that is saved on the local storage. All the files in the ZIP file contain the default image type.

This article has taught us the extraction of PowerPoint slides images with C# REST Interface. To add a watermark in a presentation, refer to the article Add watermark to PPT with C# REST API.

 English