Last active
June 9, 2023 14:02
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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