Add, Read and Remove Document Properties in Word in Java
Tags: java, word, documentproperty
Published: 2019-07-08 08:36:43

---
title: Add, Read and Remove Document Properties in Word in Java
published: true
description: This article shows how to add, read and remove Word document properties using java
tags: java, word, document property
---
Every Word document can contain built-in properties and custom properties like Author, Category, Title, Subject, keyword (Tag), Comment etc. In this article, we will see how to create these properties for a Word document, and will learn how to read and remove these properties from the Word document programmatically in Java using [Free Spire.Doc for Java library](https://www.e-iceblue.com/Introduce/free-doc-for-java.html).

#Create document properties

1.Create built-in document properties
```java
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");

        //Create built-in properties
        document.getBuiltinDocumentProperties().setTitle("Creating document properties");
        document.getBuiltinDocumentProperties().setSubject("Word document properties");
        document.getBuiltinDocumentProperties().setAuthor("James");
        document.getBuiltinDocumentProperties().setCompany("Codex");
        document.getBuiltinDocumentProperties().setManager("Chris");
        document.getBuiltinDocumentProperties().setCategory("Word manipulation");
        document.getBuiltinDocumentProperties().setKeywords("Document properties, Word");
        document.getBuiltinDocumentProperties().setComments("For internal use only");

        //Save the resultant document
        document.saveToFile("SetBuiltInProperties.docx", FileFormat.Docx_2013);
    }
}
```
![](https://thepracticaldev.s3.amazonaws.com/i/77xfnyw43sqr2v475a8i.png) 

2.Create custom document properties
```java
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");

        //Create custom properties
        document.getCustomDocumentProperties().add("TrackingID", "AB01");
        document.getCustomDocumentProperties().add("Checked by", "Wilson");

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

    }
}
```
![](https://thepracticaldev.s3.amazonaws.com/i/usvyi03lj6ck850rte39.png) 

#Read document properties

1.Read built-in document properties
```java
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("SetBuiltInProperties.docx");

        //Read built-in properties
        System.out.println("Title: " + document.getBuiltinDocumentProperties().getTitle());
        System.out.println("Subject: " + document.getBuiltinDocumentProperties().getSubject());
        System.out.println("author: " + document.getBuiltinDocumentProperties().getAuthor());
        System.out.println("company: " + document.getBuiltinDocumentProperties().getCompany());
        System.out.println("manager: " + document.getBuiltinDocumentProperties().getManager());
        System.out.println("category: " + document.getBuiltinDocumentProperties().getCategory());
        System.out.println("keyWords: " + document.getBuiltinDocumentProperties().getKeywords());
        System.out.println("comments: " + document.getBuiltinDocumentProperties().getComments());
    }
}
```
![](https://thepracticaldev.s3.amazonaws.com/i/3ck0i7xoiaskz7kdvquj.png)
 
2.Read custom document properties
```java
import com.spire.doc.Document;
import com.spire.doc.DocumentProperty;

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

        //Get the first custom property        
        DocumentProperty property = document.getCustomDocumentProperties().get(0);
        //DocumentProperty property = document.getCustomDocumentProperties().get("TrackingID");

        //Read name and value of the first custom property
        System.out.println("Name: " + property.getName());
        System.out.println("Value: " + property.getValue());
    }
}
```
![](https://thepracticaldev.s3.amazonaws.com/i/0zmdccbd56vdau1gzksp.png) 

#Remove document properties

1.Remove built-in properties
```java
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("SetBuiltInProperties.docx");

        //Remove built-in properties by setting the value to null
        document.getBuiltinDocumentProperties().setTitle("");
        document.getBuiltinDocumentProperties().setSubject("");
        document.getBuiltinDocumentProperties().setAuthor("");
        document.getBuiltinDocumentProperties().setCompany("");
        document.getBuiltinDocumentProperties().setManager("");
        document.getBuiltinDocumentProperties().setCategory("");
        document.getBuiltinDocumentProperties().setKeywords("");
        document.getBuiltinDocumentProperties().setComments("");

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

2.Remove custom properties
```java
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("SetCustomProperties.docx");

        //Remove specific custom property by name
        document.getCustomDocumentProperties().remove("TrackingID");
        document.getCustomDocumentProperties().remove("Checked by");

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