Extract Images from PDF using C#

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

Extract Images from PDF Document Using C# Tool

In order to extract Image from 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 using 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#

var inputFile = Path.Combine(dataDir, "ExtractImages.pdf");
var outputFile = Path.Combine(dataDir, "ExtractImages_out.pdf");
var imageFile = Path.Combine(dataDir, "aspose-logo.jpg");
var pdfDocument = new Aspose.Pdf.Document(inputFile);

var xImage = pdfDocument.Pages[1].Resources.Images[1];
var outputImage = new FileStream(imageFile, FileMode.Create);
xImage.Save(outputImage, 300);
outputImage.Close();

pdfDocument.Save(outputFile);