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.

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 built-in document properties in the "Description" category.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Below are four built-in document properties that have fields that can display their values in the document body.
        // 1 -  "Author" property, which we can display using an AUTHOR field:
        properties.setAuthor("John Doe");
        builder.write("Author:\t");
        builder.insertField(FieldType.FIELD_AUTHOR, true);
        
        // 2 -  "Title" property, which we can display using a TITLE field:
        properties.setTitle("John's Document");
        builder.write("\nDoc title:\t");
        builder.insertField(FieldType.FIELD_TITLE, true);
        
        // 3 -  "Subject" property, which we can display using a SUBJECT field:
        properties.setSubject("My subject");
        builder.write("\nSubject:\t");
        builder.insertField(FieldType.FIELD_SUBJECT, true);
        
        // 4 -  "Comments" property, which we can display using a COMMENTS field:
        properties.setComments(MessageFormat.format("This is {0}'s document about {1}", properties.getAuthor(), properties.getSubject()));
        builder.write("\nComments:\t\"");
        builder.insertField(FieldType.FIELD_COMMENTS, true);
        builder.write("\"");
        
        // The "Category" built-in property does not have a field that can display its value.
        properties.setCategory("My category");
        
        // We can set multiple keywords for a document by separating the string value of the "Keywords" property with semicolons.
        properties.setKeywords("Tag 1; Tag 2; Tag 3");
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details".
        // The "Author" built-in property is in the "Origin" group, and the others are in the "Description" group.
        doc.save(getArtifactsDir() + "DocumentProperties.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
        {
            Document doc = new Document(getMyDir() + "Paragraphs.docx");
            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
        
            // The "Pages" property stores the page count of the document. 
            Assert.assertEquals(6, properties.getPages());
        
            // The "Words", "Characters", and "CharactersWithSpaces" built-in properties also display various document statistics,
            // but we need to call the "UpdateWordCount" method on the whole document before we can expect them to contain accurate values.
            doc.updateWordCount();
        
            Assert.assertEquals(1035, properties.getWords());
            Assert.assertEquals(6026, properties.getCharacters());
            Assert.assertEquals(7041, properties.getCharactersWithSpaces());
        
            // Count the number of lines in the document, and then assign the result to the "Lines" built-in property.
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
        
            Assert.assertEquals(142, properties.getLines());
        
            // Assign the number of Paragraph nodes in the document to the "Paragraphs" built-in property.
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(29, properties.getParagraphs());
        
            // Get an estimate of the file size of our document via the "Bytes" built-in property.
            Assert.assertEquals(20310, properties.getBytes());
        
            // Set a different template for our document, and then update the "Template" built-in property manually to reflect this change.
            doc.setAttachedTemplate(getMyDir() + "Business brochure.dotx");
        
            Assert.assertEquals("Normal", properties.getTemplate());    
        
            properties.setTemplate(doc.getAttachedTemplate());
        
            // "ContentStatus" is a descriptive built-in property.
            properties.setContentStatus("Draft");
        
            // Upon saving, the "ContentType" built-in property will contain 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 the "LinksUpToDate" property to "true".
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "DocumentProperties.Content.docx");
        }
        
        /// <summary>
        /// Counts the lines in a document.
        /// Traverses the document's layout entities tree upon construction,
        /// 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 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 built-in document properties in the "Description" category.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Below are four built-in document properties that have fields that can display their values in the document body.
        // 1 -  "Author" property, which we can display using an AUTHOR field:
        properties.setAuthor("John Doe");
        builder.write("Author:\t");
        builder.insertField(FieldType.FIELD_AUTHOR, true);
        
        // 2 -  "Title" property, which we can display using a TITLE field:
        properties.setTitle("John's Document");
        builder.write("\nDoc title:\t");
        builder.insertField(FieldType.FIELD_TITLE, true);
        
        // 3 -  "Subject" property, which we can display using a SUBJECT field:
        properties.setSubject("My subject");
        builder.write("\nSubject:\t");
        builder.insertField(FieldType.FIELD_SUBJECT, true);
        
        // 4 -  "Comments" property, which we can display using a COMMENTS field:
        properties.setComments(MessageFormat.format("This is {0}'s document about {1}", properties.getAuthor(), properties.getSubject()));
        builder.write("\nComments:\t\"");
        builder.insertField(FieldType.FIELD_COMMENTS, true);
        builder.write("\"");
        
        // The "Category" built-in property does not have a field that can display its value.
        properties.setCategory("My category");
        
        // We can set multiple keywords for a document by separating the string value of the "Keywords" property with semicolons.
        properties.setKeywords("Tag 1; Tag 2; Tag 3");
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details".
        // The "Author" built-in property is in the "Origin" group, and the others are in the "Description" group.
        doc.save(getArtifactsDir() + "DocumentProperties.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();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " +
                "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
        builder.write("Ut enim ad minim veniam, " +
                "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.");
        
        // Aspose.Words does not track document metrics like these in real time.
        Assert.assertEquals(0, doc.getBuiltInDocumentProperties().getCharacters());
        Assert.assertEquals(0, doc.getBuiltInDocumentProperties().getWords());
        Assert.assertEquals(1, doc.getBuiltInDocumentProperties().getParagraphs());
        Assert.assertEquals(1, doc.getBuiltInDocumentProperties().getLines());
        
        // To get accurate values for three of these properties, we will need to update them manually.
        doc.updateWordCount();
        
        Assert.assertEquals(196, doc.getBuiltInDocumentProperties().getCharacters());
        Assert.assertEquals(36, doc.getBuiltInDocumentProperties().getWords());
        Assert.assertEquals(2, doc.getBuiltInDocumentProperties().getParagraphs());
        
        // For the line count, we will need to call a specific overload of the updating method.
        Assert.assertEquals(1, doc.getBuiltInDocumentProperties().getLines());
        
        doc.updateWordCount(true);
        
        Assert.assertEquals(4, doc.getBuiltInDocumentProperties().getLines());

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception
        {
            Document doc = new Document(getMyDir() + "Paragraphs.docx");
            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
        
            // The "Pages" property stores the page count of the document. 
            Assert.assertEquals(6, properties.getPages());
        
            // The "Words", "Characters", and "CharactersWithSpaces" built-in properties also display various document statistics,
            // but we need to call the "UpdateWordCount" method on the whole document before we can expect them to contain accurate values.
            doc.updateWordCount();
        
            Assert.assertEquals(1035, properties.getWords());
            Assert.assertEquals(6026, properties.getCharacters());
            Assert.assertEquals(7041, properties.getCharactersWithSpaces());
        
            // Count the number of lines in the document, and then assign the result to the "Lines" built-in property.
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
        
            Assert.assertEquals(142, properties.getLines());
        
            // Assign the number of Paragraph nodes in the document to the "Paragraphs" built-in property.
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(29, properties.getParagraphs());
        
            // Get an estimate of the file size of our document via the "Bytes" built-in property.
            Assert.assertEquals(20310, properties.getBytes());
        
            // Set a different template for our document, and then update the "Template" built-in property manually to reflect this change.
            doc.setAttachedTemplate(getMyDir() + "Business brochure.dotx");
        
            Assert.assertEquals("Normal", properties.getTemplate());    
        
            properties.setTemplate(doc.getAttachedTemplate());
        
            // "ContentStatus" is a descriptive built-in property.
            properties.setContentStatus("Draft");
        
            // Upon saving, the "ContentType" built-in property will contain 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 the "LinksUpToDate" property to "true".
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "DocumentProperties.Content.docx");
        }
        
        /// <summary>
        /// Counts the lines in a document.
        /// Traverses the document's layout entities tree upon construction,
        /// 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 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
        {
            Document doc = new Document(getMyDir() + "Paragraphs.docx");
            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
        
            // The "Pages" property stores the page count of the document. 
            Assert.assertEquals(6, properties.getPages());
        
            // The "Words", "Characters", and "CharactersWithSpaces" built-in properties also display various document statistics,
            // but we need to call the "UpdateWordCount" method on the whole document before we can expect them to contain accurate values.
            doc.updateWordCount();
        
            Assert.assertEquals(1035, properties.getWords());
            Assert.assertEquals(6026, properties.getCharacters());
            Assert.assertEquals(7041, properties.getCharactersWithSpaces());
        
            // Count the number of lines in the document, and then assign the result to the "Lines" built-in property.
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
        
            Assert.assertEquals(142, properties.getLines());
        
            // Assign the number of Paragraph nodes in the document to the "Paragraphs" built-in property.
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(29, properties.getParagraphs());
        
            // Get an estimate of the file size of our document via the "Bytes" built-in property.
            Assert.assertEquals(20310, properties.getBytes());
        
            // Set a different template for our document, and then update the "Template" built-in property manually to reflect this change.
            doc.setAttachedTemplate(getMyDir() + "Business brochure.dotx");
        
            Assert.assertEquals("Normal", properties.getTemplate());    
        
            properties.setTemplate(doc.getAttachedTemplate());
        
            // "ContentStatus" is a descriptive built-in property.
            properties.setContentStatus("Draft");
        
            // Upon saving, the "ContentType" built-in property will contain 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 the "LinksUpToDate" property to "true".
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "DocumentProperties.Content.docx");
        }
        
        /// <summary>
        /// Counts the lines in a document.
        /// Traverses the document's layout entities tree upon construction,
        /// 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 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 built-in document properties in the "Description" category.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Below are four built-in document properties that have fields that can display their values in the document body.
        // 1 -  "Author" property, which we can display using an AUTHOR field:
        properties.setAuthor("John Doe");
        builder.write("Author:\t");
        builder.insertField(FieldType.FIELD_AUTHOR, true);
        
        // 2 -  "Title" property, which we can display using a TITLE field:
        properties.setTitle("John's Document");
        builder.write("\nDoc title:\t");
        builder.insertField(FieldType.FIELD_TITLE, true);
        
        // 3 -  "Subject" property, which we can display using a SUBJECT field:
        properties.setSubject("My subject");
        builder.write("\nSubject:\t");
        builder.insertField(FieldType.FIELD_SUBJECT, true);
        
        // 4 -  "Comments" property, which we can display using a COMMENTS field:
        properties.setComments(MessageFormat.format("This is {0}'s document about {1}", properties.getAuthor(), properties.getSubject()));
        builder.write("\nComments:\t\"");
        builder.insertField(FieldType.FIELD_COMMENTS, true);
        builder.write("\"");
        
        // The "Category" built-in property does not have a field that can display its value.
        properties.setCategory("My category");
        
        // We can set multiple keywords for a document by separating the string value of the "Keywords" property with semicolons.
        properties.setKeywords("Tag 1; Tag 2; Tag 3");
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details".
        // The "Author" built-in property is in the "Origin" group, and the others are in the "Description" group.
        doc.save(getArtifactsDir() + "DocumentProperties.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 that we have created and edited using Microsoft Word.
        Document doc = new Document(getMyDir() + "Properties.docx");
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // The following built-in properties contain information regarding the creation and editing of this document.
        // We can right-click this document in Windows Explorer and find
        // these properties via "Properties" -> "Details" -> "Origin" category.
        // Fields such as PRINTDATE and EDITTIME can display these values in the document body.
        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 also change the values of built-in properties.
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1);
        
        // Microsoft Word updates the following properties automatically when we save the document.
        // To use these properties with Aspose.Words, we will need to set values for them manually.
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details" -> "Origin".
        doc.save(getArtifactsDir() + "DocumentProperties.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
        {
            Document doc = new Document(getMyDir() + "Paragraphs.docx");
            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
        
            // The "Pages" property stores the page count of the document. 
            Assert.assertEquals(6, properties.getPages());
        
            // The "Words", "Characters", and "CharactersWithSpaces" built-in properties also display various document statistics,
            // but we need to call the "UpdateWordCount" method on the whole document before we can expect them to contain accurate values.
            doc.updateWordCount();
        
            Assert.assertEquals(1035, properties.getWords());
            Assert.assertEquals(6026, properties.getCharacters());
            Assert.assertEquals(7041, properties.getCharactersWithSpaces());
        
            // Count the number of lines in the document, and then assign the result to the "Lines" built-in property.
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
        
            Assert.assertEquals(142, properties.getLines());
        
            // Assign the number of Paragraph nodes in the document to the "Paragraphs" built-in property.
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(29, properties.getParagraphs());
        
            // Get an estimate of the file size of our document via the "Bytes" built-in property.
            Assert.assertEquals(20310, properties.getBytes());
        
            // Set a different template for our document, and then update the "Template" built-in property manually to reflect this change.
            doc.setAttachedTemplate(getMyDir() + "Business brochure.dotx");
        
            Assert.assertEquals("Normal", properties.getTemplate());    
        
            properties.setTemplate(doc.getAttachedTemplate());
        
            // "ContentStatus" is a descriptive built-in property.
            properties.setContentStatus("Draft");
        
            // Upon saving, the "ContentType" built-in property will contain 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 the "LinksUpToDate" property to "true".
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "DocumentProperties.Content.docx");
        }
        
        /// <summary>
        /// Counts the lines in a document.
        /// Traverses the document's layout entities tree upon construction,
        /// 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 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
        {
            Document doc = new Document(getMyDir() + "Paragraphs.docx");
            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
        
            // The "Pages" property stores the page count of the document. 
            Assert.assertEquals(6, properties.getPages());
        
            // The "Words", "Characters", and "CharactersWithSpaces" built-in properties also display various document statistics,
            // but we need to call the "UpdateWordCount" method on the whole document before we can expect them to contain accurate values.
            doc.updateWordCount();
        
            Assert.assertEquals(1035, properties.getWords());
            Assert.assertEquals(6026, properties.getCharacters());
            Assert.assertEquals(7041, properties.getCharactersWithSpaces());
        
            // Count the number of lines in the document, and then assign the result to the "Lines" built-in property.
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
        
            Assert.assertEquals(142, properties.getLines());
        
            // Assign the number of Paragraph nodes in the document to the "Paragraphs" built-in property.
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(29, properties.getParagraphs());
        
            // Get an estimate of the file size of our document via the "Bytes" built-in property.
            Assert.assertEquals(20310, properties.getBytes());
        
            // Set a different template for our document, and then update the "Template" built-in property manually to reflect this change.
            doc.setAttachedTemplate(getMyDir() + "Business brochure.dotx");
        
            Assert.assertEquals("Normal", properties.getTemplate());    
        
            properties.setTemplate(doc.getAttachedTemplate());
        
            // "ContentStatus" is a descriptive built-in property.
            properties.setContentStatus("Draft");
        
            // Upon saving, the "ContentType" built-in property will contain 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 the "LinksUpToDate" property to "true".
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "DocumentProperties.Content.docx");
        }
        
        /// <summary>
        /// Counts the lines in a document.
        /// Traverses the document's layout entities tree upon construction,
        /// 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 LayoutEnumerator mLayoutEnumerator;
            private int mLineCount;
            private boolean mScanningLineForRealText;
        }
      • getCount

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

        Example:

        Shows how to work with custom document properties.
        Document doc = new Document(getMyDir() + "Properties.docx");
        
        // Every document contains a collection of custom properties, which, like the built-in properties, are key-value pairs.
        // Unlike the built-in properties, many of which the document maintains by itself, we need to create all of our own custom properties. 
        Assert.assertEquals("Value of custom document property", doc.getCustomDocumentProperties().get("CustomProperty").toString());
        
        doc.getCustomDocumentProperties().add("CustomProperty2", "Value of custom document property #2");
        
        System.out.println("Custom Properties:");
        for (DocumentProperty customDocumentProperty : doc.getCustomDocumentProperties())
        {
            System.out.println(customDocumentProperty.getName());
            System.out.println(MessageFormat.format("\tType:\t{0}", customDocumentProperty.getType()));
            System.out.println(MessageFormat.format("\tValue:\t\"{0}\"", customDocumentProperty.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 that we have created and edited using Microsoft Word.
        Document doc = new Document(getMyDir() + "Properties.docx");
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // The following built-in properties contain information regarding the creation and editing of this document.
        // We can right-click this document in Windows Explorer and find
        // these properties via "Properties" -> "Details" -> "Origin" category.
        // Fields such as PRINTDATE and EDITTIME can display these values in the document body.
        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 also change the values of built-in properties.
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1);
        
        // Microsoft Word updates the following properties automatically when we save the document.
        // To use these properties with Aspose.Words, we will need to set values for them manually.
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details" -> "Origin".
        doc.save(getArtifactsDir() + "DocumentProperties.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.
        Document doc = new Document(getMyDir() + "Heading pairs and titles of parts.docx");
        
        // We can find the combined values of these collections via "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 across.
        Object[] headingPairs = doc.getBuiltInDocumentProperties().getHeadingPairs();
        
        // The TitlesOfParts property contains the names of parts that belong to the above headings.
        String[] titlesOfParts = doc.getBuiltInDocumentProperties().getTitlesOfParts();
        
        int headingPairsIndex = 0;
        int titlesOfPartsIndex = 0;
        while (headingPairsIndex < headingPairs.length)
        {
            System.out.println(MessageFormat.format("Parts for {0}:", headingPairs[headingPairsIndex++]));
            int partsCount = (int)headingPairs[headingPairsIndex++];
        
            for (int i = 0; i < partsCount; i++)
                System.out.println(MessageFormat.format("\t\"{0}\"", titlesOfParts[titlesOfPartsIndex++]));
        }
        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.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a relative hyperlink to a document in the local file system named "Document.docx".
        // When we click the link in Microsoft Word, it will open the designated document, provided that it is available.
        builder.insertHyperlink("Relative hyperlink", "Document.docx", false);
        
        // This link is relative. If there is no "Document.docx" in the same folder
        // as the document that contains this link, the link will be broken.
        Assert.assertFalse(new File(getArtifactsDir() + "Document.docx").exists());
        doc.save(getArtifactsDir() + "DocumentProperties.HyperlinkBase.BrokenLink.docx");
        
        // The document we are trying to link to is in a different directory to the one we are planning to save the document in.
        // We could fix links like this by putting an absolute filename in each one. 
        // Alternatively, we could provide a base link that every hyperlink with a relative filename
        // will prepend to its link when we click on it. 
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        properties.setHyperlinkBase(getMyDir());
        
        Assert.assertTrue(new File(properties.getHyperlinkBase() + ((FieldHyperlink)doc.getRange().getFields().get(0)).getAddress()).exists());
        
        doc.save(getArtifactsDir() + "DocumentProperties.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 built-in document properties in the "Description" category.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Below are four built-in document properties that have fields that can display their values in the document body.
        // 1 -  "Author" property, which we can display using an AUTHOR field:
        properties.setAuthor("John Doe");
        builder.write("Author:\t");
        builder.insertField(FieldType.FIELD_AUTHOR, true);
        
        // 2 -  "Title" property, which we can display using a TITLE field:
        properties.setTitle("John's Document");
        builder.write("\nDoc title:\t");
        builder.insertField(FieldType.FIELD_TITLE, true);
        
        // 3 -  "Subject" property, which we can display using a SUBJECT field:
        properties.setSubject("My subject");
        builder.write("\nSubject:\t");
        builder.insertField(FieldType.FIELD_SUBJECT, true);
        
        // 4 -  "Comments" property, which we can display using a COMMENTS field:
        properties.setComments(MessageFormat.format("This is {0}'s document about {1}", properties.getAuthor(), properties.getSubject()));
        builder.write("\nComments:\t\"");
        builder.insertField(FieldType.FIELD_COMMENTS, true);
        builder.write("\"");
        
        // The "Category" built-in property does not have a field that can display its value.
        properties.setCategory("My category");
        
        // We can set multiple keywords for a document by separating the string value of the "Keywords" property with semicolons.
        properties.setKeywords("Tag 1; Tag 2; Tag 3");
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details".
        // The "Author" built-in property is in the "Origin" group, and the others are in the "Description" group.
        doc.save(getArtifactsDir() + "DocumentProperties.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 that we have created and edited using Microsoft Word.
        Document doc = new Document(getMyDir() + "Properties.docx");
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // The following built-in properties contain information regarding the creation and editing of this document.
        // We can right-click this document in Windows Explorer and find
        // these properties via "Properties" -> "Details" -> "Origin" category.
        // Fields such as PRINTDATE and EDITTIME can display these values in the document body.
        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 also change the values of built-in properties.
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1);
        
        // Microsoft Word updates the following properties automatically when we save the document.
        // To use these properties with Aspose.Words, we will need to set values for them manually.
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details" -> "Origin".
        doc.save(getArtifactsDir() + "DocumentProperties.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 that we have created and edited using Microsoft Word.
        Document doc = new Document(getMyDir() + "Properties.docx");
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // The following built-in properties contain information regarding the creation and editing of this document.
        // We can right-click this document in Windows Explorer and find
        // these properties via "Properties" -> "Details" -> "Origin" category.
        // Fields such as PRINTDATE and EDITTIME can display these values in the document body.
        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 also change the values of built-in properties.
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1);
        
        // Microsoft Word updates the following properties automatically when we save the document.
        // To use these properties with Aspose.Words, we will need to set values for them manually.
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details" -> "Origin".
        doc.save(getArtifactsDir() + "DocumentProperties.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 that we have created and edited using Microsoft Word.
        Document doc = new Document(getMyDir() + "Properties.docx");
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // The following built-in properties contain information regarding the creation and editing of this document.
        // We can right-click this document in Windows Explorer and find
        // these properties via "Properties" -> "Details" -> "Origin" category.
        // Fields such as PRINTDATE and EDITTIME can display these values in the document body.
        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 also change the values of built-in properties.
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1);
        
        // Microsoft Word updates the following properties automatically when we save the document.
        // To use these properties with Aspose.Words, we will need to set values for them manually.
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details" -> "Origin".
        doc.save(getArtifactsDir() + "DocumentProperties.Origin.docx");

        Example:

        Shows how to use the SAVEDATE field to display the date/time of the document's most recent save operation performed using Microsoft Word.
        Document doc = new Document(getMyDir() + "Document.docx");
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.moveToDocumentEnd();
        builder.writeln(" Date this document was last saved:");
        
        // We can use the SAVEDATE field to display the last save operation's date and time on the document.
        // The save operation that these fields refer to is the manual save in an application like Microsoft Word,
        // not the document's Save method.
        // Below are three different calendar types according to which the SAVEDATE field can display the date/time.
        // 1 -  Islamic Lunar Calendar:
        builder.write("According to the Lunar Calendar - ");
        FieldSaveDate field = (FieldSaveDate) builder.insertField(FieldType.FIELD_SAVE_DATE, true);
        field.setUseLunarCalendar(true);
        
        Assert.assertEquals(" SAVEDATE  \\h", field.getFieldCode());
        
        // 2 -  Umm al-Qura calendar:
        builder.write("\nAccording to the Umm al-Qura calendar - ");
        field = (FieldSaveDate) builder.insertField(FieldType.FIELD_SAVE_DATE, true);
        field.setUseUmAlQuraCalendar(true);
        
        Assert.assertEquals(" SAVEDATE  \\u", field.getFieldCode());
        
        // 3 -  Indian National calendar:
        builder.write("\nAccording to the Indian National calendar - ");
        field = (FieldSaveDate) builder.insertField(FieldType.FIELD_SAVE_DATE, true);
        field.setUseSakaEraCalendar(true);
        
        Assert.assertEquals(" SAVEDATE  \\s", field.getFieldCode());
        
        // The SAVEDATE fields draw their date/time values from the LastSavedTime built-in property.
        // The document's Save method will not update this value, but we can still update it manually.
        doc.getBuiltInDocumentProperties().setLastSavedTime(new Date());
        
        doc.updateFields();
        doc.save(getArtifactsDir() + "Field.SAVEDATE.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 update all list labels in a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " +
                "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
        builder.write("Ut enim ad minim veniam, " +
                "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.");
        
        // Aspose.Words does not track document metrics like these in real time.
        Assert.assertEquals(0, doc.getBuiltInDocumentProperties().getCharacters());
        Assert.assertEquals(0, doc.getBuiltInDocumentProperties().getWords());
        Assert.assertEquals(1, doc.getBuiltInDocumentProperties().getParagraphs());
        Assert.assertEquals(1, doc.getBuiltInDocumentProperties().getLines());
        
        // To get accurate values for three of these properties, we will need to update them manually.
        doc.updateWordCount();
        
        Assert.assertEquals(196, doc.getBuiltInDocumentProperties().getCharacters());
        Assert.assertEquals(36, doc.getBuiltInDocumentProperties().getWords());
        Assert.assertEquals(2, doc.getBuiltInDocumentProperties().getParagraphs());
        
        // For the line count, we will need to call a specific overload of the updating method.
        Assert.assertEquals(1, doc.getBuiltInDocumentProperties().getLines());
        
        doc.updateWordCount(true);
        
        Assert.assertEquals(4, doc.getBuiltInDocumentProperties().getLines());

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception
        {
            Document doc = new Document(getMyDir() + "Paragraphs.docx");
            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
        
            // The "Pages" property stores the page count of the document. 
            Assert.assertEquals(6, properties.getPages());
        
            // The "Words", "Characters", and "CharactersWithSpaces" built-in properties also display various document statistics,
            // but we need to call the "UpdateWordCount" method on the whole document before we can expect them to contain accurate values.
            doc.updateWordCount();
        
            Assert.assertEquals(1035, properties.getWords());
            Assert.assertEquals(6026, properties.getCharacters());
            Assert.assertEquals(7041, properties.getCharactersWithSpaces());
        
            // Count the number of lines in the document, and then assign the result to the "Lines" built-in property.
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
        
            Assert.assertEquals(142, properties.getLines());
        
            // Assign the number of Paragraph nodes in the document to the "Paragraphs" built-in property.
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(29, properties.getParagraphs());
        
            // Get an estimate of the file size of our document via the "Bytes" built-in property.
            Assert.assertEquals(20310, properties.getBytes());
        
            // Set a different template for our document, and then update the "Template" built-in property manually to reflect this change.
            doc.setAttachedTemplate(getMyDir() + "Business brochure.dotx");
        
            Assert.assertEquals("Normal", properties.getTemplate());    
        
            properties.setTemplate(doc.getAttachedTemplate());
        
            // "ContentStatus" is a descriptive built-in property.
            properties.setContentStatus("Draft");
        
            // Upon saving, the "ContentType" built-in property will contain 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 the "LinksUpToDate" property to "true".
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "DocumentProperties.Content.docx");
        }
        
        /// <summary>
        /// Counts the lines in a document.
        /// Traverses the document's layout entities tree upon construction,
        /// 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 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
        {
            Document doc = new Document(getMyDir() + "Paragraphs.docx");
            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
        
            // The "Pages" property stores the page count of the document. 
            Assert.assertEquals(6, properties.getPages());
        
            // The "Words", "Characters", and "CharactersWithSpaces" built-in properties also display various document statistics,
            // but we need to call the "UpdateWordCount" method on the whole document before we can expect them to contain accurate values.
            doc.updateWordCount();
        
            Assert.assertEquals(1035, properties.getWords());
            Assert.assertEquals(6026, properties.getCharacters());
            Assert.assertEquals(7041, properties.getCharactersWithSpaces());
        
            // Count the number of lines in the document, and then assign the result to the "Lines" built-in property.
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
        
            Assert.assertEquals(142, properties.getLines());
        
            // Assign the number of Paragraph nodes in the document to the "Paragraphs" built-in property.
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(29, properties.getParagraphs());
        
            // Get an estimate of the file size of our document via the "Bytes" built-in property.
            Assert.assertEquals(20310, properties.getBytes());
        
            // Set a different template for our document, and then update the "Template" built-in property manually to reflect this change.
            doc.setAttachedTemplate(getMyDir() + "Business brochure.dotx");
        
            Assert.assertEquals("Normal", properties.getTemplate());    
        
            properties.setTemplate(doc.getAttachedTemplate());
        
            // "ContentStatus" is a descriptive built-in property.
            properties.setContentStatus("Draft");
        
            // Upon saving, the "ContentType" built-in property will contain 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 the "LinksUpToDate" property to "true".
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "DocumentProperties.Content.docx");
        }
        
        /// <summary>
        /// Counts the lines in a document.
        /// Traverses the document's layout entities tree upon construction,
        /// 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 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 that we have created and edited using Microsoft Word.
        Document doc = new Document(getMyDir() + "Properties.docx");
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // The following built-in properties contain information regarding the creation and editing of this document.
        // We can right-click this document in Windows Explorer and find
        // these properties via "Properties" -> "Details" -> "Origin" category.
        // Fields such as PRINTDATE and EDITTIME can display these values in the document body.
        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 also change the values of built-in properties.
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1);
        
        // Microsoft Word updates the following properties automatically when we save the document.
        // To use these properties with Aspose.Words, we will need to set values for them manually.
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details" -> "Origin".
        doc.save(getArtifactsDir() + "DocumentProperties.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 that we have created and edited using Microsoft Word.
        Document doc = new Document(getMyDir() + "Properties.docx");
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // The following built-in properties contain information regarding the creation and editing of this document.
        // We can right-click this document in Windows Explorer and find
        // these properties via "Properties" -> "Details" -> "Origin" category.
        // Fields such as PRINTDATE and EDITTIME can display these values in the document body.
        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 also change the values of built-in properties.
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1);
        
        // Microsoft Word updates the following properties automatically when we save the document.
        // To use these properties with Aspose.Words, we will need to set values for them manually.
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details" -> "Origin".
        doc.save(getArtifactsDir() + "DocumentProperties.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
        {
            Document doc = new Document(getMyDir() + "Paragraphs.docx");
            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
        
            // The "Pages" property stores the page count of the document. 
            Assert.assertEquals(6, properties.getPages());
        
            // The "Words", "Characters", and "CharactersWithSpaces" built-in properties also display various document statistics,
            // but we need to call the "UpdateWordCount" method on the whole document before we can expect them to contain accurate values.
            doc.updateWordCount();
        
            Assert.assertEquals(1035, properties.getWords());
            Assert.assertEquals(6026, properties.getCharacters());
            Assert.assertEquals(7041, properties.getCharactersWithSpaces());
        
            // Count the number of lines in the document, and then assign the result to the "Lines" built-in property.
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
        
            Assert.assertEquals(142, properties.getLines());
        
            // Assign the number of Paragraph nodes in the document to the "Paragraphs" built-in property.
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(29, properties.getParagraphs());
        
            // Get an estimate of the file size of our document via the "Bytes" built-in property.
            Assert.assertEquals(20310, properties.getBytes());
        
            // Set a different template for our document, and then update the "Template" built-in property manually to reflect this change.
            doc.setAttachedTemplate(getMyDir() + "Business brochure.dotx");
        
            Assert.assertEquals("Normal", properties.getTemplate());    
        
            properties.setTemplate(doc.getAttachedTemplate());
        
            // "ContentStatus" is a descriptive built-in property.
            properties.setContentStatus("Draft");
        
            // Upon saving, the "ContentType" built-in property will contain 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 the "LinksUpToDate" property to "true".
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "DocumentProperties.Content.docx");
        }
        
        /// <summary>
        /// Counts the lines in a document.
        /// Traverses the document's layout entities tree upon construction,
        /// 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 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();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " +
                "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
        builder.write("Ut enim ad minim veniam, " +
                "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.");
        
        // Aspose.Words does not track document metrics like these in real time.
        Assert.assertEquals(0, doc.getBuiltInDocumentProperties().getCharacters());
        Assert.assertEquals(0, doc.getBuiltInDocumentProperties().getWords());
        Assert.assertEquals(1, doc.getBuiltInDocumentProperties().getParagraphs());
        Assert.assertEquals(1, doc.getBuiltInDocumentProperties().getLines());
        
        // To get accurate values for three of these properties, we will need to update them manually.
        doc.updateWordCount();
        
        Assert.assertEquals(196, doc.getBuiltInDocumentProperties().getCharacters());
        Assert.assertEquals(36, doc.getBuiltInDocumentProperties().getWords());
        Assert.assertEquals(2, doc.getBuiltInDocumentProperties().getParagraphs());
        
        // For the line count, we will need to call a specific overload of the updating method.
        Assert.assertEquals(1, doc.getBuiltInDocumentProperties().getLines());
        
        doc.updateWordCount(true);
        
        Assert.assertEquals(4, doc.getBuiltInDocumentProperties().getLines());

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception
        {
            Document doc = new Document(getMyDir() + "Paragraphs.docx");
            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
        
            // The "Pages" property stores the page count of the document. 
            Assert.assertEquals(6, properties.getPages());
        
            // The "Words", "Characters", and "CharactersWithSpaces" built-in properties also display various document statistics,
            // but we need to call the "UpdateWordCount" method on the whole document before we can expect them to contain accurate values.
            doc.updateWordCount();
        
            Assert.assertEquals(1035, properties.getWords());
            Assert.assertEquals(6026, properties.getCharacters());
            Assert.assertEquals(7041, properties.getCharactersWithSpaces());
        
            // Count the number of lines in the document, and then assign the result to the "Lines" built-in property.
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
        
            Assert.assertEquals(142, properties.getLines());
        
            // Assign the number of Paragraph nodes in the document to the "Paragraphs" built-in property.
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(29, properties.getParagraphs());
        
            // Get an estimate of the file size of our document via the "Bytes" built-in property.
            Assert.assertEquals(20310, properties.getBytes());
        
            // Set a different template for our document, and then update the "Template" built-in property manually to reflect this change.
            doc.setAttachedTemplate(getMyDir() + "Business brochure.dotx");
        
            Assert.assertEquals("Normal", properties.getTemplate());    
        
            properties.setTemplate(doc.getAttachedTemplate());
        
            // "ContentStatus" is a descriptive built-in property.
            properties.setContentStatus("Draft");
        
            // Upon saving, the "ContentType" built-in property will contain 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 the "LinksUpToDate" property to "true".
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "DocumentProperties.Content.docx");
        }
        
        /// <summary>
        /// Counts the lines in a document.
        /// Traverses the document's layout entities tree upon construction,
        /// 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 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 REVNUM fields.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.write("Current revision #");
        
        // Insert a REVNUM field, which displays the document's current revision number property.
        FieldRevNum field = (FieldRevNum)builder.insertField(FieldType.FIELD_REVISION_NUM, true);
        
        Assert.assertEquals(" REVNUM ", field.getFieldCode());
        Assert.assertEquals("1", field.getResult());
        Assert.assertEquals(1, doc.getBuiltInDocumentProperties().getRevisionNumber());
        
        // This property counts how many times a document has been saved in Microsoft Word,
        // and is unrelated to tracked revisions. We can find it by right clicking the document in Windows Explorer
        // via Properties -> Details. We can update this property manually.
        doc.getBuiltInDocumentProperties().setRevisionNumber(doc.getBuiltInDocumentProperties().getRevisionNumber() + 1)/*Property++*/;
        field.update();
        
        Assert.assertEquals("2", field.getResult());

        Example:

        Shows how to work with document properties in the "Origin" category.
        // Open a document that we have created and edited using Microsoft Word.
        Document doc = new Document(getMyDir() + "Properties.docx");
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // The following built-in properties contain information regarding the creation and editing of this document.
        // We can right-click this document in Windows Explorer and find
        // these properties via "Properties" -> "Details" -> "Origin" category.
        // Fields such as PRINTDATE and EDITTIME can display these values in the document body.
        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 also change the values of built-in properties.
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1);
        
        // Microsoft Word updates the following properties automatically when we save the document.
        // To use these properties with Aspose.Words, we will need to set values for them manually.
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details" -> "Origin".
        doc.save(getArtifactsDir() + "DocumentProperties.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.
        Document doc = new Document();
        
        Assert.assertEquals(DocumentSecurity.NONE, doc.getBuiltInDocumentProperties().getSecurity());
        
        // If we configure a document to be read-only, it will display this status using the "Security" built-in property.
        doc.getWriteProtection().setReadOnlyRecommended(true);
        doc.save(getArtifactsDir() + "DocumentProperties.Security.ReadOnlyRecommended.docx");
        
        Assert.assertEquals(DocumentSecurity.READ_ONLY_RECOMMENDED, 
            new Document(getArtifactsDir() + "DocumentProperties.Security.ReadOnlyRecommended.docx").getBuiltInDocumentProperties().getSecurity());
        
        // Write-protect a document, and then verify its security level.
        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() + "DocumentProperties.Security.ReadOnlyEnforced.docx");
        
        Assert.assertEquals(DocumentSecurity.READ_ONLY_ENFORCED,
            new Document(getArtifactsDir() + "DocumentProperties.Security.ReadOnlyEnforced.docx").getBuiltInDocumentProperties().getSecurity());
        
        // "Security" is a descriptive property. We can edit its value manually.
        doc = new Document();
        
        doc.protect(ProtectionType.ALLOW_ONLY_COMMENTS, "MyPassword");
        doc.getBuiltInDocumentProperties().setSecurity(DocumentSecurity.READ_ONLY_EXCEPT_ANNOTATIONS);
        doc.save(getArtifactsDir() + "DocumentProperties.Security.ReadOnlyExceptAnnotations.docx");
        
        Assert.assertEquals(DocumentSecurity.READ_ONLY_EXCEPT_ANNOTATIONS,
            new Document(getArtifactsDir() + "DocumentProperties.Security.ReadOnlyExceptAnnotations.docx").getBuiltInDocumentProperties().getSecurity());
      • 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 built-in document properties in the "Description" category.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Below are four built-in document properties that have fields that can display their values in the document body.
        // 1 -  "Author" property, which we can display using an AUTHOR field:
        properties.setAuthor("John Doe");
        builder.write("Author:\t");
        builder.insertField(FieldType.FIELD_AUTHOR, true);
        
        // 2 -  "Title" property, which we can display using a TITLE field:
        properties.setTitle("John's Document");
        builder.write("\nDoc title:\t");
        builder.insertField(FieldType.FIELD_TITLE, true);
        
        // 3 -  "Subject" property, which we can display using a SUBJECT field:
        properties.setSubject("My subject");
        builder.write("\nSubject:\t");
        builder.insertField(FieldType.FIELD_SUBJECT, true);
        
        // 4 -  "Comments" property, which we can display using a COMMENTS field:
        properties.setComments(MessageFormat.format("This is {0}'s document about {1}", properties.getAuthor(), properties.getSubject()));
        builder.write("\nComments:\t\"");
        builder.insertField(FieldType.FIELD_COMMENTS, true);
        builder.write("\"");
        
        // The "Category" built-in property does not have a field that can display its value.
        properties.setCategory("My category");
        
        // We can set multiple keywords for a document by separating the string value of the "Keywords" property with semicolons.
        properties.setKeywords("Tag 1; Tag 2; Tag 3");
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details".
        // The "Author" built-in property is in the "Origin" group, and the others are in the "Description" group.
        doc.save(getArtifactsDir() + "DocumentProperties.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 that we have created and edited using Microsoft Word.
        Document doc = new Document(getMyDir() + "Properties.docx");
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // The following built-in properties contain information regarding the creation and editing of this document.
        // We can right-click this document in Windows Explorer and find
        // these properties via "Properties" -> "Details" -> "Origin" category.
        // Fields such as PRINTDATE and EDITTIME can display these values in the document body.
        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 also change the values of built-in properties.
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1);
        
        // Microsoft Word updates the following properties automatically when we save the document.
        // To use these properties with Aspose.Words, we will need to set values for them manually.
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details" -> "Origin".
        doc.save(getArtifactsDir() + "DocumentProperties.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 add a thumbnail to a document that we save as an Epub.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Hello world!");
        
        // If we save a document, whose "Thumbnail" property contains image data that we added, as an Epub,
        // a reader that opens that document may display the image before the first page.
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        byte[] thumbnailBytes = DocumentHelper.getBytesFromStream(new FileInputStream(getImageDir() + "Logo.jpg"));
        properties.setThumbnail(thumbnailBytes);
        
        doc.save(getArtifactsDir() + "DocumentProperties.Thumbnail.epub");
        
        // We can extract a document's thumbnail image and save it to the local file system.
        DocumentProperty thumbnail = doc.getBuiltInDocumentProperties().get("Thumbnail");
        FileUtils.writeByteArrayToFile(new File(getArtifactsDir() + "DocumentProperties.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 built-in document properties in the "Description" category.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // Below are four built-in document properties that have fields that can display their values in the document body.
        // 1 -  "Author" property, which we can display using an AUTHOR field:
        properties.setAuthor("John Doe");
        builder.write("Author:\t");
        builder.insertField(FieldType.FIELD_AUTHOR, true);
        
        // 2 -  "Title" property, which we can display using a TITLE field:
        properties.setTitle("John's Document");
        builder.write("\nDoc title:\t");
        builder.insertField(FieldType.FIELD_TITLE, true);
        
        // 3 -  "Subject" property, which we can display using a SUBJECT field:
        properties.setSubject("My subject");
        builder.write("\nSubject:\t");
        builder.insertField(FieldType.FIELD_SUBJECT, true);
        
        // 4 -  "Comments" property, which we can display using a COMMENTS field:
        properties.setComments(MessageFormat.format("This is {0}'s document about {1}", properties.getAuthor(), properties.getSubject()));
        builder.write("\nComments:\t\"");
        builder.insertField(FieldType.FIELD_COMMENTS, true);
        builder.write("\"");
        
        // The "Category" built-in property does not have a field that can display its value.
        properties.setCategory("My category");
        
        // We can set multiple keywords for a document by separating the string value of the "Keywords" property with semicolons.
        properties.setKeywords("Tag 1; Tag 2; Tag 3");
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details".
        // The "Author" built-in property is in the "Origin" group, and the others are in the "Description" group.
        doc.save(getArtifactsDir() + "DocumentProperties.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.
        Document doc = new Document(getMyDir() + "Heading pairs and titles of parts.docx");
        
        // We can find the combined values of these collections via "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 across.
        Object[] headingPairs = doc.getBuiltInDocumentProperties().getHeadingPairs();
        
        // The TitlesOfParts property contains the names of parts that belong to the above headings.
        String[] titlesOfParts = doc.getBuiltInDocumentProperties().getTitlesOfParts();
        
        int headingPairsIndex = 0;
        int titlesOfPartsIndex = 0;
        while (headingPairsIndex < headingPairs.length)
        {
            System.out.println(MessageFormat.format("Parts for {0}:", headingPairs[headingPairsIndex++]));
            int partsCount = (int)headingPairs[headingPairsIndex++];
        
            for (int i = 0; i < partsCount; i++)
                System.out.println(MessageFormat.format("\t\"{0}\"", titlesOfParts[titlesOfPartsIndex++]));
        }
        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 that we have created and edited using Microsoft Word.
        Document doc = new Document(getMyDir() + "Properties.docx");
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // The following built-in properties contain information regarding the creation and editing of this document.
        // We can right-click this document in Windows Explorer and find
        // these properties via "Properties" -> "Details" -> "Origin" category.
        // Fields such as PRINTDATE and EDITTIME can display these values in the document body.
        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 also change the values of built-in properties.
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1);
        
        // Microsoft Word updates the following properties automatically when we save the document.
        // To use these properties with Aspose.Words, we will need to set values for them manually.
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details" -> "Origin".
        doc.save(getArtifactsDir() + "DocumentProperties.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 that we have created and edited using Microsoft Word.
        Document doc = new Document(getMyDir() + "Properties.docx");
        BuiltInDocumentProperties properties = doc.getBuiltInDocumentProperties();
        
        // The following built-in properties contain information regarding the creation and editing of this document.
        // We can right-click this document in Windows Explorer and find
        // these properties via "Properties" -> "Details" -> "Origin" category.
        // Fields such as PRINTDATE and EDITTIME can display these values in the document body.
        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 also change the values of built-in properties.
        properties.setCompany("Doe Ltd.");
        properties.setManager("Jane Doe");
        properties.setVersion(5);
        properties.setRevisionNumber(properties.getRevisionNumber() + 1);
        
        // Microsoft Word updates the following properties automatically when we save the document.
        // To use these properties with Aspose.Words, we will need to set values for them manually.
        properties.setLastSavedBy("John Doe");
        properties.setLastSavedTime(new Date());
        
        // We can right-click this document in Windows Explorer and find these properties in "Properties" -> "Details" -> "Origin".
        doc.save(getArtifactsDir() + "DocumentProperties.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();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " +
                "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
        builder.write("Ut enim ad minim veniam, " +
                "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.");
        
        // Aspose.Words does not track document metrics like these in real time.
        Assert.assertEquals(0, doc.getBuiltInDocumentProperties().getCharacters());
        Assert.assertEquals(0, doc.getBuiltInDocumentProperties().getWords());
        Assert.assertEquals(1, doc.getBuiltInDocumentProperties().getParagraphs());
        Assert.assertEquals(1, doc.getBuiltInDocumentProperties().getLines());
        
        // To get accurate values for three of these properties, we will need to update them manually.
        doc.updateWordCount();
        
        Assert.assertEquals(196, doc.getBuiltInDocumentProperties().getCharacters());
        Assert.assertEquals(36, doc.getBuiltInDocumentProperties().getWords());
        Assert.assertEquals(2, doc.getBuiltInDocumentProperties().getParagraphs());
        
        // For the line count, we will need to call a specific overload of the updating method.
        Assert.assertEquals(1, doc.getBuiltInDocumentProperties().getLines());
        
        doc.updateWordCount(true);
        
        Assert.assertEquals(4, doc.getBuiltInDocumentProperties().getLines());

        Example:

        Shows how to work with document properties in the "Content" category.
        public void content() throws Exception
        {
            Document doc = new Document(getMyDir() + "Paragraphs.docx");
            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
        
            // The "Pages" property stores the page count of the document. 
            Assert.assertEquals(6, properties.getPages());
        
            // The "Words", "Characters", and "CharactersWithSpaces" built-in properties also display various document statistics,
            // but we need to call the "UpdateWordCount" method on the whole document before we can expect them to contain accurate values.
            doc.updateWordCount();
        
            Assert.assertEquals(1035, properties.getWords());
            Assert.assertEquals(6026, properties.getCharacters());
            Assert.assertEquals(7041, properties.getCharactersWithSpaces());
        
            // Count the number of lines in the document, and then assign the result to the "Lines" built-in property.
            LineCounter lineCounter = new LineCounter(doc);
            properties.setLines(lineCounter.getLineCount());
        
            Assert.assertEquals(142, properties.getLines());
        
            // Assign the number of Paragraph nodes in the document to the "Paragraphs" built-in property.
            properties.setParagraphs(doc.getChildNodes(NodeType.PARAGRAPH, true).getCount());
            Assert.assertEquals(29, properties.getParagraphs());
        
            // Get an estimate of the file size of our document via the "Bytes" built-in property.
            Assert.assertEquals(20310, properties.getBytes());
        
            // Set a different template for our document, and then update the "Template" built-in property manually to reflect this change.
            doc.setAttachedTemplate(getMyDir() + "Business brochure.dotx");
        
            Assert.assertEquals("Normal", properties.getTemplate());    
        
            properties.setTemplate(doc.getAttachedTemplate());
        
            // "ContentStatus" is a descriptive built-in property.
            properties.setContentStatus("Draft");
        
            // Upon saving, the "ContentType" built-in property will contain 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 the "LinksUpToDate" property to "true".
            Assert.assertFalse(properties.getLinksUpToDate());
        
            doc.save(getArtifactsDir() + "DocumentProperties.Content.docx");
        }
        
        /// <summary>
        /// Counts the lines in a document.
        /// Traverses the document's layout entities tree upon construction,
        /// 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 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:

        Shows how to work with custom document properties.
        Document doc = new Document(getMyDir() + "Properties.docx");
        
        // Every document contains a collection of custom properties, which, like the built-in properties, are key-value pairs.
        // Unlike the built-in properties, many of which the document maintains by itself, we need to create all of our own custom properties. 
        Assert.assertEquals("Value of custom document property", doc.getCustomDocumentProperties().get("CustomProperty").toString());
        
        doc.getCustomDocumentProperties().add("CustomProperty2", "Value of custom document property #2");
        
        System.out.println("Custom Properties:");
        for (DocumentProperty customDocumentProperty : doc.getCustomDocumentProperties())
        {
            System.out.println(customDocumentProperty.getName());
            System.out.println(MessageFormat.format("\tType:\t{0}", customDocumentProperty.getType()));
            System.out.println(MessageFormat.format("\tValue:\t\"{0}\"", customDocumentProperty.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:

        Shows how to work with custom document properties.
        Document doc = new Document(getMyDir() + "Properties.docx");
        
        // Every document contains a collection of custom properties, which, like the built-in properties, are key-value pairs.
        // Unlike the built-in properties, many of which the document maintains by itself, we need to create all of our own custom properties. 
        Assert.assertEquals("Value of custom document property", doc.getCustomDocumentProperties().get("CustomProperty").toString());
        
        doc.getCustomDocumentProperties().add("CustomProperty2", "Value of custom document property #2");
        
        System.out.println("Custom Properties:");
        for (DocumentProperty customDocumentProperty : doc.getCustomDocumentProperties())
        {
            System.out.println(customDocumentProperty.getName());
            System.out.println(MessageFormat.format("\tType:\t{0}", customDocumentProperty.getType()));
            System.out.println(MessageFormat.format("\tValue:\t\"{0}\"", customDocumentProperty.getValue()));
        }
    • Method Detail

      • clear

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

        Example:

        Shows how to work with a document's custom properties.
        Document doc = new Document();
        CustomDocumentProperties properties = doc.getCustomDocumentProperties();
        
        Assert.assertEquals(0, properties.getCount());
        
        // Custom document properties are key-value pairs that we can add to the document.
        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);
        
        // The collection sorts the custom properties in alphabetic order.
        Assert.assertEquals(1, properties.indexOf("Authorized Amount"));
        Assert.assertEquals(5, properties.getCount());
        
        // Print every custom property in the document.
        Iterator<DocumentProperty> enumerator = properties.iterator();
        while (enumerator.hasNext()) {
            DocumentProperty property = enumerator.next();
            System.out.println(MessageFormat.format("Name: \"{0}\"\n\tType: \"{1}\"\n\tValue: \"{2}\"", property.getName(), property.getType(), property.getValue()));
        }
        
        // Display the value of a custom property using a DOCPROPERTY field.
        DocumentBuilder builder = new DocumentBuilder(doc);
        FieldDocProperty field = (FieldDocProperty)builder.insertField(" DOCPROPERTY \"Authorized By\"");
        field.update();
        
        Assert.assertEquals("John Doe", field.getResult());
        
        // We can find these custom properties in Microsoft Word via "File" -> "Properties" > "Advanced Properties" > "Custom".
        doc.save(getArtifactsDir() + "DocumentProperties.DocumentPropertyCollection.docx");
        
        // Below are three ways or removing custom properties from a document.
        // 1 -  Remove by index:
        properties.removeAt(1);
        
        Assert.assertFalse(properties.contains("Authorized Amount"));
        Assert.assertEquals(4, properties.getCount());
        
        // 2 -  Remove by name:
        properties.remove("Authorized Revision");
        
        Assert.assertFalse(properties.contains("Authorized Revision"));
        Assert.assertEquals(3, properties.getCount());
        
        // 3 -  Empty the entire collection at once:
        properties.clear();
        
        Assert.assertEquals(0, properties.getCount());
      • 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 work with a document's custom properties.
        Document doc = new Document();
        CustomDocumentProperties properties = doc.getCustomDocumentProperties();
        
        Assert.assertEquals(0, properties.getCount());
        
        // Custom document properties are key-value pairs that we can add to the document.
        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);
        
        // The collection sorts the custom properties in alphabetic order.
        Assert.assertEquals(1, properties.indexOf("Authorized Amount"));
        Assert.assertEquals(5, properties.getCount());
        
        // Print every custom property in the document.
        Iterator<DocumentProperty> enumerator = properties.iterator();
        while (enumerator.hasNext()) {
            DocumentProperty property = enumerator.next();
            System.out.println(MessageFormat.format("Name: \"{0}\"\n\tType: \"{1}\"\n\tValue: \"{2}\"", property.getName(), property.getType(), property.getValue()));
        }
        
        // Display the value of a custom property using a DOCPROPERTY field.
        DocumentBuilder builder = new DocumentBuilder(doc);
        FieldDocProperty field = (FieldDocProperty)builder.insertField(" DOCPROPERTY \"Authorized By\"");
        field.update();
        
        Assert.assertEquals("John Doe", field.getResult());
        
        // We can find these custom properties in Microsoft Word via "File" -> "Properties" > "Advanced Properties" > "Custom".
        doc.save(getArtifactsDir() + "DocumentProperties.DocumentPropertyCollection.docx");
        
        // Below are three ways or removing custom properties from a document.
        // 1 -  Remove by index:
        properties.removeAt(1);
        
        Assert.assertFalse(properties.contains("Authorized Amount"));
        Assert.assertEquals(4, properties.getCount());
        
        // 2 -  Remove by name:
        properties.remove("Authorized Revision");
        
        Assert.assertFalse(properties.contains("Authorized Revision"));
        Assert.assertEquals(3, properties.getCount());
        
        // 3 -  Empty the entire collection at once:
        properties.clear();
        
        Assert.assertEquals(0, properties.getCount());
      • 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 work with a document's custom properties.
        Document doc = new Document();
        CustomDocumentProperties properties = doc.getCustomDocumentProperties();
        
        Assert.assertEquals(0, properties.getCount());
        
        // Custom document properties are key-value pairs that we can add to the document.
        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);
        
        // The collection sorts the custom properties in alphabetic order.
        Assert.assertEquals(1, properties.indexOf("Authorized Amount"));
        Assert.assertEquals(5, properties.getCount());
        
        // Print every custom property in the document.
        Iterator<DocumentProperty> enumerator = properties.iterator();
        while (enumerator.hasNext()) {
            DocumentProperty property = enumerator.next();
            System.out.println(MessageFormat.format("Name: \"{0}\"\n\tType: \"{1}\"\n\tValue: \"{2}\"", property.getName(), property.getType(), property.getValue()));
        }
        
        // Display the value of a custom property using a DOCPROPERTY field.
        DocumentBuilder builder = new DocumentBuilder(doc);
        FieldDocProperty field = (FieldDocProperty)builder.insertField(" DOCPROPERTY \"Authorized By\"");
        field.update();
        
        Assert.assertEquals("John Doe", field.getResult());
        
        // We can find these custom properties in Microsoft Word via "File" -> "Properties" > "Advanced Properties" > "Custom".
        doc.save(getArtifactsDir() + "DocumentProperties.DocumentPropertyCollection.docx");
        
        // Below are three ways or removing custom properties from a document.
        // 1 -  Remove by index:
        properties.removeAt(1);
        
        Assert.assertFalse(properties.contains("Authorized Amount"));
        Assert.assertEquals(4, properties.getCount());
        
        // 2 -  Remove by name:
        properties.remove("Authorized Revision");
        
        Assert.assertFalse(properties.contains("Authorized Revision"));
        Assert.assertEquals(3, properties.getCount());
        
        // 3 -  Empty the entire collection at once:
        properties.clear();
        
        Assert.assertEquals(0, properties.getCount());
      • 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 work with a document's custom properties.
        Document doc = new Document();
        CustomDocumentProperties properties = doc.getCustomDocumentProperties();
        
        Assert.assertEquals(0, properties.getCount());
        
        // Custom document properties are key-value pairs that we can add to the document.
        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);
        
        // The collection sorts the custom properties in alphabetic order.
        Assert.assertEquals(1, properties.indexOf("Authorized Amount"));
        Assert.assertEquals(5, properties.getCount());
        
        // Print every custom property in the document.
        Iterator<DocumentProperty> enumerator = properties.iterator();
        while (enumerator.hasNext()) {
            DocumentProperty property = enumerator.next();
            System.out.println(MessageFormat.format("Name: \"{0}\"\n\tType: \"{1}\"\n\tValue: \"{2}\"", property.getName(), property.getType(), property.getValue()));
        }
        
        // Display the value of a custom property using a DOCPROPERTY field.
        DocumentBuilder builder = new DocumentBuilder(doc);
        FieldDocProperty field = (FieldDocProperty)builder.insertField(" DOCPROPERTY \"Authorized By\"");
        field.update();
        
        Assert.assertEquals("John Doe", field.getResult());
        
        // We can find these custom properties in Microsoft Word via "File" -> "Properties" > "Advanced Properties" > "Custom".
        doc.save(getArtifactsDir() + "DocumentProperties.DocumentPropertyCollection.docx");
        
        // Below are three ways or removing custom properties from a document.
        // 1 -  Remove by index:
        properties.removeAt(1);
        
        Assert.assertFalse(properties.contains("Authorized Amount"));
        Assert.assertEquals(4, properties.getCount());
        
        // 2 -  Remove by name:
        properties.remove("Authorized Revision");
        
        Assert.assertFalse(properties.contains("Authorized Revision"));
        Assert.assertEquals(3, properties.getCount());
        
        // 3 -  Empty the entire collection at once:
        properties.clear();
        
        Assert.assertEquals(0, properties.getCount());
      • 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 work with a document's custom properties.
        Document doc = new Document();
        CustomDocumentProperties properties = doc.getCustomDocumentProperties();
        
        Assert.assertEquals(0, properties.getCount());
        
        // Custom document properties are key-value pairs that we can add to the document.
        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);
        
        // The collection sorts the custom properties in alphabetic order.
        Assert.assertEquals(1, properties.indexOf("Authorized Amount"));
        Assert.assertEquals(5, properties.getCount());
        
        // Print every custom property in the document.
        Iterator<DocumentProperty> enumerator = properties.iterator();
        while (enumerator.hasNext()) {
            DocumentProperty property = enumerator.next();
            System.out.println(MessageFormat.format("Name: \"{0}\"\n\tType: \"{1}\"\n\tValue: \"{2}\"", property.getName(), property.getType(), property.getValue()));
        }
        
        // Display the value of a custom property using a DOCPROPERTY field.
        DocumentBuilder builder = new DocumentBuilder(doc);
        FieldDocProperty field = (FieldDocProperty)builder.insertField(" DOCPROPERTY \"Authorized By\"");
        field.update();
        
        Assert.assertEquals("John Doe", field.getResult());
        
        // We can find these custom properties in Microsoft Word via "File" -> "Properties" > "Advanced Properties" > "Custom".
        doc.save(getArtifactsDir() + "DocumentProperties.DocumentPropertyCollection.docx");
        
        // Below are three ways or removing custom properties from a document.
        // 1 -  Remove by index:
        properties.removeAt(1);
        
        Assert.assertFalse(properties.contains("Authorized Amount"));
        Assert.assertEquals(4, properties.getCount());
        
        // 2 -  Remove by name:
        properties.remove("Authorized Revision");
        
        Assert.assertFalse(properties.contains("Authorized Revision"));
        Assert.assertEquals(3, properties.getCount());
        
        // 3 -  Empty the entire collection at once:
        properties.clear();
        
        Assert.assertEquals(0, properties.getCount());
      • 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 work with a document's custom properties.
        Document doc = new Document();
        CustomDocumentProperties properties = doc.getCustomDocumentProperties();
        
        Assert.assertEquals(0, properties.getCount());
        
        // Custom document properties are key-value pairs that we can add to the document.
        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);
        
        // The collection sorts the custom properties in alphabetic order.
        Assert.assertEquals(1, properties.indexOf("Authorized Amount"));
        Assert.assertEquals(5, properties.getCount());
        
        // Print every custom property in the document.
        Iterator<DocumentProperty> enumerator = properties.iterator();
        while (enumerator.hasNext()) {
            DocumentProperty property = enumerator.next();
            System.out.println(MessageFormat.format("Name: \"{0}\"\n\tType: \"{1}\"\n\tValue: \"{2}\"", property.getName(), property.getType(), property.getValue()));
        }
        
        // Display the value of a custom property using a DOCPROPERTY field.
        DocumentBuilder builder = new DocumentBuilder(doc);
        FieldDocProperty field = (FieldDocProperty)builder.insertField(" DOCPROPERTY \"Authorized By\"");
        field.update();
        
        Assert.assertEquals("John Doe", field.getResult());
        
        // We can find these custom properties in Microsoft Word via "File" -> "Properties" > "Advanced Properties" > "Custom".
        doc.save(getArtifactsDir() + "DocumentProperties.DocumentPropertyCollection.docx");
        
        // Below are three ways or removing custom properties from a document.
        // 1 -  Remove by index:
        properties.removeAt(1);
        
        Assert.assertFalse(properties.contains("Authorized Amount"));
        Assert.assertEquals(4, properties.getCount());
        
        // 2 -  Remove by name:
        properties.remove("Authorized Revision");
        
        Assert.assertFalse(properties.contains("Authorized Revision"));
        Assert.assertEquals(3, properties.getCount());
        
        // 3 -  Empty the entire collection at once:
        properties.clear();
        
        Assert.assertEquals(0, properties.getCount());