Metadata Management in Node.js

Managing metadata is an important part of document automation, especially for applications that work with different document formats. In this article, we will look at how to manage metadata in Node.js applications, with a focus on extracting, modifying, and removing metadata.

In this guide, we will explore the following sections:

  1. What is GroupDocs.Metadata and how it helps?
  2. How to install
  3. Quick start guide
  4. Key Features
  5. Common Use Cases
  6. Getting Started with a Free Trial
  7. See Also

What is GroupDocs.Metadata and how it helps?

GroupDocs.Metadata for Node.js is a library that helps developers manage metadata across various document formats in Node.js applications.

Although there are native methods that allow Node.js developers to extract basic metadata such as file size, type, and attributes, these methods do not cover more complex metadata associated with specific file formats.

GroupDocs.Metadata fills this gap by allowing users to retrieve, update, and remove metadata from files such as PDFs, Microsoft Office formats, images, audio, video and many others. It also enables access to detailed information such as the author, title, specific properties of file formats, including GPS location data, and many others. With a straightforward API, GroupDocs.Metadata allows you to manipulate metadata effectively to cover many document automation and data processing scenarios.

How to install

GroupDocs.Metadata for Node.js via Java is hosted at NPM. You can easily reference our API in your Node.js project by installing it with the following command:

npm install @groupdocs/groupdocs.metadata

Quick start guide

Getting started with GroupDocs.Metadata for Node.js is quick and straightforward with our examples project. Here’s a simple guide to help you set up:

  1. Clone the Repository: Clone the example repository to your local machine.

    git clone https://github.com/groupdocs-metadata/GroupDocs.Metadata-for-Node.js-via-Java.git
    
  2. Navigate to the Examples Folder:

    cd ./GroupDocs.Metadata-for-Node.js-via-Java/
    
  3. Install Necessary Packages:

    npm install   
    
  4. Run the Examples:

    node runExamples.js 
    

This will execute a series of example scripts demonstrating various functionalities of the GroupDocs.Metadata library.

Key Features

GroupDocs.Metadata for Node.js is equipped with a range of features that make it a useful API for developers dealing with document metadata. Here are some of the key features:

  • Rich Set of Metadata Management Features: Read, update, and remove metadata from various document formats.
  • Targeted Property Manipulation: Search, update, and delete specific metadata properties that meet certain criteria.
  • Unified Property Management: Utilize tags for easy manipulation of common metadata properties in a consistent manner.
  • Support for Password-Protected Documents: Work with documents that are secured, ensuring flexibility even with sensitive data.
  • Insight into Document Properties: Extract detailed information about hidden pages, digital signatures, user comments, revisions, and more.
  • Compatibility with Popular Standards: Work with leading metadata standards such as IPTC, XMP, EXIF, and Image Resources.
  • Multimedia Metadata Handling: Manipulate native metadata properties in various formats and extract technical information from multimedia files.
  • Document Statistics Calculation: Calculate common document statistics like word count and character count for your documents.
  • File Format Detection: Identify the format and MIME type of a file based on its internal structure.
  • Support for Audio Tags: Manage various audio tags, including ID3, Lyrics, and APE.

Common Use Cases

Below are some common use cases for GroupDocs.Metadata in Node.js applications, along with corresponding code snippets.

Use Case 1: Retrieve metadata from an image

In this example, we will fetch metadata properties of an image file (e.g., image.png) based on specific criteria.

  1. Initialize the Metadata Object: Create a new instance of the Metadata class with your file.
  2. Define Search Criteria: Use a search specification to find particular properties, such as “Width” or “Height.”
  3. Fetch and Display Metadata: Retrieve the matching properties and log their names and values.
const groupdocsMetadata = require('@groupdocs/groupdocs.metadata');

try {
    // Initialize the Metadata object with the image file
    const metadata = new groupdocsMetadata.Metadata("image.png");

    // Fetch properties based on name criteria: Width or Height
    var searchSpecification = new groupdocsMetadata.WithNameSpecification("Width")
        .or(new groupdocsMetadata.WithNameSpecification("Height"));
    var metadataProperties = metadata.findProperties(searchSpecification);

    console.log(`Total found properties#: ${metadataProperties.getCount()}`);    

    // Iterate and log all found properties
    for (var i = 0; i < metadataProperties.getCount(); i++) {
        console.log(`Property name: ${metadataProperties.get_Item(i).getName()}, 
        Property value: ${metadataProperties.get_Item(i).getValue()}`);
    }
} catch (error) {
    console.error('An error:', error);
}

Use Case 2: Clean up metadata from a document

Here we will clean up unwanted metadata from a PDF document.

  1. Load the PDF: Create a Metadata object for the PDF file.
  2. Sanitize Metadata: Remove detected metadata packages.
  3. Save the Cleaned Document: Save the sanitized document to a new file.
try {
    // Load the PDF file
    const metadata = new groupdocsMetadata.Metadata("input.pdf");

    // Remove detected metadata packages and log the properties removed
    var affected = metadata.sanitize();
    console.log(`Properties removed: ${affected}`);

    // Save the cleaned PDF
    metadata.save("cleaned_output.pdf");
} catch (error) {
    console.error('An error occurred during the sanitization:', error);
}

Use Case 3: Update document metadata

This example will show you how to update the creation and modification dates of a document.

  1. Load the Document: Initialize a Metadata object for the document file.
  2. Set New Properties: Update the creation and modification dates of the document.
  3. Save the Updated Document: Save the changes to the file.
try {
    // Load the VSDX file
    const metadata = new groupdocsMetadata.Metadata("input.vsdx");

    // Set the current date for creation and modification properties
    var affected = metadata.setProperties(
        new groupdocsMetadata.ContainsTagSpecification(
                groupdocsMetadata.Tags.getTime().getCreated())
            .or(new groupdocsMetadata.ContainsTagSpecification(
                groupdocsMetadata.Tags.getTime().getModified())),
        new groupdocsMetadata.PropertyValue(new Date())
    );

    console.log(`Properties set: ${affected}`);

    // Save the updated VSDX
    metadata.save("updated_output.vsdx");
} catch (error) {
    console.error('An error occurred:', error);
}

Getting Started with a Free Trial

By default the library operates in trial mode without a license, allowing you to explore its basic features and functionalities of the library. You can download GroupDocs.Metadata for Node.js via Java from the GroupDocs Releases page.

Additionally, you can acquire a temporary license from this link. The temp license allows you to use the library without any restrictions and fully explore its capabilities.

See Also

To delve deeper and gain more insights about GroupDocs.Metadata and its functionalities, refer to the following resources: