com.aspose.words

Class BuiltInDocumentProperties

A collection of built-in document properties.

Provides access to DocumentProperty objects by their names (using an indexer) and via a set of typed properties that return values of appropriate types.

The names of the properties are case-insensitive.

The properties in the collection are sorted alphabetically by name.

Example:

Enumerates through all built-in and custom properties in a document.
String fileName = getMyDir() + "Properties.doc";
Document doc = new Document(fileName);

System.out.println(MessageFormat.format("1. Document name: {0}", doc.getOriginalFileName()));

System.out.println("2. Built-in Properties");
for (DocumentProperty docProperty : doc.getBuiltInDocumentProperties())
    System.out.println(MessageFormat.format("{0} : {1}", docProperty.getName(), docProperty.getValue()));

System.out.println("3. Custom Properties");
for (DocumentProperty docProperty : doc.getCustomDocumentProperties())
    System.out.println(MessageFormat.format("{0} : {1}", docProperty.getName(), docProperty.getValue()));
See Also:
Document, Document.BuiltInDocumentProperties, Document.CustomDocumentProperties

Property Getters/Setters Summary
java.lang.StringgetAuthor()
void
setAuthor(java.lang.Stringvalue)
           Gets or sets the name of the document's author.
intgetBytes()
void
setBytes(intvalue)
           Represents an estimate of the number of bytes in the document.
java.lang.StringgetCategory()
void
setCategory(java.lang.Stringvalue)
           Gets or sets the category of the document.
intgetCharacters()
void
setCharacters(intvalue)
           Represents an estimate of the number of characters in the document.
intgetCharactersWithSpaces()
void
           Represents an estimate of the number of characters (including spaces) in the document.
java.lang.StringgetComments()
void
setComments(java.lang.Stringvalue)
           Gets or sets the document comments.
java.lang.StringgetCompany()
void
setCompany(java.lang.Stringvalue)
           Gets or sets the company property.
java.lang.StringgetContentStatus()
void
setContentStatus(java.lang.Stringvalue)
           Gets or sets the ContentStatus of the document.
java.lang.StringgetContentType()
void
setContentType(java.lang.Stringvalue)
           Gets or sets the ContentStatus of the document.
intgetCount()
Gets number of items in the collection.
java.util.DategetCreatedTime()
void
setCreatedTime(java.util.Datevalue)
           Gets or sets date of the document creation in UTC.
java.lang.Object[]getHeadingPairs()
void
setHeadingPairs(java.lang.Object[]value)
           Specifies document headings and their names.
java.lang.StringgetHyperlinkBase()
void
setHyperlinkBase(java.lang.Stringvalue)
           Specifies the base string used for evaluating relative hyperlinks in this document.
java.lang.StringgetKeywords()
void
setKeywords(java.lang.Stringvalue)
           Gets or sets the document keywords.
java.util.DategetLastPrinted()
void
setLastPrinted(java.util.Datevalue)
           Gets or sets the date when the document was last printed in UTC.
java.lang.StringgetLastSavedBy()
void
setLastSavedBy(java.lang.Stringvalue)
           Gets or sets the name of the last author.
java.util.DategetLastSavedTime()
void
setLastSavedTime(java.util.Datevalue)
           Gets or sets the time of the last save in UTC.
intgetLines()
void
setLines(intvalue)
           Represents an estimate of the number of lines in the document.
booleangetLinksUpToDate()
void
setLinksUpToDate(booleanvalue)
           Indicates whether hyperlinks in a document are up-to-date.
java.lang.StringgetManager()
void
setManager(java.lang.Stringvalue)
           Gets or sets the manager property.
java.lang.StringgetNameOfApplication()
void
setNameOfApplication(java.lang.Stringvalue)
           Gets or sets the name of the application.
intgetPages()
void
setPages(intvalue)
           Represents an estimate of the number of pages in the document.
intgetParagraphs()
void
setParagraphs(intvalue)
           Represents an estimate of the number of paragraphs in the document.
intgetRevisionNumber()
void
           Gets or sets the document revision number.
intgetSecurity()
void
setSecurity(intvalue)
           Specifies the security level of a document as a numeric value. The value of the property is DocumentSecurity integer constant.
java.lang.StringgetSubject()
void
setSubject(java.lang.Stringvalue)
           Gets or sets the subject of the document.
java.lang.StringgetTemplate()
void
setTemplate(java.lang.Stringvalue)
           Gets or sets the informational name of the document template.
byte[]getThumbnail()
void
setThumbnail(byte[]value)
          

Gets or sets the thumbnail of the document.

java.lang.StringgetTitle()
void
setTitle(java.lang.Stringvalue)
           Gets or sets the title of the document.
java.lang.String[]getTitlesOfParts()
void
setTitlesOfParts(java.lang.String[]value)
           Each string in the array specifies the name of a part in the document.
intgetTotalEditingTime()
void
           Gets or sets the total editing time in minutes.
intgetVersion()
void
setVersion(intvalue)
           Represents the version number of the application that created the document.
intgetWords()
void
setWords(intvalue)
           Represents an estimate of the number of words in the document.
DocumentPropertyget(int index)
Returns a DocumentProperty object by index.
DocumentPropertyget(java.lang.String name)
Returns a DocumentProperty object by the name of the property.
 
Method Summary
voidclear()
Removes all properties from the collection.
booleancontains(java.lang.String name)
Returns true if a property with the specified name exists in the collection.
intindexOf(java.lang.String name)
Gets the index of a property by name.
java.util.Iterator<DocumentProperty>iterator()
Returns an iterator object that can be used to iterate over all items in the collection.
voidremove(java.lang.String name)
Removes a property with the specified name from the collection.
voidremoveAt(int index)
Removes a property at the specified index.
 

    • Property Getters/Setters Detail

      • getAuthor/setAuthor

        public java.lang.String getAuthor() / public void setAuthor(java.lang.String value)
        
        Gets or sets the name of the document's author.

        Example:

        Shows how to work with document properties in the "Description" category.
        // Create a blank document
        Document doc = new Document();
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Set the values of some descriptive properties
        // These are metadata that can be glanced at without opening the document in the "Details" or "Content" folder views in Windows Explorer
        // The "Details" view has columns dedicated to these properties
        // Fields such as AUTHOR, SUBJECT, TITLE etc. can be used to display these values inside the document
        properties.setAuthor("John Doe");
        properties.setTitle("John's Document");
        properties.setSubject("My subject");
        properties.setCategory("My category");
        properties.setComments("This is {properties.Author}'s document about {properties.Subject}");
        
        // Tags can be used as keywords and are separated by semicolons
        properties.setKeywords("Tag 1; Tag 2; Tag 3");
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Description
        doc.save(getArtifactsDir() + "Properties.Description.docx");
      • getBytes/setBytes

        public int getBytes() / public void setBytes(int value)
        
        Represents an estimate of the number of bytes in the document.

        Microsoft Word does not always set this property.

        Aspose.Words does not update this property.

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception {
            // Open a document with a couple paragraphs of content
            Document doc = new Document(getMyDir() + "Properties.Content.docx");
        
            // The properties we will work with are members of the BuiltInDocumentProperties attribute
            BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
            // By using built in properties,
            // we can treat document statistics such as word/page/character counts as metadata that can be glanced at without opening the document
            // These properties are accessed by right-clicking the file in Windows Explorer and navigating to Properties > Details > Content
            // If we want to display this data inside the document, we can use fields such as NUMPAGES, NUMWORDS, NUMCHARS etc.
            // Also, these values can also be viewed in Microsoft Word by navigating File > Properties > Advanced Properties > Statistics
            // Page count: The PageCount attribute shows the page count in real time and its value can be assigned to the Pages property
            properties.setPages(doc.getPageCount());
            Assert.assertEquals(properties.getPages(), 2);
        
            // Word count: The UpdateWordCount() automatically assigns the real time word/character counts to the respective built in properties
            doc.updateWordCount();
            Assert.assertEquals(properties.getWords(), 198);
            Assert.assertEquals(properties.getCharacters(), 1114);
            Assert.assertEquals(properties.getCharactersWithSpaces(), 1310);
        
            // Line count: Count the lines in a document and assign value to the Lines property\
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
            Assert.assertEquals(properties.getLines(), 14);
        
            // Paragraph count: Assign the size of the count of child Paragraph-nodes to the Paragraphs built in property
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(properties.getParagraphs(), 2);
        
            // Bytes: Use a stream to find out the real file size of our document and assign it to the Property
            OutputStream stream = new FileOutputStream(getArtifactsDir() + "Properties.Content.docx");
            doc.save(stream, SaveFormat.DOCX);
        
            // Template: The Template attribute can reflect the filename of the attached template document
            doc.setAttachedTemplate(getMyDir() + "Document.BusinessBrochureTemplate.dot");
            Assert.assertEquals(properties.getTemplate(), "Normal");
            properties.setTemplate(doc.getAttachedTemplate());
        
            // Content status: This is a descriptive field
            properties.setContentStatus("Draft");
        
            // Content type: Upon saving, any value we assign to this field will be overwritten by the MIME type of the output save format
            Assert.assertEquals(properties.getContentType(), "");
        
            // If the document contains links and they are all up to date, we can set this to true
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "Properties.Content.docx");
        }
        
        /// <summary>
        /// Util class that counts the lines in a document
        /// Upon construction, traverses the document's layout entities tree, counting entities of the "Line" type that also contain real text
        /// </summary>
        private static class LineCounter {
            public LineCounter(Document doc) throws Exception {
                mLayoutEnumerator = new LayoutEnumerator(doc);
        
                countLines();
            }
        
            public int getLineCount() {
                return mLineCount;
            }
        
            private void countLines() throws Exception {
                do {
                    if (mLayoutEnumerator.getType() == LayoutEntityType.LINE) {
                        mScanningLineForRealText = true;
                    }
        
                    if (mLayoutEnumerator.moveFirstChild()) {
                        if (mScanningLineForRealText && mLayoutEnumerator.getKind().startsWith("TEXT")) {
                            mLineCount++;
                            mScanningLineForRealText = false;
                        }
                        countLines();
                        mLayoutEnumerator.moveParent();
                    }
                } while (mLayoutEnumerator.moveNext());
            }
        
            private /*final*/ LayoutEnumerator mLayoutEnumerator;
            private int mLineCount;
            private boolean mScanningLineForRealText;
        }
      • getCategory/setCategory

        public java.lang.String getCategory() / public void setCategory(java.lang.String value)
        
        Gets or sets the category of the document.

        Example:

        Shows how to work with document properties in the "Description" category.
        // Create a blank document
        Document doc = new Document();
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Set the values of some descriptive properties
        // These are metadata that can be glanced at without opening the document in the "Details" or "Content" folder views in Windows Explorer
        // The "Details" view has columns dedicated to these properties
        // Fields such as AUTHOR, SUBJECT, TITLE etc. can be used to display these values inside the document
        properties.setAuthor("John Doe");
        properties.setTitle("John's Document");
        properties.setSubject("My subject");
        properties.setCategory("My category");
        properties.setComments("This is {properties.Author}'s document about {properties.Subject}");
        
        // Tags can be used as keywords and are separated by semicolons
        properties.setKeywords("Tag 1; Tag 2; Tag 3");
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Description
        doc.save(getArtifactsDir() + "Properties.Description.docx");
      • getCharacters/setCharacters

        public int getCharacters() / public void setCharacters(int value)
        
        Represents an estimate of the number of characters in the document.

        Aspose.Words updates this property when you call Document.updateWordCount().

        Example:

        Shows how to update all list labels in a document.
        Document doc = new Document(getMyDir() + "Document.doc");
        
        // Some work should be done here that changes the document's content.
        
        // Update the word, character and paragraph count of the document.
        doc.updateWordCount();
        
        // Display the updated document properties.
        System.out.println(MessageFormat.format("Characters: {0}", doc.getBuiltInDocumentProperties().getCharacters()));
        System.out.println(MessageFormat.format("Words: {0}", doc.getBuiltInDocumentProperties().getWords()));
        System.out.println(MessageFormat.format("Paragraphs: {0}", doc.getBuiltInDocumentProperties().getParagraphs()));

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception {
            // Open a document with a couple paragraphs of content
            Document doc = new Document(getMyDir() + "Properties.Content.docx");
        
            // The properties we will work with are members of the BuiltInDocumentProperties attribute
            BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
            // By using built in properties,
            // we can treat document statistics such as word/page/character counts as metadata that can be glanced at without opening the document
            // These properties are accessed by right-clicking the file in Windows Explorer and navigating to Properties > Details > Content
            // If we want to display this data inside the document, we can use fields such as NUMPAGES, NUMWORDS, NUMCHARS etc.
            // Also, these values can also be viewed in Microsoft Word by navigating File > Properties > Advanced Properties > Statistics
            // Page count: The PageCount attribute shows the page count in real time and its value can be assigned to the Pages property
            properties.setPages(doc.getPageCount());
            Assert.assertEquals(properties.getPages(), 2);
        
            // Word count: The UpdateWordCount() automatically assigns the real time word/character counts to the respective built in properties
            doc.updateWordCount();
            Assert.assertEquals(properties.getWords(), 198);
            Assert.assertEquals(properties.getCharacters(), 1114);
            Assert.assertEquals(properties.getCharactersWithSpaces(), 1310);
        
            // Line count: Count the lines in a document and assign value to the Lines property\
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
            Assert.assertEquals(properties.getLines(), 14);
        
            // Paragraph count: Assign the size of the count of child Paragraph-nodes to the Paragraphs built in property
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(properties.getParagraphs(), 2);
        
            // Bytes: Use a stream to find out the real file size of our document and assign it to the Property
            OutputStream stream = new FileOutputStream(getArtifactsDir() + "Properties.Content.docx");
            doc.save(stream, SaveFormat.DOCX);
        
            // Template: The Template attribute can reflect the filename of the attached template document
            doc.setAttachedTemplate(getMyDir() + "Document.BusinessBrochureTemplate.dot");
            Assert.assertEquals(properties.getTemplate(), "Normal");
            properties.setTemplate(doc.getAttachedTemplate());
        
            // Content status: This is a descriptive field
            properties.setContentStatus("Draft");
        
            // Content type: Upon saving, any value we assign to this field will be overwritten by the MIME type of the output save format
            Assert.assertEquals(properties.getContentType(), "");
        
            // If the document contains links and they are all up to date, we can set this to true
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "Properties.Content.docx");
        }
        
        /// <summary>
        /// Util class that counts the lines in a document
        /// Upon construction, traverses the document's layout entities tree, counting entities of the "Line" type that also contain real text
        /// </summary>
        private static class LineCounter {
            public LineCounter(Document doc) throws Exception {
                mLayoutEnumerator = new LayoutEnumerator(doc);
        
                countLines();
            }
        
            public int getLineCount() {
                return mLineCount;
            }
        
            private void countLines() throws Exception {
                do {
                    if (mLayoutEnumerator.getType() == LayoutEntityType.LINE) {
                        mScanningLineForRealText = true;
                    }
        
                    if (mLayoutEnumerator.moveFirstChild()) {
                        if (mScanningLineForRealText && mLayoutEnumerator.getKind().startsWith("TEXT")) {
                            mLineCount++;
                            mScanningLineForRealText = false;
                        }
                        countLines();
                        mLayoutEnumerator.moveParent();
                    }
                } while (mLayoutEnumerator.moveNext());
            }
        
            private /*final*/ LayoutEnumerator mLayoutEnumerator;
            private int mLineCount;
            private boolean mScanningLineForRealText;
        }
      • getCharactersWithSpaces/setCharactersWithSpaces

        public int getCharactersWithSpaces() / public void setCharactersWithSpaces(int value)
        
        Represents an estimate of the number of characters (including spaces) in the document.

        Aspose.Words updates this property when you call Document.updateWordCount().

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception {
            // Open a document with a couple paragraphs of content
            Document doc = new Document(getMyDir() + "Properties.Content.docx");
        
            // The properties we will work with are members of the BuiltInDocumentProperties attribute
            BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
            // By using built in properties,
            // we can treat document statistics such as word/page/character counts as metadata that can be glanced at without opening the document
            // These properties are accessed by right-clicking the file in Windows Explorer and navigating to Properties > Details > Content
            // If we want to display this data inside the document, we can use fields such as NUMPAGES, NUMWORDS, NUMCHARS etc.
            // Also, these values can also be viewed in Microsoft Word by navigating File > Properties > Advanced Properties > Statistics
            // Page count: The PageCount attribute shows the page count in real time and its value can be assigned to the Pages property
            properties.setPages(doc.getPageCount());
            Assert.assertEquals(properties.getPages(), 2);
        
            // Word count: The UpdateWordCount() automatically assigns the real time word/character counts to the respective built in properties
            doc.updateWordCount();
            Assert.assertEquals(properties.getWords(), 198);
            Assert.assertEquals(properties.getCharacters(), 1114);
            Assert.assertEquals(properties.getCharactersWithSpaces(), 1310);
        
            // Line count: Count the lines in a document and assign value to the Lines property\
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
            Assert.assertEquals(properties.getLines(), 14);
        
            // Paragraph count: Assign the size of the count of child Paragraph-nodes to the Paragraphs built in property
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(properties.getParagraphs(), 2);
        
            // Bytes: Use a stream to find out the real file size of our document and assign it to the Property
            OutputStream stream = new FileOutputStream(getArtifactsDir() + "Properties.Content.docx");
            doc.save(stream, SaveFormat.DOCX);
        
            // Template: The Template attribute can reflect the filename of the attached template document
            doc.setAttachedTemplate(getMyDir() + "Document.BusinessBrochureTemplate.dot");
            Assert.assertEquals(properties.getTemplate(), "Normal");
            properties.setTemplate(doc.getAttachedTemplate());
        
            // Content status: This is a descriptive field
            properties.setContentStatus("Draft");
        
            // Content type: Upon saving, any value we assign to this field will be overwritten by the MIME type of the output save format
            Assert.assertEquals(properties.getContentType(), "");
        
            // If the document contains links and they are all up to date, we can set this to true
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "Properties.Content.docx");
        }
        
        /// <summary>
        /// Util class that counts the lines in a document
        /// Upon construction, traverses the document's layout entities tree, counting entities of the "Line" type that also contain real text
        /// </summary>
        private static class LineCounter {
            public LineCounter(Document doc) throws Exception {
                mLayoutEnumerator = new LayoutEnumerator(doc);
        
                countLines();
            }
        
            public int getLineCount() {
                return mLineCount;
            }
        
            private void countLines() throws Exception {
                do {
                    if (mLayoutEnumerator.getType() == LayoutEntityType.LINE) {
                        mScanningLineForRealText = true;
                    }
        
                    if (mLayoutEnumerator.moveFirstChild()) {
                        if (mScanningLineForRealText && mLayoutEnumerator.getKind().startsWith("TEXT")) {
                            mLineCount++;
                            mScanningLineForRealText = false;
                        }
                        countLines();
                        mLayoutEnumerator.moveParent();
                    }
                } while (mLayoutEnumerator.moveNext());
            }
        
            private /*final*/ LayoutEnumerator mLayoutEnumerator;
            private int mLineCount;
            private boolean mScanningLineForRealText;
        }
      • getComments/setComments

        public java.lang.String getComments() / public void setComments(java.lang.String value)
        
        Gets or sets the document comments.

        Example:

        Shows how to work with document properties in the "Description" category.
        // Create a blank document
        Document doc = new Document();
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Set the values of some descriptive properties
        // These are metadata that can be glanced at without opening the document in the "Details" or "Content" folder views in Windows Explorer
        // The "Details" view has columns dedicated to these properties
        // Fields such as AUTHOR, SUBJECT, TITLE etc. can be used to display these values inside the document
        properties.setAuthor("John Doe");
        properties.setTitle("John's Document");
        properties.setSubject("My subject");
        properties.setCategory("My category");
        properties.setComments("This is {properties.Author}'s document about {properties.Subject}");
        
        // Tags can be used as keywords and are separated by semicolons
        properties.setKeywords("Tag 1; Tag 2; Tag 3");
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Description
        doc.save(getArtifactsDir() + "Properties.Description.docx");
      • getCompany/setCompany

        public java.lang.String getCompany() / public void setCompany(java.lang.String value)
        
        Gets or sets the company property.

        Example:

        Shows how to work with document properties in the "Origin" category.
        // Open a document
        Document doc = new Document(getMyDir() + "Properties.doc");
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Since this document has been edited and printed in the past, values generated by Microsoft Word will appear here
        // These values can be glanced at by right clicking the file in Windows Explorer, without actually opening the document
        // Fields such as PRINTDATE, EDITTIME etc. can display these values inside the document
        System.out.println(MessageFormat.format("Created using {0}, on {1}", properties.getNameOfApplication(), properties.getCreatedTime()));
        System.out.println(MessageFormat.format("Minutes spent editing: {0}", properties.getTotalEditingTime()));
        System.out.println(MessageFormat.format("Date/time last printed: {0}", properties.getLastPrinted()));
        System.out.println(MessageFormat.format("Template document: {0}", properties.getTemplate()));
        
        // We can set these properties ourselves
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1)/*Property++*/;
        
        // If we plan on programmatically saving the document, we may record some details like this
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Origin
        doc.save(getArtifactsDir() + "Properties.Origin.docx");
      • getContentStatus/setContentStatus

        public java.lang.String getContentStatus() / public void setContentStatus(java.lang.String value)
        
        Gets or sets the ContentStatus of the document.

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception {
            // Open a document with a couple paragraphs of content
            Document doc = new Document(getMyDir() + "Properties.Content.docx");
        
            // The properties we will work with are members of the BuiltInDocumentProperties attribute
            BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
            // By using built in properties,
            // we can treat document statistics such as word/page/character counts as metadata that can be glanced at without opening the document
            // These properties are accessed by right-clicking the file in Windows Explorer and navigating to Properties > Details > Content
            // If we want to display this data inside the document, we can use fields such as NUMPAGES, NUMWORDS, NUMCHARS etc.
            // Also, these values can also be viewed in Microsoft Word by navigating File > Properties > Advanced Properties > Statistics
            // Page count: The PageCount attribute shows the page count in real time and its value can be assigned to the Pages property
            properties.setPages(doc.getPageCount());
            Assert.assertEquals(properties.getPages(), 2);
        
            // Word count: The UpdateWordCount() automatically assigns the real time word/character counts to the respective built in properties
            doc.updateWordCount();
            Assert.assertEquals(properties.getWords(), 198);
            Assert.assertEquals(properties.getCharacters(), 1114);
            Assert.assertEquals(properties.getCharactersWithSpaces(), 1310);
        
            // Line count: Count the lines in a document and assign value to the Lines property\
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
            Assert.assertEquals(properties.getLines(), 14);
        
            // Paragraph count: Assign the size of the count of child Paragraph-nodes to the Paragraphs built in property
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(properties.getParagraphs(), 2);
        
            // Bytes: Use a stream to find out the real file size of our document and assign it to the Property
            OutputStream stream = new FileOutputStream(getArtifactsDir() + "Properties.Content.docx");
            doc.save(stream, SaveFormat.DOCX);
        
            // Template: The Template attribute can reflect the filename of the attached template document
            doc.setAttachedTemplate(getMyDir() + "Document.BusinessBrochureTemplate.dot");
            Assert.assertEquals(properties.getTemplate(), "Normal");
            properties.setTemplate(doc.getAttachedTemplate());
        
            // Content status: This is a descriptive field
            properties.setContentStatus("Draft");
        
            // Content type: Upon saving, any value we assign to this field will be overwritten by the MIME type of the output save format
            Assert.assertEquals(properties.getContentType(), "");
        
            // If the document contains links and they are all up to date, we can set this to true
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "Properties.Content.docx");
        }
        
        /// <summary>
        /// Util class that counts the lines in a document
        /// Upon construction, traverses the document's layout entities tree, counting entities of the "Line" type that also contain real text
        /// </summary>
        private static class LineCounter {
            public LineCounter(Document doc) throws Exception {
                mLayoutEnumerator = new LayoutEnumerator(doc);
        
                countLines();
            }
        
            public int getLineCount() {
                return mLineCount;
            }
        
            private void countLines() throws Exception {
                do {
                    if (mLayoutEnumerator.getType() == LayoutEntityType.LINE) {
                        mScanningLineForRealText = true;
                    }
        
                    if (mLayoutEnumerator.moveFirstChild()) {
                        if (mScanningLineForRealText && mLayoutEnumerator.getKind().startsWith("TEXT")) {
                            mLineCount++;
                            mScanningLineForRealText = false;
                        }
                        countLines();
                        mLayoutEnumerator.moveParent();
                    }
                } while (mLayoutEnumerator.moveNext());
            }
        
            private /*final*/ LayoutEnumerator mLayoutEnumerator;
            private int mLineCount;
            private boolean mScanningLineForRealText;
        }
      • getContentType/setContentType

        public java.lang.String getContentType() / public void setContentType(java.lang.String value)
        
        Gets or sets the ContentStatus of the document.

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception {
            // Open a document with a couple paragraphs of content
            Document doc = new Document(getMyDir() + "Properties.Content.docx");
        
            // The properties we will work with are members of the BuiltInDocumentProperties attribute
            BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
            // By using built in properties,
            // we can treat document statistics such as word/page/character counts as metadata that can be glanced at without opening the document
            // These properties are accessed by right-clicking the file in Windows Explorer and navigating to Properties > Details > Content
            // If we want to display this data inside the document, we can use fields such as NUMPAGES, NUMWORDS, NUMCHARS etc.
            // Also, these values can also be viewed in Microsoft Word by navigating File > Properties > Advanced Properties > Statistics
            // Page count: The PageCount attribute shows the page count in real time and its value can be assigned to the Pages property
            properties.setPages(doc.getPageCount());
            Assert.assertEquals(properties.getPages(), 2);
        
            // Word count: The UpdateWordCount() automatically assigns the real time word/character counts to the respective built in properties
            doc.updateWordCount();
            Assert.assertEquals(properties.getWords(), 198);
            Assert.assertEquals(properties.getCharacters(), 1114);
            Assert.assertEquals(properties.getCharactersWithSpaces(), 1310);
        
            // Line count: Count the lines in a document and assign value to the Lines property\
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
            Assert.assertEquals(properties.getLines(), 14);
        
            // Paragraph count: Assign the size of the count of child Paragraph-nodes to the Paragraphs built in property
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(properties.getParagraphs(), 2);
        
            // Bytes: Use a stream to find out the real file size of our document and assign it to the Property
            OutputStream stream = new FileOutputStream(getArtifactsDir() + "Properties.Content.docx");
            doc.save(stream, SaveFormat.DOCX);
        
            // Template: The Template attribute can reflect the filename of the attached template document
            doc.setAttachedTemplate(getMyDir() + "Document.BusinessBrochureTemplate.dot");
            Assert.assertEquals(properties.getTemplate(), "Normal");
            properties.setTemplate(doc.getAttachedTemplate());
        
            // Content status: This is a descriptive field
            properties.setContentStatus("Draft");
        
            // Content type: Upon saving, any value we assign to this field will be overwritten by the MIME type of the output save format
            Assert.assertEquals(properties.getContentType(), "");
        
            // If the document contains links and they are all up to date, we can set this to true
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "Properties.Content.docx");
        }
        
        /// <summary>
        /// Util class that counts the lines in a document
        /// Upon construction, traverses the document's layout entities tree, counting entities of the "Line" type that also contain real text
        /// </summary>
        private static class LineCounter {
            public LineCounter(Document doc) throws Exception {
                mLayoutEnumerator = new LayoutEnumerator(doc);
        
                countLines();
            }
        
            public int getLineCount() {
                return mLineCount;
            }
        
            private void countLines() throws Exception {
                do {
                    if (mLayoutEnumerator.getType() == LayoutEntityType.LINE) {
                        mScanningLineForRealText = true;
                    }
        
                    if (mLayoutEnumerator.moveFirstChild()) {
                        if (mScanningLineForRealText && mLayoutEnumerator.getKind().startsWith("TEXT")) {
                            mLineCount++;
                            mScanningLineForRealText = false;
                        }
                        countLines();
                        mLayoutEnumerator.moveParent();
                    }
                } while (mLayoutEnumerator.moveNext());
            }
        
            private /*final*/ LayoutEnumerator mLayoutEnumerator;
            private int mLineCount;
            private boolean mScanningLineForRealText;
        }
      • getCount

        public int getCount()
        
        Gets number of items in the collection.

        Example:

        Enumerates through all built-in and custom properties in a document using indexed access.
        String fileName = getMyDir() + "Properties.doc";
        Document doc = new Document(fileName);
        
        System.out.println(MessageFormat.format("1. Document name: {0}", fileName));
        
        System.out.println("2. Built-in Properties");
        for (int i = 0; i < doc.getBuiltInDocumentProperties().getCount(); i++) {
            DocumentProperty docProperty = doc.getBuiltInDocumentProperties().get(i);
            System.out.println(MessageFormat.format("{0}({1}) : {2}", docProperty.getName(), docProperty.getType(), docProperty.getValue()));
        }
        
        System.out.println("3. Custom Properties");
        for (int i = 0; i < doc.getCustomDocumentProperties().getCount(); i++) {
            DocumentProperty docProperty = doc.getCustomDocumentProperties().get(i);
            System.out.println(MessageFormat.format("{0}({1}) : {2}", docProperty.getName(), docProperty.getType(), docProperty.getValue()));
        }
      • getCreatedTime/setCreatedTime

        public java.util.Date getCreatedTime() / public void setCreatedTime(java.util.Date value)
        
        Gets or sets date of the document creation in UTC.

        For documents originated from RTF format this property returns local time of the author's machine at the moment of document creation.

        Aspose.Words does not update this property.

        Example:

        Shows how to work with document properties in the "Origin" category.
        // Open a document
        Document doc = new Document(getMyDir() + "Properties.doc");
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Since this document has been edited and printed in the past, values generated by Microsoft Word will appear here
        // These values can be glanced at by right clicking the file in Windows Explorer, without actually opening the document
        // Fields such as PRINTDATE, EDITTIME etc. can display these values inside the document
        System.out.println(MessageFormat.format("Created using {0}, on {1}", properties.getNameOfApplication(), properties.getCreatedTime()));
        System.out.println(MessageFormat.format("Minutes spent editing: {0}", properties.getTotalEditingTime()));
        System.out.println(MessageFormat.format("Date/time last printed: {0}", properties.getLastPrinted()));
        System.out.println(MessageFormat.format("Template document: {0}", properties.getTemplate()));
        
        // We can set these properties ourselves
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1)/*Property++*/;
        
        // If we plan on programmatically saving the document, we may record some details like this
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Origin
        doc.save(getArtifactsDir() + "Properties.Origin.docx");
      • getHeadingPairs/setHeadingPairs

        public java.lang.Object[] getHeadingPairs() / public void setHeadingPairs(java.lang.Object[] value)
        
        Specifies document headings and their names.

        Every heading pair occupies two elements in this array.

        The first element of the pair is a java.lang.String and specifies the heading name. The second element of the pair is an int and specifies the count of document parts for this heading in the TitlesOfParts property.

        The total sum of counts for all heading pairs in this property must be equal to the number of elements in the TitlesOfParts property.

        Aspose.Words does not update this property.

        Example:

        Shows the relationship between HeadingPairs and TitlesOfParts properties.
        // Open a document that contains entries in the HeadingPairs/TitlesOfParts properties
        Document doc = new Document(getMyDir() + "Properties.HeadingPairs.docx");
        
        // We can find the combined values of these collections in File > Properties > Advanced Properties > Contents tab
        
        // The HeadingPairs property is a collection of <string, int> pairs that determines
        // how many document parts a heading spans over
        Object[] headingPairs = doc.getBuiltInDocumentProperties().getHeadingPairs();
        
        // The TitlesOfParts property contains the names of parts that belong to the above headings
        String[] titlesOfParts = doc.getBuiltInDocumentProperties().getTitlesOfParts();
        See Also:
        TitlesOfParts
      • getHyperlinkBase/setHyperlinkBase

        public java.lang.String getHyperlinkBase() / public void setHyperlinkBase(java.lang.String value)
        
        Specifies the base string used for evaluating relative hyperlinks in this document.

        Aspose.Words does not use this property.

        Example:

        Shows how to store the base part of a hyperlink in the document's properties.
        // Create a blank document and a DocumentBuilder
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a relative hyperlink to "Document.docx", which will open that document when clicked on
        builder.insertHyperlink("Relative hyperlink", "Document.docx", false);
        
        // If we don't have a "Document.docx" in the same folder as the document we are about to save, we will end up with a broken link
        Assert.assertFalse(Files.exists(Paths.get(getArtifactsDir() + "Document.docx")));
        doc.save(getArtifactsDir() + "Properties.HyperlinkBase.BrokenLink.docx");
        
        // We could keep prepending something like 'C:\\users\\...\\data' to every hyperlink we place to remedy this
        // Alternatively, if we know that all our linked files will come from the same folder,
        // we could set a base hyperlink in the document properties, keeping our hyperlinks short
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        Assert.assertTrue(Files.exists(Paths.get(getMyDir() + "Document.docx")));
        properties.setHyperlinkBase(getMyDir());
        
        doc.save(getArtifactsDir() + "Properties.HyperlinkBase.WorkingLink.docx");
      • getKeywords/setKeywords

        public java.lang.String getKeywords() / public void setKeywords(java.lang.String value)
        
        Gets or sets the document keywords.

        Example:

        Shows how to work with document properties in the "Description" category.
        // Create a blank document
        Document doc = new Document();
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Set the values of some descriptive properties
        // These are metadata that can be glanced at without opening the document in the "Details" or "Content" folder views in Windows Explorer
        // The "Details" view has columns dedicated to these properties
        // Fields such as AUTHOR, SUBJECT, TITLE etc. can be used to display these values inside the document
        properties.setAuthor("John Doe");
        properties.setTitle("John's Document");
        properties.setSubject("My subject");
        properties.setCategory("My category");
        properties.setComments("This is {properties.Author}'s document about {properties.Subject}");
        
        // Tags can be used as keywords and are separated by semicolons
        properties.setKeywords("Tag 1; Tag 2; Tag 3");
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Description
        doc.save(getArtifactsDir() + "Properties.Description.docx");
      • getLastPrinted/setLastPrinted

        public java.util.Date getLastPrinted() / public void setLastPrinted(java.util.Date value)
        
        Gets or sets the date when the document was last printed in UTC.

        For documents originated from RTF format this property returns the local time of last print operation.

        If the document was never printed, this property will return DateTime.MinValue.

        Aspose.Words does not update this property.

        Example:

        Shows how to work with document properties in the "Origin" category.
        // Open a document
        Document doc = new Document(getMyDir() + "Properties.doc");
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Since this document has been edited and printed in the past, values generated by Microsoft Word will appear here
        // These values can be glanced at by right clicking the file in Windows Explorer, without actually opening the document
        // Fields such as PRINTDATE, EDITTIME etc. can display these values inside the document
        System.out.println(MessageFormat.format("Created using {0}, on {1}", properties.getNameOfApplication(), properties.getCreatedTime()));
        System.out.println(MessageFormat.format("Minutes spent editing: {0}", properties.getTotalEditingTime()));
        System.out.println(MessageFormat.format("Date/time last printed: {0}", properties.getLastPrinted()));
        System.out.println(MessageFormat.format("Template document: {0}", properties.getTemplate()));
        
        // We can set these properties ourselves
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1)/*Property++*/;
        
        // If we plan on programmatically saving the document, we may record some details like this
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Origin
        doc.save(getArtifactsDir() + "Properties.Origin.docx");
      • getLastSavedBy/setLastSavedBy

        public java.lang.String getLastSavedBy() / public void setLastSavedBy(java.lang.String value)
        
        Gets or sets the name of the last author.

        Aspose.Words does not update this property.

        Example:

        Shows how to work with document properties in the "Origin" category.
        // Open a document
        Document doc = new Document(getMyDir() + "Properties.doc");
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Since this document has been edited and printed in the past, values generated by Microsoft Word will appear here
        // These values can be glanced at by right clicking the file in Windows Explorer, without actually opening the document
        // Fields such as PRINTDATE, EDITTIME etc. can display these values inside the document
        System.out.println(MessageFormat.format("Created using {0}, on {1}", properties.getNameOfApplication(), properties.getCreatedTime()));
        System.out.println(MessageFormat.format("Minutes spent editing: {0}", properties.getTotalEditingTime()));
        System.out.println(MessageFormat.format("Date/time last printed: {0}", properties.getLastPrinted()));
        System.out.println(MessageFormat.format("Template document: {0}", properties.getTemplate()));
        
        // We can set these properties ourselves
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1)/*Property++*/;
        
        // If we plan on programmatically saving the document, we may record some details like this
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Origin
        doc.save(getArtifactsDir() + "Properties.Origin.docx");
      • getLastSavedTime/setLastSavedTime

        public java.util.Date getLastSavedTime() / public void setLastSavedTime(java.util.Date value)
        
        Gets or sets the time of the last save in UTC.

        For documents originated from RTF format this property returns the local time of last save operation.

        Aspose.Words does not update this property.

        Example:

        Shows how to work with document properties in the "Origin" category.
        // Open a document
        Document doc = new Document(getMyDir() + "Properties.doc");
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Since this document has been edited and printed in the past, values generated by Microsoft Word will appear here
        // These values can be glanced at by right clicking the file in Windows Explorer, without actually opening the document
        // Fields such as PRINTDATE, EDITTIME etc. can display these values inside the document
        System.out.println(MessageFormat.format("Created using {0}, on {1}", properties.getNameOfApplication(), properties.getCreatedTime()));
        System.out.println(MessageFormat.format("Minutes spent editing: {0}", properties.getTotalEditingTime()));
        System.out.println(MessageFormat.format("Date/time last printed: {0}", properties.getLastPrinted()));
        System.out.println(MessageFormat.format("Template document: {0}", properties.getTemplate()));
        
        // We can set these properties ourselves
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1)/*Property++*/;
        
        // If we plan on programmatically saving the document, we may record some details like this
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Origin
        doc.save(getArtifactsDir() + "Properties.Origin.docx");
      • getLines/setLines

        public int getLines() / public void setLines(int value)
        
        Represents an estimate of the number of lines in the document.

        Aspose.Words updates this property when you call Document.updateWordCount(boolean).

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception {
            // Open a document with a couple paragraphs of content
            Document doc = new Document(getMyDir() + "Properties.Content.docx");
        
            // The properties we will work with are members of the BuiltInDocumentProperties attribute
            BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
            // By using built in properties,
            // we can treat document statistics such as word/page/character counts as metadata that can be glanced at without opening the document
            // These properties are accessed by right-clicking the file in Windows Explorer and navigating to Properties > Details > Content
            // If we want to display this data inside the document, we can use fields such as NUMPAGES, NUMWORDS, NUMCHARS etc.
            // Also, these values can also be viewed in Microsoft Word by navigating File > Properties > Advanced Properties > Statistics
            // Page count: The PageCount attribute shows the page count in real time and its value can be assigned to the Pages property
            properties.setPages(doc.getPageCount());
            Assert.assertEquals(properties.getPages(), 2);
        
            // Word count: The UpdateWordCount() automatically assigns the real time word/character counts to the respective built in properties
            doc.updateWordCount();
            Assert.assertEquals(properties.getWords(), 198);
            Assert.assertEquals(properties.getCharacters(), 1114);
            Assert.assertEquals(properties.getCharactersWithSpaces(), 1310);
        
            // Line count: Count the lines in a document and assign value to the Lines property\
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
            Assert.assertEquals(properties.getLines(), 14);
        
            // Paragraph count: Assign the size of the count of child Paragraph-nodes to the Paragraphs built in property
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(properties.getParagraphs(), 2);
        
            // Bytes: Use a stream to find out the real file size of our document and assign it to the Property
            OutputStream stream = new FileOutputStream(getArtifactsDir() + "Properties.Content.docx");
            doc.save(stream, SaveFormat.DOCX);
        
            // Template: The Template attribute can reflect the filename of the attached template document
            doc.setAttachedTemplate(getMyDir() + "Document.BusinessBrochureTemplate.dot");
            Assert.assertEquals(properties.getTemplate(), "Normal");
            properties.setTemplate(doc.getAttachedTemplate());
        
            // Content status: This is a descriptive field
            properties.setContentStatus("Draft");
        
            // Content type: Upon saving, any value we assign to this field will be overwritten by the MIME type of the output save format
            Assert.assertEquals(properties.getContentType(), "");
        
            // If the document contains links and they are all up to date, we can set this to true
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "Properties.Content.docx");
        }
        
        /// <summary>
        /// Util class that counts the lines in a document
        /// Upon construction, traverses the document's layout entities tree, counting entities of the "Line" type that also contain real text
        /// </summary>
        private static class LineCounter {
            public LineCounter(Document doc) throws Exception {
                mLayoutEnumerator = new LayoutEnumerator(doc);
        
                countLines();
            }
        
            public int getLineCount() {
                return mLineCount;
            }
        
            private void countLines() throws Exception {
                do {
                    if (mLayoutEnumerator.getType() == LayoutEntityType.LINE) {
                        mScanningLineForRealText = true;
                    }
        
                    if (mLayoutEnumerator.moveFirstChild()) {
                        if (mScanningLineForRealText && mLayoutEnumerator.getKind().startsWith("TEXT")) {
                            mLineCount++;
                            mScanningLineForRealText = false;
                        }
                        countLines();
                        mLayoutEnumerator.moveParent();
                    }
                } while (mLayoutEnumerator.moveNext());
            }
        
            private /*final*/ LayoutEnumerator mLayoutEnumerator;
            private int mLineCount;
            private boolean mScanningLineForRealText;
        }
      • getLinksUpToDate/setLinksUpToDate

        public boolean getLinksUpToDate() / public void setLinksUpToDate(boolean value)
        
        Indicates whether hyperlinks in a document are up-to-date.

        Aspose.Words does not update this property.

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception {
            // Open a document with a couple paragraphs of content
            Document doc = new Document(getMyDir() + "Properties.Content.docx");
        
            // The properties we will work with are members of the BuiltInDocumentProperties attribute
            BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
            // By using built in properties,
            // we can treat document statistics such as word/page/character counts as metadata that can be glanced at without opening the document
            // These properties are accessed by right-clicking the file in Windows Explorer and navigating to Properties > Details > Content
            // If we want to display this data inside the document, we can use fields such as NUMPAGES, NUMWORDS, NUMCHARS etc.
            // Also, these values can also be viewed in Microsoft Word by navigating File > Properties > Advanced Properties > Statistics
            // Page count: The PageCount attribute shows the page count in real time and its value can be assigned to the Pages property
            properties.setPages(doc.getPageCount());
            Assert.assertEquals(properties.getPages(), 2);
        
            // Word count: The UpdateWordCount() automatically assigns the real time word/character counts to the respective built in properties
            doc.updateWordCount();
            Assert.assertEquals(properties.getWords(), 198);
            Assert.assertEquals(properties.getCharacters(), 1114);
            Assert.assertEquals(properties.getCharactersWithSpaces(), 1310);
        
            // Line count: Count the lines in a document and assign value to the Lines property\
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
            Assert.assertEquals(properties.getLines(), 14);
        
            // Paragraph count: Assign the size of the count of child Paragraph-nodes to the Paragraphs built in property
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(properties.getParagraphs(), 2);
        
            // Bytes: Use a stream to find out the real file size of our document and assign it to the Property
            OutputStream stream = new FileOutputStream(getArtifactsDir() + "Properties.Content.docx");
            doc.save(stream, SaveFormat.DOCX);
        
            // Template: The Template attribute can reflect the filename of the attached template document
            doc.setAttachedTemplate(getMyDir() + "Document.BusinessBrochureTemplate.dot");
            Assert.assertEquals(properties.getTemplate(), "Normal");
            properties.setTemplate(doc.getAttachedTemplate());
        
            // Content status: This is a descriptive field
            properties.setContentStatus("Draft");
        
            // Content type: Upon saving, any value we assign to this field will be overwritten by the MIME type of the output save format
            Assert.assertEquals(properties.getContentType(), "");
        
            // If the document contains links and they are all up to date, we can set this to true
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "Properties.Content.docx");
        }
        
        /// <summary>
        /// Util class that counts the lines in a document
        /// Upon construction, traverses the document's layout entities tree, counting entities of the "Line" type that also contain real text
        /// </summary>
        private static class LineCounter {
            public LineCounter(Document doc) throws Exception {
                mLayoutEnumerator = new LayoutEnumerator(doc);
        
                countLines();
            }
        
            public int getLineCount() {
                return mLineCount;
            }
        
            private void countLines() throws Exception {
                do {
                    if (mLayoutEnumerator.getType() == LayoutEntityType.LINE) {
                        mScanningLineForRealText = true;
                    }
        
                    if (mLayoutEnumerator.moveFirstChild()) {
                        if (mScanningLineForRealText && mLayoutEnumerator.getKind().startsWith("TEXT")) {
                            mLineCount++;
                            mScanningLineForRealText = false;
                        }
                        countLines();
                        mLayoutEnumerator.moveParent();
                    }
                } while (mLayoutEnumerator.moveNext());
            }
        
            private /*final*/ LayoutEnumerator mLayoutEnumerator;
            private int mLineCount;
            private boolean mScanningLineForRealText;
        }
      • getManager/setManager

        public java.lang.String getManager() / public void setManager(java.lang.String value)
        
        Gets or sets the manager property.

        Example:

        Shows how to work with document properties in the "Origin" category.
        // Open a document
        Document doc = new Document(getMyDir() + "Properties.doc");
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Since this document has been edited and printed in the past, values generated by Microsoft Word will appear here
        // These values can be glanced at by right clicking the file in Windows Explorer, without actually opening the document
        // Fields such as PRINTDATE, EDITTIME etc. can display these values inside the document
        System.out.println(MessageFormat.format("Created using {0}, on {1}", properties.getNameOfApplication(), properties.getCreatedTime()));
        System.out.println(MessageFormat.format("Minutes spent editing: {0}", properties.getTotalEditingTime()));
        System.out.println(MessageFormat.format("Date/time last printed: {0}", properties.getLastPrinted()));
        System.out.println(MessageFormat.format("Template document: {0}", properties.getTemplate()));
        
        // We can set these properties ourselves
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1)/*Property++*/;
        
        // If we plan on programmatically saving the document, we may record some details like this
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Origin
        doc.save(getArtifactsDir() + "Properties.Origin.docx");
      • getNameOfApplication/setNameOfApplication

        public java.lang.String getNameOfApplication() / public void setNameOfApplication(java.lang.String value)
        
        Gets or sets the name of the application.

        Example:

        Shows how to work with document properties in the "Origin" category.
        // Open a document
        Document doc = new Document(getMyDir() + "Properties.doc");
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Since this document has been edited and printed in the past, values generated by Microsoft Word will appear here
        // These values can be glanced at by right clicking the file in Windows Explorer, without actually opening the document
        // Fields such as PRINTDATE, EDITTIME etc. can display these values inside the document
        System.out.println(MessageFormat.format("Created using {0}, on {1}", properties.getNameOfApplication(), properties.getCreatedTime()));
        System.out.println(MessageFormat.format("Minutes spent editing: {0}", properties.getTotalEditingTime()));
        System.out.println(MessageFormat.format("Date/time last printed: {0}", properties.getLastPrinted()));
        System.out.println(MessageFormat.format("Template document: {0}", properties.getTemplate()));
        
        // We can set these properties ourselves
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1)/*Property++*/;
        
        // If we plan on programmatically saving the document, we may record some details like this
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Origin
        doc.save(getArtifactsDir() + "Properties.Origin.docx");
      • getPages/setPages

        public int getPages() / public void setPages(int value)
        
        Represents an estimate of the number of pages in the document.

        Aspose.Words updates this property when you call Document.updatePageLayout().

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception {
            // Open a document with a couple paragraphs of content
            Document doc = new Document(getMyDir() + "Properties.Content.docx");
        
            // The properties we will work with are members of the BuiltInDocumentProperties attribute
            BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
            // By using built in properties,
            // we can treat document statistics such as word/page/character counts as metadata that can be glanced at without opening the document
            // These properties are accessed by right-clicking the file in Windows Explorer and navigating to Properties > Details > Content
            // If we want to display this data inside the document, we can use fields such as NUMPAGES, NUMWORDS, NUMCHARS etc.
            // Also, these values can also be viewed in Microsoft Word by navigating File > Properties > Advanced Properties > Statistics
            // Page count: The PageCount attribute shows the page count in real time and its value can be assigned to the Pages property
            properties.setPages(doc.getPageCount());
            Assert.assertEquals(properties.getPages(), 2);
        
            // Word count: The UpdateWordCount() automatically assigns the real time word/character counts to the respective built in properties
            doc.updateWordCount();
            Assert.assertEquals(properties.getWords(), 198);
            Assert.assertEquals(properties.getCharacters(), 1114);
            Assert.assertEquals(properties.getCharactersWithSpaces(), 1310);
        
            // Line count: Count the lines in a document and assign value to the Lines property\
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
            Assert.assertEquals(properties.getLines(), 14);
        
            // Paragraph count: Assign the size of the count of child Paragraph-nodes to the Paragraphs built in property
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(properties.getParagraphs(), 2);
        
            // Bytes: Use a stream to find out the real file size of our document and assign it to the Property
            OutputStream stream = new FileOutputStream(getArtifactsDir() + "Properties.Content.docx");
            doc.save(stream, SaveFormat.DOCX);
        
            // Template: The Template attribute can reflect the filename of the attached template document
            doc.setAttachedTemplate(getMyDir() + "Document.BusinessBrochureTemplate.dot");
            Assert.assertEquals(properties.getTemplate(), "Normal");
            properties.setTemplate(doc.getAttachedTemplate());
        
            // Content status: This is a descriptive field
            properties.setContentStatus("Draft");
        
            // Content type: Upon saving, any value we assign to this field will be overwritten by the MIME type of the output save format
            Assert.assertEquals(properties.getContentType(), "");
        
            // If the document contains links and they are all up to date, we can set this to true
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "Properties.Content.docx");
        }
        
        /// <summary>
        /// Util class that counts the lines in a document
        /// Upon construction, traverses the document's layout entities tree, counting entities of the "Line" type that also contain real text
        /// </summary>
        private static class LineCounter {
            public LineCounter(Document doc) throws Exception {
                mLayoutEnumerator = new LayoutEnumerator(doc);
        
                countLines();
            }
        
            public int getLineCount() {
                return mLineCount;
            }
        
            private void countLines() throws Exception {
                do {
                    if (mLayoutEnumerator.getType() == LayoutEntityType.LINE) {
                        mScanningLineForRealText = true;
                    }
        
                    if (mLayoutEnumerator.moveFirstChild()) {
                        if (mScanningLineForRealText && mLayoutEnumerator.getKind().startsWith("TEXT")) {
                            mLineCount++;
                            mScanningLineForRealText = false;
                        }
                        countLines();
                        mLayoutEnumerator.moveParent();
                    }
                } while (mLayoutEnumerator.moveNext());
            }
        
            private /*final*/ LayoutEnumerator mLayoutEnumerator;
            private int mLineCount;
            private boolean mScanningLineForRealText;
        }
      • getParagraphs/setParagraphs

        public int getParagraphs() / public void setParagraphs(int value)
        
        Represents an estimate of the number of paragraphs in the document.

        Aspose.Words updates this property when you call Document.updateWordCount().

        Example:

        Shows how to update all list labels in a document.
        Document doc = new Document(getMyDir() + "Document.doc");
        
        // Some work should be done here that changes the document's content.
        
        // Update the word, character and paragraph count of the document.
        doc.updateWordCount();
        
        // Display the updated document properties.
        System.out.println(MessageFormat.format("Characters: {0}", doc.getBuiltInDocumentProperties().getCharacters()));
        System.out.println(MessageFormat.format("Words: {0}", doc.getBuiltInDocumentProperties().getWords()));
        System.out.println(MessageFormat.format("Paragraphs: {0}", doc.getBuiltInDocumentProperties().getParagraphs()));

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception {
            // Open a document with a couple paragraphs of content
            Document doc = new Document(getMyDir() + "Properties.Content.docx");
        
            // The properties we will work with are members of the BuiltInDocumentProperties attribute
            BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
            // By using built in properties,
            // we can treat document statistics such as word/page/character counts as metadata that can be glanced at without opening the document
            // These properties are accessed by right-clicking the file in Windows Explorer and navigating to Properties > Details > Content
            // If we want to display this data inside the document, we can use fields such as NUMPAGES, NUMWORDS, NUMCHARS etc.
            // Also, these values can also be viewed in Microsoft Word by navigating File > Properties > Advanced Properties > Statistics
            // Page count: The PageCount attribute shows the page count in real time and its value can be assigned to the Pages property
            properties.setPages(doc.getPageCount());
            Assert.assertEquals(properties.getPages(), 2);
        
            // Word count: The UpdateWordCount() automatically assigns the real time word/character counts to the respective built in properties
            doc.updateWordCount();
            Assert.assertEquals(properties.getWords(), 198);
            Assert.assertEquals(properties.getCharacters(), 1114);
            Assert.assertEquals(properties.getCharactersWithSpaces(), 1310);
        
            // Line count: Count the lines in a document and assign value to the Lines property\
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
            Assert.assertEquals(properties.getLines(), 14);
        
            // Paragraph count: Assign the size of the count of child Paragraph-nodes to the Paragraphs built in property
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(properties.getParagraphs(), 2);
        
            // Bytes: Use a stream to find out the real file size of our document and assign it to the Property
            OutputStream stream = new FileOutputStream(getArtifactsDir() + "Properties.Content.docx");
            doc.save(stream, SaveFormat.DOCX);
        
            // Template: The Template attribute can reflect the filename of the attached template document
            doc.setAttachedTemplate(getMyDir() + "Document.BusinessBrochureTemplate.dot");
            Assert.assertEquals(properties.getTemplate(), "Normal");
            properties.setTemplate(doc.getAttachedTemplate());
        
            // Content status: This is a descriptive field
            properties.setContentStatus("Draft");
        
            // Content type: Upon saving, any value we assign to this field will be overwritten by the MIME type of the output save format
            Assert.assertEquals(properties.getContentType(), "");
        
            // If the document contains links and they are all up to date, we can set this to true
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "Properties.Content.docx");
        }
        
        /// <summary>
        /// Util class that counts the lines in a document
        /// Upon construction, traverses the document's layout entities tree, counting entities of the "Line" type that also contain real text
        /// </summary>
        private static class LineCounter {
            public LineCounter(Document doc) throws Exception {
                mLayoutEnumerator = new LayoutEnumerator(doc);
        
                countLines();
            }
        
            public int getLineCount() {
                return mLineCount;
            }
        
            private void countLines() throws Exception {
                do {
                    if (mLayoutEnumerator.getType() == LayoutEntityType.LINE) {
                        mScanningLineForRealText = true;
                    }
        
                    if (mLayoutEnumerator.moveFirstChild()) {
                        if (mScanningLineForRealText && mLayoutEnumerator.getKind().startsWith("TEXT")) {
                            mLineCount++;
                            mScanningLineForRealText = false;
                        }
                        countLines();
                        mLayoutEnumerator.moveParent();
                    }
                } while (mLayoutEnumerator.moveNext());
            }
        
            private /*final*/ LayoutEnumerator mLayoutEnumerator;
            private int mLineCount;
            private boolean mScanningLineForRealText;
        }
      • getRevisionNumber/setRevisionNumber

        public int getRevisionNumber() / public void setRevisionNumber(int value)
        
        Gets or sets the document revision number.

        Aspose.Words does not update this property.

        Example:

        Shows how to work with document properties in the "Origin" category.
        // Open a document
        Document doc = new Document(getMyDir() + "Properties.doc");
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Since this document has been edited and printed in the past, values generated by Microsoft Word will appear here
        // These values can be glanced at by right clicking the file in Windows Explorer, without actually opening the document
        // Fields such as PRINTDATE, EDITTIME etc. can display these values inside the document
        System.out.println(MessageFormat.format("Created using {0}, on {1}", properties.getNameOfApplication(), properties.getCreatedTime()));
        System.out.println(MessageFormat.format("Minutes spent editing: {0}", properties.getTotalEditingTime()));
        System.out.println(MessageFormat.format("Date/time last printed: {0}", properties.getLastPrinted()));
        System.out.println(MessageFormat.format("Template document: {0}", properties.getTemplate()));
        
        // We can set these properties ourselves
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1)/*Property++*/;
        
        // If we plan on programmatically saving the document, we may record some details like this
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Origin
        doc.save(getArtifactsDir() + "Properties.Origin.docx");
      • getSecurity/setSecurity

        public int getSecurity() / public void setSecurity(int value)
        
        Specifies the security level of a document as a numeric value. The value of the property is DocumentSecurity integer constant.

        Use this property for informational purposes only because Microsoft Word does not always set this property. This property is available in DOC and OOXML documents only.

        To protect or unprotect a document use the Document.protect(int,java.lang.String) and Document.unprotect() methods.

        Aspose.Words updates this property to a correct value before saving a document.

        Example:

        Shows how to use document properties to display the security level of a document.
        // Create a blank document, which has no security of any kind by default
        Document doc = new Document();
        
        // The "Security" property serves as a description of the security level of a document
        Assert.assertEquals(doc.getBuiltInDocumentProperties().getSecurity(), DocumentSecurity.NONE);
        
        // Upon saving a document after setting its security level, Aspose automatically updates this property to the appropriate value
        doc.getWriteProtection().setReadOnlyRecommended(true);
        doc.save(getArtifactsDir() + "Properties.Security.ReadOnlyRecommended.docx");
        
        // We can open a document and glance at its security level like this
        Assert.assertEquals(new Document(getArtifactsDir() + "Properties.Security.ReadOnlyRecommended.docx").getBuiltInDocumentProperties().getSecurity(),
                DocumentSecurity.READ_ONLY_RECOMMENDED);
        
        // Create a new document and set it to Write-Protected
        doc = new Document();
        
        Assert.assertFalse(doc.getWriteProtection().isWriteProtected());
        doc.getWriteProtection().setPassword("MyPassword");
        Assert.assertTrue(doc.getWriteProtection().validatePassword("MyPassword"));
        Assert.assertTrue(doc.getWriteProtection().isWriteProtected());
        doc.save(getArtifactsDir() + "Properties.Security.ReadOnlyEnforced.docx");
        
        // This document's security level counts as "ReadOnlyEnforced"
        Assert.assertEquals(new Document(getArtifactsDir() + "Properties.Security.ReadOnlyEnforced.docx").getBuiltInDocumentProperties().getSecurity(),
                DocumentSecurity.READ_ONLY_ENFORCED);
        
        // Since this is still a descriptive property, we can protect a document and pick a suitable value ourselves
        doc = new Document();
        
        doc.protect(ProtectionType.ALLOW_ONLY_COMMENTS, "MyPassword");
        doc.getBuiltInDocumentProperties().setSecurity(DocumentSecurity.READ_ONLY_EXCEPT_ANNOTATIONS);
        doc.save(getArtifactsDir() + "Properties.Security.ReadOnlyExceptAnnotations.docx");
        
        Assert.assertEquals(new Document(getArtifactsDir() + "Properties.Security.ReadOnlyExceptAnnotations.docx").getBuiltInDocumentProperties().getSecurity(),
                DocumentSecurity.READ_ONLY_EXCEPT_ANNOTATIONS);
      • getSubject/setSubject

        public java.lang.String getSubject() / public void setSubject(java.lang.String value)
        
        Gets or sets the subject of the document.

        Example:

        Shows how to work with document properties in the "Description" category.
        // Create a blank document
        Document doc = new Document();
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Set the values of some descriptive properties
        // These are metadata that can be glanced at without opening the document in the "Details" or "Content" folder views in Windows Explorer
        // The "Details" view has columns dedicated to these properties
        // Fields such as AUTHOR, SUBJECT, TITLE etc. can be used to display these values inside the document
        properties.setAuthor("John Doe");
        properties.setTitle("John's Document");
        properties.setSubject("My subject");
        properties.setCategory("My category");
        properties.setComments("This is {properties.Author}'s document about {properties.Subject}");
        
        // Tags can be used as keywords and are separated by semicolons
        properties.setKeywords("Tag 1; Tag 2; Tag 3");
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Description
        doc.save(getArtifactsDir() + "Properties.Description.docx");
      • getTemplate/setTemplate

        public java.lang.String getTemplate() / public void setTemplate(java.lang.String value)
        
        Gets or sets the informational name of the document template.

        In Microsoft Word, this property is for informational purposes only and usually contains only the file name of the template without the path.

        Empty string means the document is attached to the Normal template.

        To get or set the actual name of the attached template, use the Document.AttachedTemplate property.

        Example:

        Shows how to work with document properties in the "Origin" category.
        // Open a document
        Document doc = new Document(getMyDir() + "Properties.doc");
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Since this document has been edited and printed in the past, values generated by Microsoft Word will appear here
        // These values can be glanced at by right clicking the file in Windows Explorer, without actually opening the document
        // Fields such as PRINTDATE, EDITTIME etc. can display these values inside the document
        System.out.println(MessageFormat.format("Created using {0}, on {1}", properties.getNameOfApplication(), properties.getCreatedTime()));
        System.out.println(MessageFormat.format("Minutes spent editing: {0}", properties.getTotalEditingTime()));
        System.out.println(MessageFormat.format("Date/time last printed: {0}", properties.getLastPrinted()));
        System.out.println(MessageFormat.format("Template document: {0}", properties.getTemplate()));
        
        // We can set these properties ourselves
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1)/*Property++*/;
        
        // If we plan on programmatically saving the document, we may record some details like this
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Origin
        doc.save(getArtifactsDir() + "Properties.Origin.docx");
        See Also:
        Document.AttachedTemplate
      • getThumbnail/setThumbnail

        public byte[] getThumbnail() / public void setThumbnail(byte[] value)
        

        Gets or sets the thumbnail of the document.

        For now this property is used only when a document is being exported to ePub, it's not read from and written to other document formats.

        Image of arbitrary format can be set to this property, but the format is checked during export. System.InvalidOperationException is thrown if the image is invalid or its format is unsupported for specific format of document.

        Only gif, jpeg and png images can be used for ePub publication.

        Example:

        Shows how to append a thumbnail to an Epub document.
        // Create a blank document and add some text with a DocumentBuilder
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Hello world!");
        
        // The thumbnail property resides in a document's built in properties, but is used exclusively by Epub e-book documents
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Load an image from our file system into a byte array
        byte[] thumbnailBytes = Files.readAllBytes(Paths.get(getImageDir() + "Aspose.Words.gif"));
        
        // Set the value of the Thumbnail property to the array from above
        properties.setThumbnail(thumbnailBytes);
        
        // Our thumbnail should be visible at the start of the document, before the text we added
        doc.save(getArtifactsDir() + "Properties.Thumbnail.epub");
        
        // We can also extract a thumbnail property into a byte array and then into the local file system like this
        DocumentProperty thumbnail = doc.getBuiltInDocumentProperties().get("Thumbnail");
        Files.write(Paths.get(getArtifactsDir() + "Properties.Thumbnail.gif"), thumbnail.toByteArray());
      • getTitle/setTitle

        public java.lang.String getTitle() / public void setTitle(java.lang.String value)
        
        Gets or sets the title of the document.

        Example:

        Shows how to work with document properties in the "Description" category.
        // Create a blank document
        Document doc = new Document();
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Set the values of some descriptive properties
        // These are metadata that can be glanced at without opening the document in the "Details" or "Content" folder views in Windows Explorer
        // The "Details" view has columns dedicated to these properties
        // Fields such as AUTHOR, SUBJECT, TITLE etc. can be used to display these values inside the document
        properties.setAuthor("John Doe");
        properties.setTitle("John's Document");
        properties.setSubject("My subject");
        properties.setCategory("My category");
        properties.setComments("This is {properties.Author}'s document about {properties.Subject}");
        
        // Tags can be used as keywords and are separated by semicolons
        properties.setKeywords("Tag 1; Tag 2; Tag 3");
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Description
        doc.save(getArtifactsDir() + "Properties.Description.docx");
      • getTitlesOfParts/setTitlesOfParts

        public java.lang.String[] getTitlesOfParts() / public void setTitlesOfParts(java.lang.String[] value)
        
        Each string in the array specifies the name of a part in the document.

        Aspose.Words does not update this property.

        Example:

        Shows the relationship between HeadingPairs and TitlesOfParts properties.
        // Open a document that contains entries in the HeadingPairs/TitlesOfParts properties
        Document doc = new Document(getMyDir() + "Properties.HeadingPairs.docx");
        
        // We can find the combined values of these collections in File > Properties > Advanced Properties > Contents tab
        
        // The HeadingPairs property is a collection of <string, int> pairs that determines
        // how many document parts a heading spans over
        Object[] headingPairs = doc.getBuiltInDocumentProperties().getHeadingPairs();
        
        // The TitlesOfParts property contains the names of parts that belong to the above headings
        String[] titlesOfParts = doc.getBuiltInDocumentProperties().getTitlesOfParts();
        See Also:
        HeadingPairs
      • getTotalEditingTime/setTotalEditingTime

        public int getTotalEditingTime() / public void setTotalEditingTime(int value)
        
        Gets or sets the total editing time in minutes.

        Example:

        Shows how to work with document properties in the "Origin" category.
        // Open a document
        Document doc = new Document(getMyDir() + "Properties.doc");
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Since this document has been edited and printed in the past, values generated by Microsoft Word will appear here
        // These values can be glanced at by right clicking the file in Windows Explorer, without actually opening the document
        // Fields such as PRINTDATE, EDITTIME etc. can display these values inside the document
        System.out.println(MessageFormat.format("Created using {0}, on {1}", properties.getNameOfApplication(), properties.getCreatedTime()));
        System.out.println(MessageFormat.format("Minutes spent editing: {0}", properties.getTotalEditingTime()));
        System.out.println(MessageFormat.format("Date/time last printed: {0}", properties.getLastPrinted()));
        System.out.println(MessageFormat.format("Template document: {0}", properties.getTemplate()));
        
        // We can set these properties ourselves
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1)/*Property++*/;
        
        // If we plan on programmatically saving the document, we may record some details like this
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Origin
        doc.save(getArtifactsDir() + "Properties.Origin.docx");
      • getVersion/setVersion

        public int getVersion() / public void setVersion(int value)
        
        Represents the version number of the application that created the document.

        When a document was created by Microsoft Word, then high 16 bit represent the major version and low 16 bit represent the build number.

        Example:

        Shows how to work with document properties in the "Origin" category.
        // Open a document
        Document doc = new Document(getMyDir() + "Properties.doc");
        
        // The properties we will work with are members of the BuiltInDocumentProperties attribute
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Since this document has been edited and printed in the past, values generated by Microsoft Word will appear here
        // These values can be glanced at by right clicking the file in Windows Explorer, without actually opening the document
        // Fields such as PRINTDATE, EDITTIME etc. can display these values inside the document
        System.out.println(MessageFormat.format("Created using {0}, on {1}", properties.getNameOfApplication(), properties.getCreatedTime()));
        System.out.println(MessageFormat.format("Minutes spent editing: {0}", properties.getTotalEditingTime()));
        System.out.println(MessageFormat.format("Date/time last printed: {0}", properties.getLastPrinted()));
        System.out.println(MessageFormat.format("Template document: {0}", properties.getTemplate()));
        
        // We can set these properties ourselves
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1)/*Property++*/;
        
        // If we plan on programmatically saving the document, we may record some details like this
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // When right clicking the document file in Windows Explorer, these properties are found in Properties > Details > Origin
        doc.save(getArtifactsDir() + "Properties.Origin.docx");
      • getWords/setWords

        public int getWords() / public void setWords(int value)
        
        Represents an estimate of the number of words in the document.

        Aspose.Words updates this property when you call Document.updateWordCount().

        Example:

        Shows how to update all list labels in a document.
        Document doc = new Document(getMyDir() + "Document.doc");
        
        // Some work should be done here that changes the document's content.
        
        // Update the word, character and paragraph count of the document.
        doc.updateWordCount();
        
        // Display the updated document properties.
        System.out.println(MessageFormat.format("Characters: {0}", doc.getBuiltInDocumentProperties().getCharacters()));
        System.out.println(MessageFormat.format("Words: {0}", doc.getBuiltInDocumentProperties().getWords()));
        System.out.println(MessageFormat.format("Paragraphs: {0}", doc.getBuiltInDocumentProperties().getParagraphs()));

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception {
            // Open a document with a couple paragraphs of content
            Document doc = new Document(getMyDir() + "Properties.Content.docx");
        
            // The properties we will work with are members of the BuiltInDocumentProperties attribute
            BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
            // By using built in properties,
            // we can treat document statistics such as word/page/character counts as metadata that can be glanced at without opening the document
            // These properties are accessed by right-clicking the file in Windows Explorer and navigating to Properties > Details > Content
            // If we want to display this data inside the document, we can use fields such as NUMPAGES, NUMWORDS, NUMCHARS etc.
            // Also, these values can also be viewed in Microsoft Word by navigating File > Properties > Advanced Properties > Statistics
            // Page count: The PageCount attribute shows the page count in real time and its value can be assigned to the Pages property
            properties.setPages(doc.getPageCount());
            Assert.assertEquals(properties.getPages(), 2);
        
            // Word count: The UpdateWordCount() automatically assigns the real time word/character counts to the respective built in properties
            doc.updateWordCount();
            Assert.assertEquals(properties.getWords(), 198);
            Assert.assertEquals(properties.getCharacters(), 1114);
            Assert.assertEquals(properties.getCharactersWithSpaces(), 1310);
        
            // Line count: Count the lines in a document and assign value to the Lines property\
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
            Assert.assertEquals(properties.getLines(), 14);
        
            // Paragraph count: Assign the size of the count of child Paragraph-nodes to the Paragraphs built in property
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(properties.getParagraphs(), 2);
        
            // Bytes: Use a stream to find out the real file size of our document and assign it to the Property
            OutputStream stream = new FileOutputStream(getArtifactsDir() + "Properties.Content.docx");
            doc.save(stream, SaveFormat.DOCX);
        
            // Template: The Template attribute can reflect the filename of the attached template document
            doc.setAttachedTemplate(getMyDir() + "Document.BusinessBrochureTemplate.dot");
            Assert.assertEquals(properties.getTemplate(), "Normal");
            properties.setTemplate(doc.getAttachedTemplate());
        
            // Content status: This is a descriptive field
            properties.setContentStatus("Draft");
        
            // Content type: Upon saving, any value we assign to this field will be overwritten by the MIME type of the output save format
            Assert.assertEquals(properties.getContentType(), "");
        
            // If the document contains links and they are all up to date, we can set this to true
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "Properties.Content.docx");
        }
        
        /// <summary>
        /// Util class that counts the lines in a document
        /// Upon construction, traverses the document's layout entities tree, counting entities of the "Line" type that also contain real text
        /// </summary>
        private static class LineCounter {
            public LineCounter(Document doc) throws Exception {
                mLayoutEnumerator = new LayoutEnumerator(doc);
        
                countLines();
            }
        
            public int getLineCount() {
                return mLineCount;
            }
        
            private void countLines() throws Exception {
                do {
                    if (mLayoutEnumerator.getType() == LayoutEntityType.LINE) {
                        mScanningLineForRealText = true;
                    }
        
                    if (mLayoutEnumerator.moveFirstChild()) {
                        if (mScanningLineForRealText && mLayoutEnumerator.getKind().startsWith("TEXT")) {
                            mLineCount++;
                            mScanningLineForRealText = false;
                        }
                        countLines();
                        mLayoutEnumerator.moveParent();
                    }
                } while (mLayoutEnumerator.moveNext());
            }
        
            private /*final*/ LayoutEnumerator mLayoutEnumerator;
            private int mLineCount;
            private boolean mScanningLineForRealText;
        }
      • get

        public DocumentProperty get(int index)
        
        Returns a DocumentProperty object by index.

        Note: In Java this method is slow because iterates over all nodes.

        Parameters:
        index - Zero-based index of the DocumentProperty to retrieve.

        Example:

        Enumerates through all built-in and custom properties in a document using indexed access.
        String fileName = getMyDir() + "Properties.doc";
        Document doc = new Document(fileName);
        
        System.out.println(MessageFormat.format("1. Document name: {0}", fileName));
        
        System.out.println("2. Built-in Properties");
        for (int i = 0; i < doc.getBuiltInDocumentProperties().getCount(); i++) {
            DocumentProperty docProperty = doc.getBuiltInDocumentProperties().get(i);
            System.out.println(MessageFormat.format("{0}({1}) : {2}", docProperty.getName(), docProperty.getType(), docProperty.getValue()));
        }
        
        System.out.println("3. Custom Properties");
        for (int i = 0; i < doc.getCustomDocumentProperties().getCount(); i++) {
            DocumentProperty docProperty = doc.getCustomDocumentProperties().get(i);
            System.out.println(MessageFormat.format("{0}({1}) : {2}", docProperty.getName(), docProperty.getType(), docProperty.getValue()));
        }
      • get

        public DocumentProperty get(java.lang.String name)
        
        Returns a DocumentProperty object by the name of the property.

        The string names of the properties correspond to the names of the typed properties available from BuiltInDocumentProperties.

        If you request a property that is not present in the document, but the name of the property is recognized as a valid built-in name, a new DocumentProperty is created, added to the collection and returned. The newly created property is assigned a default value (empty string, zero, false or DateTime.MinValue depending on the type of the built-in property).

        If you request a property that is not present in the document and the name is not recognized as a built-in name, a null is returned.

        Parameters:
        name - The case-insensitive name of the property to retrieve.

        Example:

        Retrieves a built-in document property by name.
        Document doc = new Document(getMyDir() + "Properties.doc");
        
        DocumentProperty docProperty = doc.getBuiltInDocumentProperties().get("Keywords");
        System.out.println(docProperty.toString());
    • Method Detail

      • clear

        public void clear()
        Removes all properties from the collection.

        Example:

        Shows how to add custom properties to a document.
        // Create a blank document and get its custom property collection
        Document doc = new Document();
        CustomDocumentProperties properties = doc.getCustomDocumentProperties();
        
        // The collection will be empty by default
        Assert.assertEquals(properties.getCount(), 0);
        
        // We can populate it with key/value pairs with a variety of value types
        properties.add("Authorized", true);
        properties.add("Authorized By", "John Doe");
        properties.add("Authorized Date", new Date());
        properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
        properties.add("Authorized Amount", 123.45);
        
        // Custom properties are automatically sorted in alphabetic order
        Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
        Assert.assertEquals(properties.getCount(), 5);
        
        // Enumerate and print all custom properties
        Iterator<DocumentProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                DocumentProperty property = enumerator.next();
                System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
        doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");
        
        // We can remove elements from the property collection by index or by name
        properties.removeAt(1);
        Assert.assertFalse(properties.contains("Authorized Amount"));
        Assert.assertEquals(properties.getCount(), 4);
        
        properties.remove("Authorized Revision");
        Assert.assertFalse(properties.contains("Authorized Revision"));
        Assert.assertEquals(properties.getCount(), 3);
        
        // We can also empty the entire custom property collection at once
        properties.clear();
        Assert.assertEquals(properties.getCount(), 0);
      • contains

        public boolean contains(java.lang.String name)
        Returns true if a property with the specified name exists in the collection.
        Parameters:
        name - The case-insensitive name of the property.
        Returns:
        True if the property exists in the collection; false otherwise.

        Example:

        Shows how to add custom properties to a document.
        // Create a blank document and get its custom property collection
        Document doc = new Document();
        CustomDocumentProperties properties = doc.getCustomDocumentProperties();
        
        // The collection will be empty by default
        Assert.assertEquals(properties.getCount(), 0);
        
        // We can populate it with key/value pairs with a variety of value types
        properties.add("Authorized", true);
        properties.add("Authorized By", "John Doe");
        properties.add("Authorized Date", new Date());
        properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
        properties.add("Authorized Amount", 123.45);
        
        // Custom properties are automatically sorted in alphabetic order
        Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
        Assert.assertEquals(properties.getCount(), 5);
        
        // Enumerate and print all custom properties
        Iterator<DocumentProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                DocumentProperty property = enumerator.next();
                System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
        doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");
        
        // We can remove elements from the property collection by index or by name
        properties.removeAt(1);
        Assert.assertFalse(properties.contains("Authorized Amount"));
        Assert.assertEquals(properties.getCount(), 4);
        
        properties.remove("Authorized Revision");
        Assert.assertFalse(properties.contains("Authorized Revision"));
        Assert.assertEquals(properties.getCount(), 3);
        
        // We can also empty the entire custom property collection at once
        properties.clear();
        Assert.assertEquals(properties.getCount(), 0);
      • indexOf

        public int indexOf(java.lang.String name)
        Gets the index of a property by name.

        Note: In Java this method is slow because iterates over all nodes.

        Parameters:
        name - The case-insensitive name of the property.
        Returns:
        The zero based index. Negative value if not found.

        Example:

        Shows how to add custom properties to a document.
        // Create a blank document and get its custom property collection
        Document doc = new Document();
        CustomDocumentProperties properties = doc.getCustomDocumentProperties();
        
        // The collection will be empty by default
        Assert.assertEquals(properties.getCount(), 0);
        
        // We can populate it with key/value pairs with a variety of value types
        properties.add("Authorized", true);
        properties.add("Authorized By", "John Doe");
        properties.add("Authorized Date", new Date());
        properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
        properties.add("Authorized Amount", 123.45);
        
        // Custom properties are automatically sorted in alphabetic order
        Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
        Assert.assertEquals(properties.getCount(), 5);
        
        // Enumerate and print all custom properties
        Iterator<DocumentProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                DocumentProperty property = enumerator.next();
                System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
        doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");
        
        // We can remove elements from the property collection by index or by name
        properties.removeAt(1);
        Assert.assertFalse(properties.contains("Authorized Amount"));
        Assert.assertEquals(properties.getCount(), 4);
        
        properties.remove("Authorized Revision");
        Assert.assertFalse(properties.contains("Authorized Revision"));
        Assert.assertEquals(properties.getCount(), 3);
        
        // We can also empty the entire custom property collection at once
        properties.clear();
        Assert.assertEquals(properties.getCount(), 0);
      • iterator

        public java.util.Iterator<DocumentProperty> iterator()
        Returns an iterator object that can be used to iterate over all items in the collection.

        Example:

        Shows how to add custom properties to a document.
        // Create a blank document and get its custom property collection
        Document doc = new Document();
        CustomDocumentProperties properties = doc.getCustomDocumentProperties();
        
        // The collection will be empty by default
        Assert.assertEquals(properties.getCount(), 0);
        
        // We can populate it with key/value pairs with a variety of value types
        properties.add("Authorized", true);
        properties.add("Authorized By", "John Doe");
        properties.add("Authorized Date", new Date());
        properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
        properties.add("Authorized Amount", 123.45);
        
        // Custom properties are automatically sorted in alphabetic order
        Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
        Assert.assertEquals(properties.getCount(), 5);
        
        // Enumerate and print all custom properties
        Iterator<DocumentProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                DocumentProperty property = enumerator.next();
                System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
        doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");
        
        // We can remove elements from the property collection by index or by name
        properties.removeAt(1);
        Assert.assertFalse(properties.contains("Authorized Amount"));
        Assert.assertEquals(properties.getCount(), 4);
        
        properties.remove("Authorized Revision");
        Assert.assertFalse(properties.contains("Authorized Revision"));
        Assert.assertEquals(properties.getCount(), 3);
        
        // We can also empty the entire custom property collection at once
        properties.clear();
        Assert.assertEquals(properties.getCount(), 0);
      • remove

        public void remove(java.lang.String name)
        Removes a property with the specified name from the collection.
        Parameters:
        name - The case-insensitive name of the property.

        Example:

        Shows how to add custom properties to a document.
        // Create a blank document and get its custom property collection
        Document doc = new Document();
        CustomDocumentProperties properties = doc.getCustomDocumentProperties();
        
        // The collection will be empty by default
        Assert.assertEquals(properties.getCount(), 0);
        
        // We can populate it with key/value pairs with a variety of value types
        properties.add("Authorized", true);
        properties.add("Authorized By", "John Doe");
        properties.add("Authorized Date", new Date());
        properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
        properties.add("Authorized Amount", 123.45);
        
        // Custom properties are automatically sorted in alphabetic order
        Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
        Assert.assertEquals(properties.getCount(), 5);
        
        // Enumerate and print all custom properties
        Iterator<DocumentProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                DocumentProperty property = enumerator.next();
                System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
        doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");
        
        // We can remove elements from the property collection by index or by name
        properties.removeAt(1);
        Assert.assertFalse(properties.contains("Authorized Amount"));
        Assert.assertEquals(properties.getCount(), 4);
        
        properties.remove("Authorized Revision");
        Assert.assertFalse(properties.contains("Authorized Revision"));
        Assert.assertEquals(properties.getCount(), 3);
        
        // We can also empty the entire custom property collection at once
        properties.clear();
        Assert.assertEquals(properties.getCount(), 0);
      • removeAt

        public void removeAt(int index)
        Removes a property at the specified index.

        Note: In Java this method is slow because iterates over all nodes.

        Parameters:
        index - The zero based index.

        Example:

        Shows how to add custom properties to a document.
        // Create a blank document and get its custom property collection
        Document doc = new Document();
        CustomDocumentProperties properties = doc.getCustomDocumentProperties();
        
        // The collection will be empty by default
        Assert.assertEquals(properties.getCount(), 0);
        
        // We can populate it with key/value pairs with a variety of value types
        properties.add("Authorized", true);
        properties.add("Authorized By", "John Doe");
        properties.add("Authorized Date", new Date());
        properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
        properties.add("Authorized Amount", 123.45);
        
        // Custom properties are automatically sorted in alphabetic order
        Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
        Assert.assertEquals(properties.getCount(), 5);
        
        // Enumerate and print all custom properties
        Iterator<DocumentProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                DocumentProperty property = enumerator.next();
                System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
        doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");
        
        // We can remove elements from the property collection by index or by name
        properties.removeAt(1);
        Assert.assertFalse(properties.contains("Authorized Amount"));
        Assert.assertEquals(properties.getCount(), 4);
        
        properties.remove("Authorized Revision");
        Assert.assertFalse(properties.contains("Authorized Revision"));
        Assert.assertEquals(properties.getCount(), 3);
        
        // We can also empty the entire custom property collection at once
        properties.clear();
        Assert.assertEquals(properties.getCount(), 0);