Delete Images from PDF File in Node.js

Contents
[ ]

You can delete images from a PDF file using Aspose.PDF for Node.js via C++.

In case you want to delete images from PDF, you can use AsposePdfDeleteImages function. Please check the following code snippet in order to delete images in Node.js environment.

CommonJS:

  1. Call require and import asposepdfnodejs module as AsposePdf variable.
  2. Specify the name of the PDF file in which the image will be removed.
  3. Call AsposePdf as Promise and perform the operation for removing images. Receive the object if successful.
  4. Call the function AsposePdfDeleteImages.
  5. Delete images from a PDF. Thus, if ‘json.errorCode’ is 0, the result of the operation is saved in “ResultPdfDeleteImages.pdf”. If the json.errorCode parameter is not 0 and, accordingly, an error appears in your file, the error information will be contained in ‘json.errorText’.

    const AsposePdf = require('asposepdfnodejs');
    const pdf_file = 'Aspose.pdf';
    AsposePdf().then(AsposePdfModule => {
        /*Delete images from a PDF-file and save the "ResultPdfDeleteImages.pdf"*/
        const json = AsposePdfModule.AsposePdfDeleteImages(pdf_file, "ResultPdfDeleteImages.pdf");
        console.log("AsposePdfDeleteImages => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);
    });

ECMAScript/ES6:

  1. Import the asposepdfnodejs module.
  2. Specify the name of the PDF file in which the image will be removed.
  3. Initialize the AsposePdf module. Receive the object if successful.
  4. Call the function AsposePdfDeleteImages.
  5. Delete images from a PDF. Thus, if ‘json.errorCode’ is 0, the result of the operation is saved in “ResultPdfDeleteImages.pdf”. If the json.errorCode parameter is not 0 and, accordingly, an error appears in your file, the error information will be contained in ‘json.errorText’.

    import AsposePdf from 'asposepdfnodejs';
    const AsposePdfModule = await AsposePdf();
    const pdf_file = 'Aspose.pdf';
    /*Delete images from a PDF-file and save the "ResultPdfDeleteImages.pdf"*/
    const json = AsposePdfModule.AsposePdfDeleteImages(pdf_file, "ResultPdfDeleteImages.pdf");
    console.log("AsposePdfDeleteImages => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);