Set PDF Document Properties using Java

Document properties are some descriptive information such as title, author, subject, key words, creation date, creator and producer, etc. This article will introduce how to set PDF document properties with a 3rd party free API — Free Spire.XLS for Java.

Import JAR dependency (2 methods)
● Download the Free Spire.PDF for Java and unzip it.Then add the Spire.Pdf.jar file to your project as dependency.

● You can also add the jar dependency to maven project by adding the following configurations to the pom.xml.


Relevant code snippet:

import com.spire.pdf.PdfDocument;

import java.util.Date;

public class SetDocumentProperties {
public static void main(String[] args)
//Instantiate a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load the PDF document

//Set title
pdf.getDocumentInformation().setTitle("Test Document");
//Set author
//Set subject
pdf.getDocumentInformation().setSubject("Document Properties Setting");
//Set key words
pdf.getDocumentInformation().setKeywords("Document Properties, PDF");
//Set creation date
pdf.getDocumentInformation().setCreationDate(new Date());
//set creator
pdf.getDocumentInformation().setCreator("Free Spire.PDF for Java");
//set producer
pdf.getDocumentInformation().setProducer("Free Spire.PDF for Java");

//save the document

Sharing Java Code