DEV Community

Shahzad Ashraf
Shahzad Ashraf

Posted on

Master PDF Metadata Extraction in Java Apps

If you're a Java developer looking to extract PDF file metadata effortlessly, using the GroupDocs.Parser Cloud Java SDK is your go-to resource. This powerful cloud API allows you to programmatically access detailed metadata with minimal code, making document management simpler and more efficient.

Developers can unlock the hidden potential of their PDF documents by diving deep into their PDFs to reveal crucial information—everything from author details to modification dates, without the need for bulky desktop tools. Our step-by-step article shows you how to integrate metadata extraction into your Java applications, enhancing search capabilities, compliance, and data insights. Whether you're working on a document automation system or a digital archiving solution, this guide offers actionable tips and practical examples to help you get started quickly.

And this Java code example lets you integrate this functionality into your Java apps in no time:

package com.groupdocs;
import com.groupdocs.cloud.parser.client.*;
import com.groupdocs.cloud.parser.api.*;
import com.groupdocs.cloud.parser.model.*;
import com.groupdocs.cloud.parser.model.requests.*;

public class ExtractMetadataFromPDF {

    public static void main(String[] args) {

        // Configure your API credentials for authentication
        String MyAppKey = "your-app-key"; 
        String MyAppSid = "your-app-sid";
        Configuration configuration = new Configuration(MyAppKey, MyAppSid);

        // Initialize the InfoApi class for metadata/info extraction
        InfoApi infoApi = new InfoApi(configuration);

        try {
            // Define the source file path in cloud storage
            FileInfo fileInfo = new FileInfo();
            fileInfo.setFilePath("SampleFiles/source.pdf");

            // Apply document info extraction options
            InfoOptions options = new InfoOptions();
            options.setFileInfo(fileInfo);

            // Create and execute metadata/info extraction request
            GetInfoRequest request = new GetInfoRequest(options);
            InfoResult result = infoApi.getInfo(request);

            // Print the extracted PDF document info to the console
            System.out.println("File Metadata/Info Extracted Successfully!");
            System.out.println("File type: " + result.getFileType());
            System.out.println("File size: " + result.getSize() + "bytes");
            System.out.println("Pages: " + result.getPageCount());

        } catch (Exception e) {
            System.err.println("An error occurred: " + e.getMessage());
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)