Skip to content

Instantly share code, notes, and snippets.

How to Edit Word Document Metadata in Java. For more details: https://kb.aspose.com/words/java/how-to-edit-word-document-metadata-in-java/
import com.aspose.words.*;
public class Main {
public static void main(String[] args) throws Exception // Update Word Metadata in Java
{
// Set the licenses
new com.aspose.words.License().setLicense("Aspose.Total.lic");
// Load the document
Document doc = new Document("SampleProps.docx");
// Access the properties
CustomDocumentProperties custProps = doc.getCustomDocumentProperties();
// Check the desired property
if (custProps.get("Reviewed") != null)
{
// Set new properties
custProps.get("Reviewed By").setValue("Mart");
custProps.get("Reviewed Date").setValue(new java.util.Date());
}
// Access the properties
BuiltInDocumentProperties documentProperties = doc.getBuiltInDocumentProperties();
// Update the properties
documentProperties.get("Pages").setValue(doc.getPageCount());
documentProperties.get("Comments").setValue("Document Comments");
documentProperties.get("Title").setValue("Document Title");
// Save the output file
doc.save("Output.docx");
System.out.println("Done");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment