Extract Images from PDF via C#

Extract images from PDF document. Use Aspose.PDF for .NET to modify PDF files programmatically

Extract Images from PDF Document Using C# Library

In order to add Image in PDF, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for net platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF

Extract Image from PDF via C#


You need Aspose.PDF for .NET library to try the code in your environment.

  1. Open PDF document.
  2. Extract a particular image.
  3. Save output image.
  4. Save updated PDF file.

Extract Images from PDF File - C#

This sample code shows how to extract Images from PDF - C#


// Open document
Document pdfDocument = new Document(dataDir+ "ExtractImages.pdf");

// Extract a particular image
XImage xImage = pdfDocument.Pages[1].Resources.Images[1];

FileStream outputImage = new FileStream(dataDir + "output.jpg", FileMode.Create);

// Save output image
xImage.Save(outputImage, ImageFormat.Jpeg);
outputImage.Close();

dataDir = dataDir + "ExtractImages_out.pdf";

// Save updated PDF file
pdfDocument.Save(dataDir);