How to extract images from a PDF file?
Steps to extract images in PDF programmatically:
- Create a new C# Console application project.
- Install the NuGet package as reference to your .NET Framework applications from .
- Include the following namespaces in the Program.cs file.
using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; using System.Drawing;
Imports Syncfusion.Pdf Imports Syncfusion.Pdf.Parsing Imports System.Drawing
- Use the method that allows you to extract images from a particular page or an entire PDF document.
//Extract images from first page Image extractedImages = pageBase.ExtractImages();
- The following C# and VB.NET code snippet shows how to extract images from a particular page or an entire PDF document.
//Load an existing PDF PdfLoadedDocument loadedDocument = new PdfLoadedDocument(DataPathBase + "sample.pdf"); //Load first page PdfPageBase pageBase = loadedDocument.Pages; //Extract images from first page Image extractedImages = pageBase.ExtractImages(); //close the document loadedDocument.Close(true);
'Load an existing PDF Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument((DataPathBase + "sample.pdf")) 'Load first page Dim pageBase As PdfPageBase = loadedDocument.Pages(0) 'Extract images from first page Dim extractedImages() As Image = pageBase.ExtractImages 'close the document loadedDocument.Close(True)
The input PDF document is as follows.
By executing the program, you will get the list of extracted images from the first page of the PDF document.
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to to learn about generating and registering Syncfusion license key in your application to use the components without trail message.
I hope you enjoyed learning about how to extract images from a PDF file.