Set custom properties for PDF files in Java

We have already demonstrated how to set PDF Document Properties in Java. This article we will show you how to set custom properties for PDF files in Java.

import com.spire.pdf.*;

public class PDFCustomProperties {
    public static void main(String[] args) throws Exception {

        String inputPath = "Sample.pdf";
        PdfDocument doc = new PdfDocument(inputPath);
        doc.loadFromFile(inputPath);

        //Set the custom properties
        doc.getDocumentInformation().setCustomerDefined("Number", "123");
        doc.getDocumentInformation().setCustomerDefined("Name", "Daisy");
        doc.getDocumentInformation().setCustomerDefined("Company", "e-iceblue");
       
        //Save the document to file
        doc.saveToFile("Output/result.pdf");
        doc.close();

    }
}

Effective screenshot after adding custom properties to PDF document:

Set custom properties for PDF files in Java