extract PDF images

Extract PDF images using .NET REST API.

In today’s digital age, where information is abundant and visuals convey messages more effectively than ever, the need to extract images from PDFs is undeniable. PDFs are a popular format for sharing documents, and often these files contain crucial images that need to be accessed or repurposed. Whether you’re looking to use images in presentations, incorporate them into reports, or share them across various platforms, the ability to extract images from PDFs is a powerful tool.

This article focuses on the pressing need for PDF image extraction and provides insights into efficient ways to achieve this using .NET Cloud SDK.

.NET Cloud SDK to Extract PDF Images

Aspose.PDF Cloud SDK for .NET is a powerful toolkit that not only allows you to efficiently extract images but also offers a spectrum of capabilities to manage and manipulate PDF documents i.e. text extraction, watermarking, annotation addition, and document conversion.

Now the first step is to add the SDK reference in our project and for that purpose, please search Aspose.PDF-Cloud in NuGet packages manager inside Visual Studio IDE and click the Add Package button.

You also need to obtain your client credentials from cloud dashboard. In case you do not have an existing account, simply create a free account by following the instructions specified over quick start.

Extract PDF Images using C# .NET

Let’s focus towards the details on image extraction to elevate the document processing and data extraction to a whole new level using C# .NET.

extract pictures from pdf

Preview pf images extracted from PDF file.

Given below are the quick details regarding above stated code snippet.

PdfApi pdfApi = new PdfApi(clientSecret, clientID);

Create an object of PdfApi class while passing client credentials as input arguments.

var response = pdfApi.PutImagesExtractAsJpeg("Instructions-for-Adding-Your-Logo-2.pdf", 1);

Now, call the API to extract images from the first page of the PDF document. After sucessful completion, the extracted images in JPEG format are stored in cloud storage.

The sample PDF file used in the above example can be downloaded from Instructions-for-Adding-Your-Logo-2.pdf.

Extract Pictures from PDF using cURL Commands

Extracting images from PDFs using Aspose.PDF Cloud and cURL commands is a straightforward and efficient process. By utilizing cURL commands, you can send HTTP requests to the Aspose.PDF Cloud API to initiate image extraction seamlessly. This approach simplifies the process, allowing an efficient approach to extract pictures from PDF without the need for extensive coding.

The first step in this approach is the generation of a JWT access token. So, please execute the following command:

curl -v "https://api.aspose.cloud/connect/token" \
 -X POST \
 -d "grant_type=client_credentials&client_id=163c02a1-fcaa-4f79-be54-33012487e783&client_secret=c71cfe618cc6c0944f8f96bdef9813ac" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -H "Accept: application/json"

Now, please execute the following command to extract photos from 3rd page of PDF document and save the extracted images as JPG format in the cloud storage.

curl -v "https://api.aspose.cloud/v3.0/pdf/{inputPDF}/pages/3/images/extract/jpeg?width=0&height=0" \
-X PUT \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-d{}

Replace inputPDF with the name of input PDF file already available in Cloud storage and, replace accessToken with JWT access token generated above.

Conclusion

In conclusion, the ability to extract images from PDF documents is a vital component in leveraging the rich visual content often embedded within PDFs. This article explored two effective methods to achieve this: using the Aspose.PDF Cloud SDK for .NET and leveraging Aspose.PDF Cloud with cURL commands. So, the choice between the two approaches depends on specific project requirements, technical expertise, and preferred integration methods, providing you with the flexibility to cater to your unique needs.

We highly recommend visiting the following blogs: