HTML JPG PDF XML DOCX
  Product Family
PDF

Remove Metadata from PDF in Node.js SDK

Delete a metadata from a PDF document using Cloud Node.js SDK

Get Started

How to remove Metadata via Node.js SDK

To delete Metadata, 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 remove Metadata via Cloud Node.js

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

  1. Create an object to connect to the Pdf.Cloud API
  2. Upload your document file
  3. Create a new XmpMetadataProperty. Set the name of the property you want to delete as the Key and null as the value
  4. Delete Metadata in the document using postXmpMetadata() function
  5. Perform some action after successful addition
  6. Download the result if needed it
 

Delete Metadata from PDF using Node.js


    import credentials from "./credentials.json"  with { type: "json" };
    import fs from 'node:fs/promises';
    import path from 'node:path';
    import { PdfApi } from "asposepdfcloud";
    import { XmpMetadata } from "asposepdfcloud/src/models/xmpMetadata.js";
    import { XmpMetadataProperty } from "asposepdfcloud/src/models/xmpMetadataProperty.js";

    const configParams = {
        LOCAL_FOLDER: "C:\\Samples\\",
        PDF_DOCUMENT_NAME: "sample.pdf",
        LOCAL_RESULT_DOCUMENT_NAME: "output_sample.pdf",
    };

    const pdfApi = new PdfApi(credentials.id, credentials.key);

    const pdfMetadatas = {
        async uploadDocument() {
            const pdfFilePath = path.join(configParams.LOCAL_FOLDER, configParams.PDF_DOCUMENT_NAME);
            const pdfFileData = await fs.readFile(pdfFilePath);
            await pdfApi.uploadFile(configParams.PDF_DOCUMENT_NAME, pdfFileData);
        },
        
        async downloadResult() {
            const changedPdfData = await pdfApi.downloadFile(configParams.PDF_DOCUMENT_NAME);
            const filePath = path.join(configParams.LOCAL_FOLDER, configParams.LOCAL_RESULT_DOCUMENT_NAME);
            await fs.writeFile(filePath, changedPdfData.body);
            console.log("Downloaded: " + filePath);
        },

        async getMetadata () {
            const responseMetadata = await pdfApi.getXmpMetadataJson(configParams.PDF_DOCUMENT_NAME);

            if (responseMetadata.response.status == 200)
            {
                const props = responseMetadata.body.properties;
                props.forEach((prop) =>{
                    console.log(prop.key);
                });
            }
        },

        async deleteMetadata () {
            const prop = new XmpMetadataProperty();
            prop.key = 'dc:creator';
            prop.value = null;        // null value means delete property...
            prop.namespaceUri = 'http://purl.org/dc/elements/1.1/';

            const metadata = new XmpMetadata();
            metadata.properties = [prop];
            
            const response = await pdfApi.postXmpMetadata(configParams.PDF_DOCUMENT_NAME, metadata);

            if (response.body.code == 200) {
                console.log("Delete metadata '" + prop.key + "' successful!");
                return true;
            }
        },
    }

    async function main() {
        try {
            await pdfMetadatas.uploadDocument();
            await pdfMetadatas.getMetadata();
            await pdfMetadatas.deleteMetadata();
            await pdfMetadatas.getMetadata();
            await pdfMetadatas.downloadResult();
        } catch (error) {
            console.error("Error:", error.message);
        }
    }
 

Work with Metadata in PDF

Working with metadata in PDF files is important. Metadata such as the title field, author and theme help classify documents, making it easier to manage large collections of documents by providing a quick overview of content without opening files. Metadata also improves file search by allowing you to search by keywords and attributes. This is particularly valuable in systems where the rapid retrieval of documents is essential. Add metadata into 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 remove metadata from PDF files online and test the functionality.