Monday, 10 June 2019 07:14

Add Document Properties to Word Document in Java

Written by  support iceblue
Rate this item
(0 votes)

Spire.Doc for Java supports adding the following two types of document properties to Word document:

  • Built-in document properties
  • Custom document properties

In this article, we will see how to use Spire.Doc for Java to add the above document properties into a Word document.

Add Built-In Document Properties

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class SetDocumentProperties {
    public static void main(String[] args){
        //Load Word document
        Document document = new Document("Input.docx");

        //Add built-in document properties to the Word document
        document.getBuiltinDocumentProperties().setTitle("Document Demo Document");
        document.getBuiltinDocumentProperties().setSubject("demo");
        document.getBuiltinDocumentProperties().setAuthor("James");
        document.getBuiltinDocumentProperties().setCompany("e-iceblue");
        document.getBuiltinDocumentProperties().setManager("Jakson");
        document.getBuiltinDocumentProperties().setCategory("Doc Demos");
        document.getBuiltinDocumentProperties().setKeywords("Document, Property, Demo");
        document.getBuiltinDocumentProperties().setComments("This document is just a demo.");

        //Save the resultant document
        document.saveToFile("SetBuiltInProperties.docx", FileFormat.Docx_2013);
    }
}

Add Document Properties to Word Document in Java

Add Custom Document Properties

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class SetDocumentProperties {
    public static void main(String[] args){

        //Load Word document
        Document document = new Document("Input.docx");

        //Add custom document properties to the Word document
        document.getCustomDocumentProperties().add("TrackingID", "AB01");
        document.getCustomDocumentProperties().add("Checked By", "Wilson");

        //Save the resultant document
        document.saveToFile("SetCustomProperties.docx", FileFormat.Docx_2013);

    }
}

Add Document Properties to Word Document in Java

Additional Info

  • tutorial_title: