public class Document extends DocumentBase
To learn more, visit the Working with Document documentation article.
The Document is a central object in the Aspose.Words library.
To load an existing document in any of the LoadFormat formats, pass a file name or a stream into one of the Document constructors. To create a blank document, call the constructor without parameters.
Use one of the Save method overloads to save the document in any of the SaveFormat formats.
To draw document pages directly onto a Graphics object use renderToScale(int, java.awt.Graphics2D, float, float, float) or renderToSize(int, java.awt.Graphics2D, float, float, float, float) method.
To print the document, use one of the print(java.lang.String) methods.
getMailMerge() is the Aspose.Words's reporting engine that allows to populate reports designed in Microsoft Word with data from various data sources quickly and easily. The data can be from a java.sql.ResultSet or an array of values. MailMerge will go through the records found in the data source and insert them into mail merge fields in the document growing it as necessary.
Document stores document-wide information such as DocumentBase.getStyles(), getBuiltInDocumentProperties(), getCustomDocumentProperties(), lists and macros. Most of these objects are accessible via the corresponding properties of the Document.
The Document is a root node of a tree that contains all other nodes of the document. The tree is a Composite design pattern and in many ways similar to XmlDocument. The content of the document can be manipulated freely programmatically:
getSections(), ParagraphCollection etc.
CompositeNode.selectNodes(java.lang.String) or CompositeNode.selectSingleNode(java.lang.String).
CompositeNode.insertBefore(com.aspose.words.Node, com.aspose.words.Node), CompositeNode.insertAfter(com.aspose.words.Node, com.aspose.words.Node), CompositeNode.removeChild(com.aspose.words.Node) and other methods provided by the base class CompositeNode.
Consider using DocumentBuilder that simplifies the task of programmatically creating or populating the document tree.
The Document can contain only Section objects.
In Microsoft Word, a valid document needs to have at least one section.
| Constructor and Description |
|---|
Document()
|
Document(java.io.InputStream stream)
Initializes a new instance of this class.
|
Document(java.io.InputStream stream,
LoadOptions loadOptions)
Initializes a new instance of this class.
|
Document(java.lang.String fileName)
Opens an existing document from a file.
|
Document(java.lang.String fileName,
LoadOptions loadOptions)
Opens an existing document from a file.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
accept(DocumentVisitor visitor)
Accepts a visitor.
|
void |
acceptAllRevisions()
Accepts all tracked changes in the document.
|
void |
add(Shape watermark) |
void |
appendDocument(Document srcDoc,
int importFormatMode) |
void |
appendDocument(Document srcDoc,
int importFormatMode,
ImportFormatOptions importFormatOptions) |
void |
cleanup()
Cleans unused styles and lists from the document.
|
void |
cleanup(CleanupOptions options)
Cleans unused styles and lists from the document depending on given
CleanupOptions. |
void |
clearSectionAttrs() |
void |
compare(Document document,
java.lang.String author,
java.util.Date dateTime)
Compares this document with another document producing changes as number of edit and format revisions
Revision. |
void |
compare(Document document,
java.lang.String author,
java.util.Date dateTime,
CompareOptions options)
Compares this document with another document producing changes as a number of edit and format revisions
Revision. |
void |
copyStylesFromTemplate(Document template)
Copies styles from the specified template to a document.
|
void |
copyStylesFromTemplate(java.lang.String template)
Copies styles from the specified template to a document.
|
Document |
deepClone()
Performs a deep copy of the
Document. |
void |
ensureMinimum()
If the document contains no sections, creates one section with one paragraph.
|
void |
expandTableStylesToDirectFormatting()
Converts formatting specified in table styles into direct formatting on tables in the document.
|
Document |
extractPages(int index,
int count)
Returns the
Document object representing specified range of pages. |
java.lang.Object |
fetchInheritedSectionAttr(int key) |
java.lang.Object |
fetchSectionAttr(int key) |
Shape |
get() |
java.lang.String |
getAttachedTemplate()
Gets the full path of the template attached to the document.
|
boolean |
getAutomaticallyUpdateStyles()
Gets a flag indicating whether the styles in the document are updated to match the styles in the attached template each time the document is opened in MS Word.
|
BuiltInDocumentProperties |
getBuiltInDocumentProperties()
Returns a collection that represents all the built-in document properties of the document.
|
CompatibilityOptions |
getCompatibilityOptions()
Provides access to document compatibility options (that is, the user preferences entered on the Compatibility tab of the Options dialog in Word).
|
int |
getCompliance()
Gets the OOXML compliance version determined from the loaded document content.
|
CustomDocumentProperties |
getCustomDocumentProperties()
Returns a collection that represents all the custom document properties of the document.
|
CustomXmlPartCollection |
getCustomXmlParts()
Gets the collection of Custom XML Data Storage Parts.
|
double |
getDefaultTabStop()
Gets the interval (in points) between the default tab stops.
|
DigitalSignatureCollection |
getDigitalSignatures()
Gets the collection of digital signatures for this document and their validation results.
|
java.lang.Object |
getDirectSectionAttr(int key) |
EndnoteOptions |
getEndnoteOptions()
Provides options that control numbering and positioning of endnotes in this document.
|
FieldOptions |
getFieldOptions()
Gets a FieldOptions object that represents options to control field handling in the document.
|
Section |
getFirstSection()
Gets the first section in the document.
|
FontSettings |
getFontSettings()
Gets document font settings.
|
FootnoteOptions |
getFootnoteOptions()
Provides options that control numbering and positioning of footnotes in this document.
|
Frameset |
getFrameset()
Returns a
getFrameset() instance if this document represents a frames page. |
GlossaryDocument |
getGlossaryDocument()
Gets the glossary document within this document or template.
|
boolean |
getGrammarChecked()
Returns true if the document has been checked for grammar.
|
HyphenationOptions |
getHyphenationOptions()
Provides access to document hyphenation options.
|
Section |
getLastSection()
Gets the last section in the document.
|
LayoutOptions |
getLayoutOptions()
Gets a LayoutOptions object that represents options to control the layout process of this document.
|
MailMerge |
getMailMerge()
Returns a MailMerge object that represents the mail merge functionality for the document.
|
MailMergeSettings |
getMailMergeSettings()
Gets the object that contains all of the mail merge information for a document.
|
int |
getNodeType()
Returns NodeType.Document.
|
java.lang.String |
getOriginalFileName()
Gets the original file name of the document.
|
int |
getOriginalLoadFormat()
Gets the format of the original document that was loaded into this object.
|
CustomPartCollection |
getPackageCustomParts()
Gets the collection of custom parts (arbitrary content) that are linked to the OOXML package using "unknown relationships".
|
int |
getPageCount()
Gets the number of pages in the document as calculated by the most recent page layout operation.
|
PageInfo |
getPageInfo(int pageIndex)
Gets the page size, orientation and other information about a page that might be useful for printing or rendering.
|
int |
getProtectionType()
Gets the currently active document protection type.
|
boolean |
getRemovePersonalInformation()
Gets a flag indicating that Microsoft Word will remove all user information from comments, revisions and document properties upon saving the document.
|
RevisionCollection |
getRevisions()
Gets a collection of revisions (tracked changes) that exist in this document.
|
int |
getRevisionsView()
Gets a value indicating whether to work with the original or revised version of a document.
|
SectionCollection |
getSections()
Returns a collection that represents all sections in the document.
|
boolean |
getShadeFormData()
Specifies whether to turn on the gray shading on form fields.
|
boolean |
getShowGrammaticalErrors()
Specifies whether to display grammar errors in this document.
|
boolean |
getShowSpellingErrors()
Specifies whether to display spelling errors in this document.
|
boolean |
getSpellingChecked()
Returns true if the document has been checked for spelling.
|
Theme |
getTheme()
Gets the
getTheme() object for this document. |
boolean |
getTrackRevisions()
True if changes are tracked when this document is edited in Microsoft Word.
|
VariableCollection |
getVariables()
Returns the collection of variables added to a document or template.
|
VbaProject |
getVbaProject()
|
int |
getVersionsCount()
Gets the number of document versions that was stored in the DOC document.
|
ViewOptions |
getViewOptions()
Provides options to control how the document is displayed in Microsoft Word.
|
Watermark |
getWatermark()
Provides access to the document watermark.
|
TaskPaneCollection |
getWebExtensionTaskPanes()
Returns a collection that represents a list of task pane add-ins.
|
WriteProtection |
getWriteProtection()
Provides access to the document write protection options.
|
boolean |
hasMacros()
Returns true if the document has a VBA project (macros).
|
boolean |
hasRevisions()
Returns true if the document has any tracked changes.
|
int |
joinRunsWithSameFormatting()
Joins runs with same formatting in all paragraphs of the document.
|
void |
normalizeFieldTypes()
Changes field type values
FieldChar.getFieldType() of FieldStart, FieldSeparator, FieldEnd in the whole document so that they correspond to the field types contained in the field codes. |
void |
print()
|
void |
print(javax.print.attribute.AttributeSet printerSettings)
Prints the document according to the specified printer settings, using the standard (no User Interface) print controller.
|
void |
print(javax.print.attribute.AttributeSet printerSettings,
java.lang.String documentName)
Prints the document according to the specified printer settings, using the standard (no User Interface) print controller and a document name.
|
void |
print(java.lang.String printerName)
Print the whole document to the specified printer, using the standard (no User Interface) print controller.
|
void |
protect(int type) |
void |
protect(int type,
java.lang.String password) |
void |
remove()
Removes itself from the parent.
|
void |
removeExternalSchemaReferences()
Removes external XML schema references from this document.
|
void |
removeMacros()
Removes all macros (the VBA project) as well as toolbars and command customizations from the document.
|
java.awt.geom.Point2D.Float |
renderToScale(int pageIndex,
java.awt.Graphics2D graphics,
float x,
float y,
float scale)
Renders a document page into a object to a specified scale.
|
float |
renderToSize(int pageIndex,
java.awt.Graphics2D graphics,
float x,
float y,
float width,
float height)
Renders a document page into a object to a specified size.
|
SaveOutputParameters |
save(java.io.OutputStream stream,
int saveFormat) |
SaveOutputParameters |
save(java.io.OutputStream stream,
SaveOptions saveOptions) |
SaveOutputParameters |
save(java.lang.String fileName)
|
SaveOutputParameters |
save(java.lang.String fileName,
int saveFormat) |
SaveOutputParameters |
save(java.lang.String fileName,
SaveOptions saveOptions)
Saves the document to a file using the specified save options.
|
void |
setAttachedTemplate(java.lang.String value)
Sets the full path of the template attached to the document.
|
void |
setAutomaticallyUpdateStyles(boolean value)
Sets a flag indicating whether the styles in the document are updated to match the styles in the attached template each time the document is opened in MS Word.
|
void |
setCustomXmlParts(CustomXmlPartCollection value)
Sets the collection of Custom XML Data Storage Parts.
|
void |
setDefaultTabStop(double value)
Sets the interval (in points) between the default tab stops.
|
void |
setFontSettings(FontSettings value)
Sets document font settings.
|
void |
setGlossaryDocument(GlossaryDocument value)
Sets the glossary document within this document or template.
|
void |
setGrammarChecked(boolean value)
Returns true if the document has been checked for grammar.
|
void |
setMailMergeSettings(MailMergeSettings value)
Sets the object that contains all of the mail merge information for a document.
|
void |
setPackageCustomParts(CustomPartCollection value)
Sets the collection of custom parts (arbitrary content) that are linked to the OOXML package using "unknown relationships".
|
void |
setRemovePersonalInformation(boolean value)
Sets a flag indicating that Microsoft Word will remove all user information from comments, revisions and document properties upon saving the document.
|
void |
setRevisionsView(int value)
Sets a value indicating whether to work with the original or revised version of a document.
|
void |
setSectionAttr(int key,
java.lang.Object value) |
void |
setShadeFormData(boolean value)
Specifies whether to turn on the gray shading on form fields.
|
void |
setShowGrammaticalErrors(boolean value)
Specifies whether to display grammar errors in this document.
|
void |
setShowSpellingErrors(boolean value)
Specifies whether to display spelling errors in this document.
|
void |
setSpellingChecked(boolean value)
Returns true if the document has been checked for spelling.
|
void |
setTrackRevisions(boolean value)
True if changes are tracked when this document is edited in Microsoft Word.
|
void |
setVbaProject(VbaProject value)
|
void |
startTrackRevisions(java.lang.String author)
Starts automatically marking all further changes you make to the document programmatically as revision changes.
|
void |
startTrackRevisions(java.lang.String author,
java.util.Date dateTime)
Starts automatically marking all further changes you make to the document programmatically as revision changes.
|
void |
stopTrackRevisions()
Stops automatic marking of document changes as revisions.
|
void |
unlinkFields()
Unlinks fields in the whole document.
|
void |
unprotect()
|
boolean |
unprotect(java.lang.String password)
Removes protection from the document if a correct password is specified.
|
void |
updateFields()
Updates the values of fields in the whole document.
|
void |
updateListLabels()
Updates list labels for all list items in the document.
|
void |
updatePageLayout()
Rebuilds the page layout of the document.
|
void |
updateTableLayout()
Implements an earlier approach to table column widths re-calculation that has known issues.
|
void |
updateThumbnail()
Updates
BuiltInDocumentProperties.getThumbnail() / BuiltInDocumentProperties.setThumbnail(byte[]) of the document using default options. |
void |
updateThumbnail(ThumbnailGeneratingOptions options)
Updates
BuiltInDocumentProperties.getThumbnail() / BuiltInDocumentProperties.setThumbnail(byte[]) of the document according to the specified options. |
void |
updateWordCount()
Updates word count properties of the document.
|
void |
updateWordCount(boolean updateLinesCount)
Updates word count properties of the document, optionally updates
BuiltInDocumentProperties.getLines() / BuiltInDocumentProperties.setLines(int) property. |
getBackgroundShape, getDocument, getFontInfos, getLists, getNodeChangingCallback, getPageColor, getResourceLoadingCallback, getStyles, getWarningCallback, importNode, importNode, resetState, setBackgroundShape, setNodeChangingCallback, setPageColor, setResourceLoadingCallback, setWarningCallbackacceptChildren, acceptCore, appendChild, coreRemoveSelfOnly, getChild, getChildNodes, getChildNodes, getContainer, getCount, getCurrentNode, getFirstChild, getLastChild, getNextMatchingNode, getText, hasChildNodes, indexOf, insertAfter, insertBefore, isComposite, iterator, prependChild, removeAllChildren, removeChild, removeSmartTags, selectNodes, selectSingleNodedd, deepClone, getAncestor, getAncestor, getCustomNodeId, getNextSibling, getParentNode, getPreviousSibling, getRange, memberwiseClone, nextPreOrder, nodeTypeToString, previousPreOrder, setCustomNodeId, toString, toString, toString, visitorActionToBoolpublic Document()
throws java.lang.Exception
The document paper size is Letter by default. If you want to change page setup, use Section.getPageSetup().
After creation, you can use DocumentBuilder to add document content easily.
java.lang.Exceptionpublic Document(java.lang.String fileName)
throws java.lang.Exception
fileName - File name of the document to open.UnsupportedFileFormatException - The document format is not recognized or not supported.FileCorruptedException - The document appears to be corrupted and cannot be loaded.java.lang.RuntimeException - There is a problem with the document and it should be reported to Aspose.Words developers.java.io.IOException - There is an input/output exception.IncorrectPasswordException - The document is encrypted and requires a password to open, but you supplied an incorrect password.java.lang.IllegalArgumentException - The name of the file cannot be null or empty string.java.lang.Exceptionpublic Document(java.lang.String fileName,
LoadOptions loadOptions)
throws java.lang.Exception
fileName - File name of the document to open.loadOptions - Additional options to use when loading a document. Can be null.UnsupportedFileFormatException - The document format is not recognized or not supported.FileCorruptedException - The document appears to be corrupted and cannot be loaded.java.lang.RuntimeException - There is a problem with the document and it should be reported to Aspose.Words developers.java.io.IOException - There is an input/output exception.IncorrectPasswordException - The document is encrypted and requires a password to open, but you supplied an incorrect password.java.lang.IllegalArgumentException - The name of the file cannot be null or empty string.java.lang.Exceptionpublic Document(java.io.InputStream stream)
throws java.lang.Exception
java.lang.Exceptionpublic Document(java.io.InputStream stream,
LoadOptions loadOptions)
throws java.lang.Exception
java.lang.Exceptionpublic java.lang.String getAttachedTemplate()
Empty string means the document is attached to the Normal template.
com.aspose.words.net.System.ArgumentNullException - Throws if you attempt to set to a null value.BuiltInDocumentProperties.getTemplate(),
BuiltInDocumentProperties.setTemplate(java.lang.String)public void setAttachedTemplate(java.lang.String value)
Empty string means the document is attached to the Normal template.
value - The full path of the template attached to the document.com.aspose.words.net.System.ArgumentNullException - Throws if you attempt to set to a null value.BuiltInDocumentProperties.getTemplate(),
BuiltInDocumentProperties.setTemplate(java.lang.String)public boolean getAutomaticallyUpdateStyles()
public void setAutomaticallyUpdateStyles(boolean value)
value - A flag indicating whether the styles in the document are updated to match the styles in the attached template each time the document is opened in MS Word.public boolean getShadeFormData()
boolean value.public void setShadeFormData(boolean value)
value - The corresponding boolean value.public boolean getTrackRevisions()
Setting this option only instructs Microsoft Word whether the track changes is turned on or off. This property has no effect on changes to the document that you make programmatically via Aspose.Words.
If you want to automatically track changes as they are made programmatically by Aspose.Words to this document use the startTrackRevisions(java.lang.String, java.util.Date) method.
boolean value.public void setTrackRevisions(boolean value)
Setting this option only instructs Microsoft Word whether the track changes is turned on or off. This property has no effect on changes to the document that you make programmatically via Aspose.Words.
If you want to automatically track changes as they are made programmatically by Aspose.Words to this document use the startTrackRevisions(java.lang.String, java.util.Date) method.
value - The corresponding boolean value.public boolean getShowGrammaticalErrors()
boolean value.public void setShowGrammaticalErrors(boolean value)
value - The corresponding boolean value.public boolean getShowSpellingErrors()
boolean value.public void setShowSpellingErrors(boolean value)
value - The corresponding boolean value.public boolean getSpellingChecked()
public void setSpellingChecked(boolean value)
value - true if the document has been checked for spelling.public boolean getGrammarChecked()
public void setGrammarChecked(boolean value)
value - true if the document has been checked for grammar.public int getNodeType()
getNodeType in class NodeNodeType constants.public BuiltInDocumentProperties getBuiltInDocumentProperties()
public TaskPaneCollection getWebExtensionTaskPanes()
public CustomDocumentProperties getCustomDocumentProperties()
public MailMerge getMailMerge()
public int getProtectionType()
This property allows to retrieve the currently set document protection type. To change the document protection type use the M:Aspose.Words.Document.Protect(Aspose.Words.ProtectionType,System.String) and unprotect() methods.
When a document is protected, the user can make only limited changes, such as adding annotations, making revisions, or completing a form.
Note that document protection is different from write protection. Write protection is specified using the getWriteProtection()
ProtectionType constants.unprotect(),
getWriteProtection()public SectionCollection getSections()
public Section getFirstSection()
null if there are no sections.public Section getLastSection()
null if there are no sections.public ViewOptions getViewOptions()
ViewOptions value.public WriteProtection getWriteProtection()
WriteProtection value.public CompatibilityOptions getCompatibilityOptions()
CompatibilityOptions value.public MailMergeSettings getMailMergeSettings()
You can use this object to specify a mail merge data source for a document and this information (along with the available data fields) will appear in Microsoft Word when the user opens this document. Or you can use this object to query mail merge settings that the user has specified in Microsoft Word for this document.
This object is never null.
public void setMailMergeSettings(MailMergeSettings value)
You can use this object to specify a mail merge data source for a document and this information (along with the available data fields) will appear in Microsoft Word when the user opens this document. Or you can use this object to query mail merge settings that the user has specified in Microsoft Word for this document.
This object is never null.
value - The object that contains all of the mail merge information for a document.public HyphenationOptions getHyphenationOptions()
HyphenationOptions value.public boolean hasRevisions()
RevisionCollection.getCount() to zero.public boolean hasMacros()
removeMacros()public Watermark getWatermark()
Watermark value.public int getVersionsCount()
Versions in Microsoft Word are accessed via the File/Versions menu. Microsoft Word supports versions only for DOC files.
This property allows to detect if there were document versions stored in this document before it was opened in Aspose.Words. Aspose.Words provides no other support for document versions. If you save this document using Aspose.Words, the document will be saved without versions.
public double getDefaultTabStop()
TabStopCollection,
TabStoppublic void setDefaultTabStop(double value)
value - The interval (in points) between the default tab stops.TabStopCollection,
TabStoppublic Theme getTheme()
getTheme() object for this document.getTheme() object for this document.public CustomXmlPartCollection getCustomXmlParts()
Aspose.Words loads and saves Custom XML Parts into OOXML and DOC documents only.
This property cannot be null.
CustomXmlPartpublic void setCustomXmlParts(CustomXmlPartCollection value)
Aspose.Words loads and saves Custom XML Parts into OOXML and DOC documents only.
This property cannot be null.
value - The collection of Custom XML Data Storage Parts.CustomXmlPartpublic CustomPartCollection getPackageCustomParts()
Do not confuse these custom parts with Custom XML Data. If you need to access Custom XML parts, use the getCustomXmlParts() / setCustomXmlParts(com.aspose.words.CustomXmlPartCollection) property.
This collection contains OOXML parts whose parent is the OOXML package and they targets are of an "unknown relationship". For more information see CustomPart.
Aspose.Words loads and saves custom parts into OOXML documents only.
This property cannot be null.
CustomPartpublic void setPackageCustomParts(CustomPartCollection value)
Do not confuse these custom parts with Custom XML Data. If you need to access Custom XML parts, use the getCustomXmlParts() / setCustomXmlParts(com.aspose.words.CustomXmlPartCollection) property.
This collection contains OOXML parts whose parent is the OOXML package and they targets are of an "unknown relationship". For more information see CustomPart.
Aspose.Words loads and saves custom parts into OOXML documents only.
This property cannot be null.
value - The collection of custom parts (arbitrary content) that are linked to the OOXML package using "unknown relationships".CustomPartpublic VariableCollection getVariables()
public GlossaryDocument getGlossaryDocument()
This property returns null if the document does not have a glossary document.
You can add a glossary document to a document by creating a GlossaryDocument object and assigning to this property.
GlossaryDocumentpublic void setGlossaryDocument(GlossaryDocument value)
This property returns null if the document does not have a glossary document.
You can add a glossary document to a document by creating a GlossaryDocument object and assigning to this property.
value - The glossary document within this document or template.GlossaryDocumentpublic java.lang.String getOriginalFileName()
Returns null if the document was loaded from a stream or created blank.
public int getOriginalLoadFormat()
If you created a new blank document, returns the LoadFormat.DOC value.
LoadFormat constants.public int getCompliance()
If you created a new blank document or load non OOXML document returns the OoxmlCompliance.ECMA_376_2006 value.
OoxmlCompliance constants.public DigitalSignatureCollection getDigitalSignatures()
This collection contains digital signatures that were loaded from the original document. These digital signatures will not be saved when you save this Document object into a file or stream because saving or converting will produce a document that is different from the original and the original digital signatures will no longer be valid.
This collection is never null. If the document is not signed, it will contain zero elements.
public FontSettings getFontSettings()
This property allows to specify font settings per document. If set to null, default static font settings FontSettings.getDefaultInstance() will be used.
The default value is null.
public void setFontSettings(FontSettings value)
This property allows to specify font settings per document. If set to null, default static font settings FontSettings.getDefaultInstance() will be used.
The default value is null.
value - Document font settings.public Frameset getFrameset()
getFrameset() instance if this document represents a frames page.
If the document is not framed, the property has the null value.getFrameset() instance if this document represents a frames page.public Document deepClone()
Document.public boolean accept(DocumentVisitor visitor) throws java.lang.Exception
Enumerates over this node and all of its children. Each node calls a corresponding method on DocumentVisitor.
For more info see the Visitor design pattern.
public void appendDocument(Document srcDoc, int importFormatMode)
public void appendDocument(Document srcDoc, int importFormatMode, ImportFormatOptions importFormatOptions)
public SaveOutputParameters save(java.lang.String fileName) throws java.lang.Exception
fileName - The name for the document. If a document with the specified file name already exists, the existing document is overwritten.java.lang.Exceptionpublic SaveOutputParameters save(java.lang.String fileName, int saveFormat) throws java.lang.Exception
java.lang.Exceptionpublic SaveOutputParameters save(java.lang.String fileName, SaveOptions saveOptions) throws java.lang.Exception
fileName - The name for the document. If a document with the specified file name already exists, the existing document is overwritten.saveOptions - Specifies the options that control how the document is saved. Can be null.java.lang.Exceptionpublic SaveOutputParameters save(java.io.OutputStream stream, int saveFormat) throws java.lang.Exception
java.lang.Exceptionpublic SaveOutputParameters save(java.io.OutputStream stream, SaveOptions saveOptions) throws java.lang.Exception
java.lang.Exceptionpublic void ensureMinimum()
public void acceptAllRevisions()
throws java.lang.Exception
RevisionCollection.acceptAll().java.lang.Exceptionpublic void protect(int type)
public void protect(int type,
java.lang.String password)
public void unprotect()
This method unprotects the document even if it has a protection password.
Note that document protection is different from write protection. Write protection is specified using the getWriteProtection().
public boolean unprotect(java.lang.String password)
This method unprotects the document only if a correct password is specified.
Note that document protection is different from write protection. Write protection is specified using the getWriteProtection().
password - The password to unprotect the document with.public void updateWordCount()
throws java.lang.Exception
UpdateWordCount recalculates and updates Characters, Words and Paragraphs properties in the getBuiltInDocumentProperties() collection of the Document.
Note that UpdateWordCount does not update number of lines and pages properties. Use the updateWordCount() overload and pass True value as a parameter to do that.
When you use an evaluation version, the evaluation watermark will also be included in the word count.
java.lang.Exceptionpublic void updateWordCount(boolean updateLinesCount)
throws java.lang.Exception
BuiltInDocumentProperties.getLines() / BuiltInDocumentProperties.setLines(int) property.
This method will rebuild page layout of the document.updateLinesCount - True if number of lines in the document shall be calculated.java.lang.Exceptionpublic void updateTableLayout()
public void updateListLabels()
throws java.lang.Exception
This method updates list label properties such as ListLabel.getLabelValue() and ListLabel.getLabelString() for each Paragraph.getListLabel() object in the document.
Also, this method is sometimes implicitly called when updating fields in the document. This is required because some fields that may reference list numbers (such as TOC or REF) need them be up-to-date.
java.lang.Exceptionpublic void removeMacros()
By removing all macros from a document you can ensure the document contains no macro viruses.
public void updateFields()
throws java.lang.Exception
When you open, modify and then save a document, Aspose.Words does not update fields automatically, it keeps them intact. Therefore, you would usually want to call this method before saving if you have modified the document programmatically and want to make sure the proper (calculated) field values appear in the saved document.
There is no need to update fields after executing a mail merge because mail merge is a kind of field update and automatically updates all fields in the document.
This method does not update all field types. For the detailed list of supported field types, see the Programmers Guide.
This method does not update fields that are related to the page layout algorithms (e.g. PAGE, PAGES, PAGEREF). The page layout-related fields are updated when you render a document or call updatePageLayout().
Use the normalizeFieldTypes() method before fields updating if there were document changes that affected field types.
To update fields in a specific part of the document use Range.updateFields().
java.lang.Exceptionpublic void unlinkFields()
throws java.lang.Exception
Replaces all the fields in the whole document with their most recent results.
To unlink fields in a specific part of the document use Range.unlinkFields().
java.lang.Exceptionpublic void normalizeFieldTypes()
FieldChar.getFieldType() of FieldStart, FieldSeparator, FieldEnd in the whole document so that they correspond to the field types contained in the field codes.
Use this method after document changes that affect field types.
To change field type values in a specific part of the document use Range.normalizeFieldTypes().
public int joinRunsWithSameFormatting()
This is an optimization method. Some documents contain adjacent runs with same formatting. Usually this occurs if a document was intensively edited manually. You can reduce the document size and speed up further processing by joining these runs.
The operation checks every Paragraph node in the document for adjacent Run nodes having identical properties. It ignores unique identifiers used to track editing sessions of run creation and modification. First run in every joining sequence accumulates all text. Remaining runs are deleted from the document.
public void expandTableStylesToDirectFormatting()
throws java.lang.Exception
This method exists because this version of Aspose.Words provides only limited support for table styles (see below). This method might be useful when you load a DOCX or WordprocessingML document that contains tables formatted with table styles and you need to query formatting of tables, cells, paragraphs or text.
This version of Aspose.Words provides limited support for table styles as follows:
java.lang.Exceptionpublic void cleanup()
throws java.lang.Exception
java.lang.Exceptionpublic void cleanup(CleanupOptions options) throws java.lang.Exception
CleanupOptions.java.lang.Exceptionpublic void removeExternalSchemaReferences()
public void startTrackRevisions(java.lang.String author,
java.util.Date dateTime)
If you call this method and then make some changes to the document programmatically, save the document and later open the document in MS Word you will see these changes as revisions.
Currently Aspose.Words supports tracking of node insertions and deletions only. Formatting changes are not recorded as revisions.
Automatic tracking of changes is supported both when modifying this document through node manipulations as well as when using DocumentBuilder
This method does not change the getTrackRevisions() / setTrackRevisions(boolean) option and does not use its value for the purposes of revision tracking.
author - Initials of the author to use for revisions.dateTime - The date and time to use for revisions.stopTrackRevisions()public void startTrackRevisions(java.lang.String author)
If you call this method and then make some changes to the document programmatically, save the document and later open the document in MS Word you will see these changes as revisions.
Currently Aspose.Words supports tracking of node insertions and deletions only. Formatting changes are not recorded as revisions.
Automatic tracking of changes is supported both when modifying this document through node manipulations as well as when using DocumentBuilder
This method does not change the getTrackRevisions() / setTrackRevisions(boolean) option and does not use its value for the purposes of revision tracking.
author - Initials of the author to use for revisions.stopTrackRevisions()public void stopTrackRevisions()
public void compare(Document document, java.lang.String author, java.util.Date dateTime) throws java.lang.Exception
Revision.document - Document to compare.author - Initials of the author to use for revisions.dateTime - The date and time to use for revisions.java.lang.Exceptionpublic void compare(Document document, java.lang.String author, java.util.Date dateTime, CompareOptions options) throws java.lang.Exception
Revision. Allows to specify comparison options using CompareOptions.java.lang.Exceptionpublic void copyStylesFromTemplate(java.lang.String template)
throws java.lang.Exception
java.lang.Exceptionpublic void copyStylesFromTemplate(Document template)
public int getPageCount()
throws java.lang.Exception
java.lang.ExceptionupdatePageLayout()public RevisionCollection getRevisions()
The returned collection is a "live" collection, which means if you remove parts of a document that contain revisions, the deleted revisions will automatically disappear from this collection.
public LayoutOptions getLayoutOptions()
public int getRevisionsView()
RevisionsView.ORIGINAL .RevisionsView constants.public void setRevisionsView(int value)
RevisionsView.ORIGINAL .value - A value indicating whether to work with the original or revised version of a document. The value must be one of RevisionsView constants.public void updatePageLayout()
throws java.lang.Exception
This method formats a document into pages and updates the page number related fields in the document such as PAGE, PAGES, PAGEREF and REF. The up-to-date page layout information is required for a correct rendering of the document to fixed-page formats.
This method is automatically invoked when you first convert a document to PDF, XPS, image or print it. However, if you modify the document after rendering and then attempt to render it again - Aspose.Words will not update the page layout automatically. In this case you should call updatePageLayout() before rendering again.
java.lang.Exceptionpublic java.awt.geom.Point2D.Float renderToScale(int pageIndex,
java.awt.Graphics2D graphics,
float x,
float y,
float scale)
throws java.lang.Exception
pageIndex - The 0-based page index.graphics - The object where to render to.x - The X coordinate (in world units) of the top left corner of the rendered page.y - The Y coordinate (in world units) of the top left corner of the rendered page.scale - The scale for rendering the page (1.0 is 100%).java.lang.Exceptionpublic float renderToSize(int pageIndex,
java.awt.Graphics2D graphics,
float x,
float y,
float width,
float height)
throws java.lang.Exception
pageIndex - The 0-based page index.graphics - The object where to render to.x - The X coordinate (in world units) of the top left corner of the rendered page.y - The Y coordinate (in world units) of the top left corner of the rendered page.width - The maximum width (in world units) that can be occupied by the rendered page.height - The maximum height (in world units) that can be occupied by the rendered page.java.lang.Exceptionpublic void add(Shape watermark) throws java.lang.Exception
java.lang.Exceptionpublic Shape get()
public void remove()
Nodepublic PageInfo getPageInfo(int pageIndex) throws java.lang.Exception
pageIndex - The 0-based page index.java.lang.Exceptionpublic void print()
public void print(java.lang.String printerName)
printerName - The name of the printer.public void print(javax.print.attribute.AttributeSet printerSettings)
The object allows you to specify the printer to print on, the range of pages of to print and other options.
The can contain both to configure PrintJob request and to configure PrintService lookup.
printerSettings - The printer settings to use.public void print(javax.print.attribute.AttributeSet printerSettings,
java.lang.String documentName)
The object allows you to specify the printer to print on, the range of pages of to print and other options.
The can contain both to configure PrintJob request and to configure PrintService lookup.
printerSettings - The printer settings to use.documentName - The document name to display (for example, in a print status dialog box or printer queue) while printing the document.public void updateThumbnail(ThumbnailGeneratingOptions options) throws java.lang.Exception
BuiltInDocumentProperties.getThumbnail() / BuiltInDocumentProperties.setThumbnail(byte[]) of the document according to the specified options.
The ThumbnailGeneratingOptions allows you to specify the source of thumbnail, size and other options. If attempt to generate thumbnail fails, doesn't change one.options - The generating options to use.java.lang.Exceptionpublic void updateThumbnail()
throws java.lang.Exception
BuiltInDocumentProperties.getThumbnail() / BuiltInDocumentProperties.setThumbnail(byte[]) of the document using default options.java.lang.Exceptionpublic Document extractPages(int index, int count) throws java.lang.Exception
Document object representing specified range of pages.
The resulting document should look like the one in MS Word, as if we had performed 'Print specific pages' – the numbering, headers/footers and cross tables layout will be preserved. But due to a large number of nuances, appearing while reducing the number of pages, full match of the layout is a quiet complicated task requiring a lot of effort. Depending on the document complexity there might be slight differences in the resulting document contents layout comparing to the source document. Any feedback would be greatly appreciated.index - The zero-based index of the first page to extract.count - Number of pages to be extracted.java.lang.Exceptionpublic FootnoteOptions getFootnoteOptions()
FootnoteOptions value.public EndnoteOptions getEndnoteOptions()
EndnoteOptions value.public java.lang.Object getDirectSectionAttr(int key)
public java.lang.Object fetchInheritedSectionAttr(int key)
public java.lang.Object fetchSectionAttr(int key)
public void setSectionAttr(int key,
java.lang.Object value)
public void clearSectionAttrs()
public FieldOptions getFieldOptions()
public boolean getRemovePersonalInformation()
public void setRemovePersonalInformation(boolean value)
value - A flag indicating that Microsoft Word will remove all user information from comments, revisions and document properties upon saving the document.public VbaProject getVbaProject()
getVbaProject() / setVbaProject(com.aspose.words.VbaProject).public void setVbaProject(VbaProject value)
value - A getVbaProject() / setVbaProject(com.aspose.words.VbaProject).