HTML JPG PDF XML DOCX
  Product Family
PDF

Extract Image from PDF in Node.js SDK

Extract Images from PDF Document using Cloud Node.js SDK.

Get Started

How to Extract Images from PDF via Node.js SDK

To extract Images from PDF, we’ll use Aspose.PDF Cloud Node.js SDK. This Cloud SDK assists Node.js programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Node.js programming language via Aspose.PDF REST API. Simply create an account at Aspose for Cloud and get your application information. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud Node.js SDK.

Package Manager Console Command


     
    npm install asposepdfcloud --save
     
     

Steps to get Images from PDF using Node.js

Aspose.PDF Cloud developers can easily load & extract Images from PDF in just a few lines of code.

  1. Load your Application Secret and Key from the JSON file or set credentials in another way
  2. Retrieves the first image from the uploaded PDF file.
  3. Extracts the image and saves it as a local PNG file.
  4. Download the result if needed it
 

Extract Images from PDF using Node.js


    import credentials from "./credentials.json"  with { type: "json" };
    import fs from 'node:fs/promises';
    import { PdfApi } from "asposepdfcloud";

    async function extract() {
        const localPdfFile = "C:\\Samples\\Sample.pdf";
        const storagePdfFile = "Sample.pdf";
        const localImageFile = "C:\\Samples\\Sample.png";

        const pdfApi = new PdfApi(credentials.id, credentials.key);
        try {
            let fileData = await fs.readFile(localPdfFile);
            let uploadResult = await pdfApi.uploadFile(storagePdfFile, fileData);
            console.log(uploadResult.response.text);
        }
        catch (error) {
            console.error(error.message);
        }

        try {
            const imagesResult = await pdfApi.getImages(storagePdfFile, 1, null, null);
            const imageId = imagesResult.body.images.list[0].id;
            const response = await pdfApi.getImageExtractAsPng(storagePdfFile, imageId);
            await fs.writeFile(localImageFile, response.body);
        } catch (error) {
            console.error(error.message);
        }
    }
 

Work with Images in PDF

Extracted images can be reused in other documents, presentations, or marketing materials, saving time and resources by avoiding re-creation. Once extracted, images can be edited or enhanced to improve their quality or adapt them for specific purposes, such as resizing or recoloring. Images extracted from a PDF can be stored separately for archival purposes, ensuring easy access and organization of visual content. By extracting images from a PDF, users can better manage, edit, and utilize visual content for a wide range of applications, from professional presentations to creative projects. Extract the Images from PDF documents with Aspose.PDF Cloud Node.js SDK.

With our Node.js library you can:

  • Add PDF document’s header & footer in text or image format.
  • Add tables & stamps (text or image) to PDF documents.
  • Append multiple PDF documents to an existing file.
  • Work with PDF attachments, annotations, & form fields.
  • Apply encryption or decryption to PDF documents & set a password.
  • Delete all stamps & tables from a page or entire PDF document.
  • Delete a specific stamp or table from the PDF document by its ID.
  • Replace single or multiple instances of text on a PDF page or from the entire document.
  • Extensive support for converting PDF documents to various other file formats.
  • Extract various elements of PDF files & make PDF documents optimized.
  • You can try out our free App to change image dimensions in PDF files online and test the functionality.