Class Document

Class Document

Namespace: Aspose.Words
Assembly: Aspose.Words.dll (25.3.0)

Represents a Word document.

To learn more, visit the Working with Document documentation article.

public class Document : DocumentBase, IEnumerable<node>, IEnumerable, IXPathNavigable

Inheritance

objectNodeCompositeNodeDocumentBaseDocument

Implements

IEnumerable<node>, IEnumerable, IXPathNavigable

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Remarks

The Aspose.Words.Document is a central object in the Aspose.Words library.

To load an existing document in any of the Aspose.Words.LoadFormat formats, pass a file name or a stream into one of the Aspose.Words.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 Aspose.Words.SaveFormat formats.

To draw document pages directly onto a Graphics object use Aspose.Words.Document.RenderToScale(System.Int32,System.Drawing.Graphics,System.Single,System.Single,System.Single) or Aspose.Words.Document.RenderToSize(System.Int32,System.Drawing.Graphics,System.Single,System.Single,System.Single,System.Single) method.

To print the document, use one of the Aspose.Words.Document.Print(System.String) methods.

Aspose.Words.Document.MailMerge 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 DataSet, DataTable, DataView, IDataReader 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.

Aspose.Words.Document stores document-wide information such as Aspose.Words.DocumentBase.Styles, Aspose.Words.Document.BuiltInDocumentProperties, Aspose.Words.Document.CustomDocumentProperties, lists and macros. Most of these objects are accessible via the corresponding properties of the Aspose.Words.Document.

The Aspose.Words.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:

  • The nodes of the document can be accessed via typed collections, for example Aspose.Words.Document.Sections, Aspose.Words.ParagraphCollection etc.
  • The nodes of the document can be selected by their node type using Aspose.Words.CompositeNode.GetChildNodes(Aspose.Words.NodeType,System.Boolean) or using an XPath query with Aspose.Words.CompositeNode.SelectNodes(System.String) or Aspose.Words.CompositeNode.SelectSingleNode(System.String).
  • Content nodes can be added or removed from anywhere in the document using Aspose.Words.CompositeNode.InsertBefore``1(``0,Aspose.Words.Node), Aspose.Words.CompositeNode.InsertAfter``1(``0,Aspose.Words.Node), Aspose.Words.CompositeNode.RemoveChild``1(``0) and other methods provided by the base class Aspose.Words.CompositeNode.
  • The formatting attributes of each node can be changed via the properties of that node.

Consider using Aspose.Words.DocumentBuilder that simplifies the task of programmatically creating or populating the document tree.

The Aspose.Words.Document can contain only Aspose.Words.Section objects.

In Microsoft Word, a valid document needs to have at least one section.

Constructors

Document()

Creates a blank Word document.

public Document()

Remarks

A blank document is retrieved from resources, and by default, the resulting document looks more like created by Aspose.Words.Settings.MsWordVersion.Word2007. This blank document contains a default fonts table, minimal default styles, and latent styles.

Aspose.Words.Settings.CompatibilityOptions.OptimizeFor(Aspose.Words.Settings.MsWordVersion) method can be used to optimize the document contents as well as default Aspose.Words behavior to a particular version of MS Word.

The document paper size is Letter by default. If you want to change page setup, use Aspose.Words.Section.PageSetup.

After creation, you can use Aspose.Words.DocumentBuilder to add document content easily.

Document(string)

Opens an existing document from a file. Automatically detects the file format.

public Document(string fileName)

Parameters

fileName string

File name of the document to open.

Exceptions

UnsupportedFileFormatException

The document format is not recognized or not supported.

FileCorruptedException

The document appears to be corrupted and cannot be loaded.

Exception

There is a problem with the document and it should be reported to Aspose.Words developers.

IOException

There is an input/output exception.

IncorrectPasswordException

The document is encrypted and requires a password to open, but you supplied an incorrect password.

ArgumentException

The name of the file cannot be null or empty string.

Document(string, LoadOptions)

Opens an existing document from a file. Allows to specify additional options such as an encryption password.

public Document(string fileName, LoadOptions loadOptions)

Parameters

fileName string

File name of the document to open.

loadOptions LoadOptions

Additional options to use when loading a document. Can be null.

Exceptions

UnsupportedFileFormatException

The document format is not recognized or not supported.

FileCorruptedException

The document appears to be corrupted and cannot be loaded.

Exception

There is a problem with the document and it should be reported to Aspose.Words developers.

IOException

There is an input/output exception.

IncorrectPasswordException

The document is encrypted and requires a password to open, but you supplied an incorrect password.

ArgumentException

The name of the file cannot be null or empty string.

Document(Stream)

Opens an existing document from a stream. Automatically detects the file format.

public Document(Stream stream)

Parameters

stream Stream

Stream where to load the document from.

Remarks

The document must be stored at the beginning of the stream. The stream must support random positioning.

Exceptions

UnsupportedFileFormatException

The document format is not recognized or not supported.

FileCorruptedException

The document appears to be corrupted and cannot be loaded.

Exception

There is a problem with the document and it should be reported to Aspose.Words developers.

IOException

There is an input/output exception.

IncorrectPasswordException

The document is encrypted and requires a password to open, but you supplied an incorrect password.

ArgumentNullException

The stream cannot be null.

NotSupportedException

The stream does not support reading or seeking.

ObjectDisposedException

The stream is a disposed object.

Document(Stream, LoadOptions)

Opens an existing document from a stream. Allows to specify additional options such as an encryption password.

public Document(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

The stream where to load the document from.

loadOptions LoadOptions

Additional options to use when loading a document. Can be null.

Remarks

The document must be stored at the beginning of the stream. The stream must support random positioning.

Exceptions

UnsupportedFileFormatException

The document format is not recognized or not supported.

FileCorruptedException

The document appears to be corrupted and cannot be loaded.

Exception

There is a problem with the document and it should be reported to Aspose.Words developers.

IOException

There is an input/output exception.

IncorrectPasswordException

The document is encrypted and requires a password to open, but you supplied an incorrect password.

ArgumentNullException

The stream cannot be null.

NotSupportedException

The stream does not support reading or seeking.

ObjectDisposedException

The stream is a disposed object.

Properties

AttachedTemplate

Gets or sets the full path of the template attached to the document.

public string AttachedTemplate { get; set; }

Property Value

string

Remarks

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

Aspose.Words.Properties.BuiltInDocumentProperties.Template

Exceptions

ArgumentNullException

Throws if you attempt to set to a null value.

AutomaticallyUpdateStyles

Gets or 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.

public bool AutomaticallyUpdateStyles { get; set; }

Property Value

bool

Bibliography

Gets the Aspose.Words.Document.Bibliography object that represents the list of sources available in the document.

public Bibliography Bibliography { get; }

Property Value

Bibliography

BuiltInDocumentProperties

Returns a collection that represents all the built-in document properties of the document.

public BuiltInDocumentProperties BuiltInDocumentProperties { get; }

Property Value

BuiltInDocumentProperties

CompatibilityOptions

Provides access to document compatibility options (that is, the user preferences entered on the Compatibility tab of the Options dialog in Word).

public CompatibilityOptions CompatibilityOptions { get; }

Property Value

CompatibilityOptions

Compliance

Gets the OOXML compliance version determined from the loaded document content. Makes sense only for OOXML documents.

public OoxmlCompliance Compliance { get; }

Property Value

OoxmlCompliance

Remarks

If you created a new blank document or load non OOXML document returns the Aspose.Words.Saving.OoxmlCompliance.Ecma376_2006 value.

CustomDocumentProperties

Returns a collection that represents all the custom document properties of the document.

public CustomDocumentProperties CustomDocumentProperties { get; }

Property Value

CustomDocumentProperties

CustomXmlParts

Gets or sets the collection of Custom XML Data Storage Parts.

public CustomXmlPartCollection CustomXmlParts { get; set; }

Property Value

CustomXmlPartCollection

Remarks

Aspose.Words loads and saves Custom XML Parts into OOXML and DOC documents only.

This property cannot be null.

Aspose.Words.Markup.CustomXmlPart

DefaultTabStop

Gets or sets the interval (in points) between the default tab stops.

public double DefaultTabStop { get; set; }

Property Value

double

See Also

TabStopCollection, TabStop

DigitalSignatures

Gets the collection of digital signatures for this document and their validation results.

public DigitalSignatureCollection DigitalSignatures { get; }

Property Value

DigitalSignatureCollection

Remarks

This collection contains digital signatures that were loaded from the original document. These digital signatures will not be saved when you save this Aspose.Words.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.

EndnoteOptions

Provides options that control numbering and positioning of endnotes in this document.

public EndnoteOptions EndnoteOptions { get; }

Property Value

EndnoteOptions

FieldOptions

Gets a Aspose.Words.Fields.FieldOptions object that represents options to control field handling in the document.

public FieldOptions FieldOptions { get; }

Property Value

FieldOptions

FirstSection

Gets the first section in the document.

public Section FirstSection { get; }

Property Value

Section

Remarks

Returns null if there are no sections.

FontSettings

Gets or sets document font settings.

public FontSettings FontSettings { get; set; }

Property Value

FontSettings

Remarks

This property allows to specify font settings per document. If set to null, default static font settings Aspose.Words.Fonts.FontSettings.DefaultInstance will be used.

The default value is null.

FootnoteOptions

Provides options that control numbering and positioning of footnotes in this document.

public FootnoteOptions FootnoteOptions { get; }

Property Value

FootnoteOptions

Frameset

Returns a Aspose.Words.Document.Frameset instance if this document represents a frames page.

public Frameset Frameset { get; }

Property Value

Frameset

Remarks

If the document is not framed, the property has the null value.

GlossaryDocument

Gets or sets the glossary document within this document or template. A glossary document is a storage for AutoText, AutoCorrect and Building Block entries defined in a document.

public GlossaryDocument GlossaryDocument { get; set; }

Property Value

GlossaryDocument

Remarks

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 Aspose.Words.BuildingBlocks.GlossaryDocument object and assigning to this property.

Aspose.Words.BuildingBlocks.GlossaryDocument

GrammarChecked

Returns true if the document has been checked for grammar.

public bool GrammarChecked { get; set; }

Property Value

bool

Remarks

To recheck the grammar in the document, set this property to false.

HasMacros

Returns true if the document has a VBA project (macros).

public bool HasMacros { get; }

Property Value

bool

See Also

Document.RemoveMacros()

HasRevisions

Returns true if the document has any tracked changes.

public bool HasRevisions { get; }

Property Value

bool

Remarks

This property is a shortcut for comparing Aspose.Words.RevisionCollection.Count to zero.

HyphenationOptions

Provides access to document hyphenation options.

public HyphenationOptions HyphenationOptions { get; }

Property Value

HyphenationOptions

IncludeTextboxesFootnotesEndnotesInStat

Specifies whether to include textboxes, footnotes and endnotes in word count statistics.

public bool IncludeTextboxesFootnotesEndnotesInStat { get; set; }

Property Value

bool

JustificationMode

Gets or sets the character spacing adjustment of a document.

public JustificationMode JustificationMode { get; set; }

Property Value

JustificationMode

LastSection

Gets the last section in the document.

public Section LastSection { get; }

Property Value

Section

Remarks

Returns null if there are no sections.

LayoutOptions

Gets a Aspose.Words.Layout.LayoutOptions object that represents options to control the layout process of this document.

public LayoutOptions LayoutOptions { get; }

Property Value

LayoutOptions

MailMerge

Returns a Aspose.Words.MailMerging.MailMerge object that represents the mail merge functionality for the document.

public MailMerge MailMerge { get; }

Property Value

MailMerge

MailMergeSettings

Gets or sets the object that contains all of the mail merge information for a document.

public MailMergeSettings MailMergeSettings { get; set; }

Property Value

MailMergeSettings

Remarks

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.

NodeType

Returns Aspose.Words.NodeType.Document.

public override NodeType NodeType { get; }

Property Value

NodeType

OriginalFileName

Gets the original file name of the document.

public string OriginalFileName { get; }

Property Value

string

Remarks

Returns null if the document was loaded from a stream or created blank.

OriginalLoadFormat

Gets the format of the original document that was loaded into this object.

public LoadFormat OriginalLoadFormat { get; }

Property Value

LoadFormat

Remarks

If you created a new blank document, returns the Aspose.Words.LoadFormat.Doc value.

PackageCustomParts

Gets or sets the collection of custom parts (arbitrary content) that are linked to the OOXML package using “unknown relationships”.

public CustomPartCollection PackageCustomParts { get; set; }

Property Value

CustomPartCollection

Remarks

Do not confuse these custom parts with Custom XML Data. If you need to access Custom XML parts, use the Aspose.Words.Document.CustomXmlParts property.

This collection contains OOXML parts whose parent is the OOXML package and they targets are of an "unknown relationship". For more information see Aspose.Words.Markup.CustomPart.

Aspose.Words loads and saves custom parts into OOXML documents only.

This property cannot be null.

Aspose.Words.Markup.CustomPart

PageCount

Gets the number of pages in the document as calculated by the most recent page layout operation.

public int PageCount { get; }

Property Value

int

See Also

Document.UpdatePageLayout()

ProtectionType

Gets the currently active document protection type.

public ProtectionType ProtectionType { get; }

Property Value

ProtectionType

Remarks

This property allows to retrieve the currently set document protection type. To change the document protection type use the Aspose.Words.Document.Protect(Aspose.Words.ProtectionType,System.String) and Aspose.Words.Document.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 Aspose.Words.Document.WriteProtection

Aspose.Words.Document.Protect(Aspose.Words.ProtectionType,System.String) Aspose.Words.Document.Unprotect Aspose.Words.Document.WriteProtection

PunctuationKerning

Specifies whether kerning applies to both Latin text and punctuation.

public bool PunctuationKerning { get; set; }

Property Value

bool

RemovePersonalInformation

Gets or sets a flag indicating that Microsoft Word will remove all user information from comments, revisions and document properties upon saving the document.

public bool RemovePersonalInformation { get; set; }

Property Value

bool

Revisions

Gets a collection of revisions (tracked changes) that exist in this document.

public RevisionCollection Revisions { get; }

Property Value

RevisionCollection

Remarks

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.

RevisionsView

Gets or sets a value indicating whether to work with the original or revised version of a document.

public RevisionsView RevisionsView { get; set; }

Property Value

RevisionsView

Remarks

The default value is Aspose.Words.RevisionsView.Original.

Sections

Returns a collection that represents all sections in the document.

public SectionCollection Sections { get; }

Property Value

SectionCollection

ShadeFormData

Specifies whether to turn on the gray shading on form fields.

public bool ShadeFormData { get; set; }

Property Value

bool

ShowGrammaticalErrors

Specifies whether to display grammar errors in this document.

public bool ShowGrammaticalErrors { get; set; }

Property Value

bool

ShowSpellingErrors

Specifies whether to display spelling errors in this document.

public bool ShowSpellingErrors { get; set; }

Property Value

bool

SpellingChecked

Returns true if the document has been checked for spelling.

public bool SpellingChecked { get; set; }

Property Value

bool

Remarks

To recheck the spelling in the document, set this property to false.

Theme

Gets the Aspose.Words.Document.Theme object for this document.

public Theme Theme { get; }

Property Value

Theme

TrackRevisions

True if changes are tracked when this document is edited in Microsoft Word.

public bool TrackRevisions { get; set; }

Property Value

bool

Remarks

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 Aspose.Words.Document.StartTrackRevisions(System.String,System.DateTime) method.

Variables

Returns the collection of variables added to a document or template.

public VariableCollection Variables { get; }

Property Value

VariableCollection

VbaProject

Gets or sets a Aspose.Words.Document.VbaProject.

public VbaProject VbaProject { get; set; }

Property Value

VbaProject

VersionsCount

Gets the number of document versions that was stored in the DOC document.

public int VersionsCount { get; }

Property Value

int

Remarks

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.

ViewOptions

Provides options to control how the document is displayed in Microsoft Word.

public ViewOptions ViewOptions { get; }

Property Value

ViewOptions

Watermark

Provides access to the document watermark.

public Watermark Watermark { get; }

Property Value

Watermark

WebExtensionTaskPanes

Returns a collection that represents a list of task pane add-ins.

public TaskPaneCollection WebExtensionTaskPanes { get; }

Property Value

TaskPaneCollection

WriteProtection

Provides access to the document write protection options.

public WriteProtection WriteProtection { get; }

Property Value

WriteProtection

Methods

Accept(DocumentVisitor)

Accepts a visitor.

public override bool Accept(DocumentVisitor visitor)

Parameters

visitor DocumentVisitor

The visitor that will visit the nodes.

Returns

bool

True if all nodes were visited; false if Aspose.Words.DocumentVisitor stopped the operation before visiting all nodes.

Remarks

Enumerates over this node and all of its children. Each node calls a corresponding method on Aspose.Words.DocumentVisitor.

For more info see the Visitor design pattern.

AcceptAllRevisions()

Accepts all tracked changes in the document.

public void AcceptAllRevisions()

Remarks

This method is a shortcut for Aspose.Words.RevisionCollection.AcceptAll.

AcceptEnd(DocumentVisitor)

Accepts a visitor for visiting the end of the document.

public override VisitorAction AcceptEnd(DocumentVisitor visitor)

Parameters

visitor DocumentVisitor

The document visitor.

Returns

VisitorAction

The action to be taken by the visitor.

AcceptStart(DocumentVisitor)

Accepts a visitor for visiting the start of the document.

public override VisitorAction AcceptStart(DocumentVisitor visitor)

Parameters

visitor DocumentVisitor

The document visitor.

Returns

VisitorAction

The action to be taken by the visitor.

AppendDocument(Document, ImportFormatMode)

Appends the specified document to the end of this document.

public void AppendDocument(Document srcDoc, ImportFormatMode importFormatMode)

Parameters

srcDoc Document

The document to append.

importFormatMode ImportFormatMode

Specifies how to merge style formatting that clashes.

AppendDocument(Document, ImportFormatMode, ImportFormatOptions)

Appends the specified document to the end of this document.

public void AppendDocument(Document srcDoc, ImportFormatMode importFormatMode, ImportFormatOptions importFormatOptions)

Parameters

srcDoc Document

The document to append.

importFormatMode ImportFormatMode

Specifies how to merge style formatting that clashes.

importFormatOptions ImportFormatOptions

Allows to specify options that affect formatting of a result document.

Cleanup()

Cleans unused styles and lists from the document.

public void Cleanup()

Cleanup(CleanupOptions)

Cleans unused styles and lists from the document depending on given Aspose.Words.CleanupOptions.

public void Cleanup(CleanupOptions options)

Parameters

options CleanupOptions

Clone()

Performs a deep copy of the Aspose.Words.Document.

public Document Clone()

Returns

Document

The cloned document.

Compare(Document, string, DateTime)

Compares this document with another document producing changes as number of edit and format revisions Aspose.Words.Revision.

public void Compare(Document document, string author, DateTime dateTime)

Parameters

document Document

Document to compare.

author string

Initials of the author to use for revisions.

dateTime DateTime

The date and time to use for revisions.

Remarks

note

Documents must not have revisions before comparison.

Compare(Document, string, DateTime, CompareOptions)

Compares this document with another document producing changes as a number of edit and format revisions Aspose.Words.Revision. Allows to specify comparison options using Aspose.Words.Comparing.CompareOptions.

public void Compare(Document document, string author, DateTime dateTime, CompareOptions options)

Parameters

document Document

author string

dateTime DateTime

options CompareOptions

CopyStylesFromTemplate(string)

Copies styles from the specified template to a document.

public void CopyStylesFromTemplate(string template)

Parameters

template string

Remarks

When styles are copied from a template to a document, like-named styles in the document are redefined to match the style descriptions in the template. Unique styles from the template are copied to the document. Unique styles in the document remain intact.

CopyStylesFromTemplate(Document)

Copies styles from the specified template to a document.

public void CopyStylesFromTemplate(Document template)

Parameters

template Document

Remarks

When styles are copied from a template to a document, like-named styles in the document are redefined to match the style descriptions in the template. Unique styles from the template are copied to the document. Unique styles in the document remain intact.

EnsureMinimum()

If the document contains no sections, creates one section with one paragraph.

public void EnsureMinimum()

ExpandTableStylesToDirectFormatting()

Converts formatting specified in table styles into direct formatting on tables in the document.

public void ExpandTableStylesToDirectFormatting()

Remarks

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:

  • Table styles defined in DOCX or WordprocessingML documents are preserved as table styles when saving the document as DOCX or WordprocessingML.
  • Table styles defined in DOCX or WordprocessingML documents are automatically converted to direct formatting on tables when saving the document into any other format, rendering or printing.
  • Table styles defined in DOC documents are preserved as table styles when saving the document as DOC only.

ExtractPages(int, int)

Returns the Aspose.Words.Document object representing specified range of pages.

public Document ExtractPages(int index, int count)

Parameters

index int

The zero-based index of the first page to extract.

count int

Number of pages to be extracted.

Returns

Document

Remarks

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.

GetPageInfo(int)

Gets the page size, orientation and other information about a page that might be useful for printing or rendering.

public PageInfo GetPageInfo(int pageIndex)

Parameters

pageIndex int

The 0-based page index.

Returns

PageInfo

JoinRunsWithSameFormatting()

Joins runs with same formatting in all paragraphs of the document.

public int JoinRunsWithSameFormatting()

Returns

int

Number of joins performed. When N adjacent runs are being joined they count as N - 1 joins.

Remarks

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 Aspose.Words.Paragraph node in the document for adjacent Aspose.Words.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.

NormalizeFieldTypes()

Changes field type values Aspose.Words.Fields.FieldChar.FieldType of Aspose.Words.Fields.FieldStart, Aspose.Words.Fields.FieldSeparator, Aspose.Words.Fields.FieldEnd in the whole document so that they correspond to the field types contained in the field codes.

public void NormalizeFieldTypes()

Remarks

Use this method after document changes that affect field types.

To change field type values in a specific part of the document use Aspose.Words.Range.NormalizeFieldTypes.

Protect(ProtectionType)

Protects the document from changes without changing the existing password or assigns a random password.

public void Protect(ProtectionType type)

Parameters

type ProtectionType

Specifies the protection type for the document.

Remarks

When a document is protected, the user can make only limited changes, such as adding annotations, making revisions, or completing a form.

When you protect a document, and the document already has a protection password, the existing protection password is not changed.

When you protect a document, and the document does not have a protection password, this method assigns a random password that makes it impossible to unprotect the document in Microsoft Word, but you still can unprotect the document in Aspose.Words as it does not require a password when unprotecting.

Protect(ProtectionType, string)

Protects the document from changes and optionally sets a protection password.

public void Protect(ProtectionType type, string password)

Parameters

type ProtectionType

Specifies the protection type for the document.

password string

The password to protect the document with. Specify null or empty string if you want to protect the document without a password.

Remarks

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 Aspose.Words.Document.WriteProtection.

RemoveBlankPages()

Removes blank pages from the document.

public List<int> RemoveBlankPages()

Returns

List<int&gt;

List of page numbers has been considered as blank and removed.

Remarks

The resulting document will not contain pages considered to be blank while other content, including numbering, headers/footers and overall layout should remain unchanged.

Page is considered to be blank when body of the page have no visible content, for example, empty table having no borders will be considered as invisible and therefore page will be detected as blank.

RemoveExternalSchemaReferences()

Removes external XML schema references from this document.

public void RemoveExternalSchemaReferences()

RemoveMacros()

Removes all macros (the VBA project) as well as toolbars and command customizations from the document.

public void RemoveMacros()

Remarks

By removing all macros from a document you can ensure the document contains no macro viruses.

RenderToScale(int, SKCanvas, float, float, float)

[CLSCompliant(false)]
public SizeF RenderToScale(int pageIndex, SKCanvas graphics, float x, float y, float scale)

Parameters

pageIndex int

graphics SKCanvas

x float

y float

scale float

Returns

SizeF

RenderToSize(int, SKCanvas, float, float, float, float)

[CLSCompliant(false)]
public float RenderToSize(int pageIndex, SKCanvas graphics, float x, float y, float width, float height)

Parameters

pageIndex int

graphics SKCanvas

x float

y float

width float

height float

Returns

float

Save(string)

Saves the document to a file. Automatically determines the save format from the extension.

public SaveOutputParameters Save(string fileName)

Parameters

fileName string

The name for the document. If a document with the specified file name already exists, the existing document is overwritten.

Returns

SaveOutputParameters

Additional information that you can optionally use.

Save(string, SaveFormat)

Saves the document to a file in the specified format.

public SaveOutputParameters Save(string fileName, SaveFormat saveFormat)

Parameters

fileName string

The name for the document. If a document with the specified file name already exists, the existing document is overwritten.

saveFormat SaveFormat

The format in which to save the document.

Returns

SaveOutputParameters

Additional information that you can optionally use.

Save(string, SaveOptions)

Saves the document to a file using the specified save options.

public SaveOutputParameters Save(string fileName, SaveOptions saveOptions)

Parameters

fileName string

The name for the document. If a document with the specified file name already exists, the existing document is overwritten.

saveOptions SaveOptions

Specifies the options that control how the document is saved. Can be null.

Returns

SaveOutputParameters

Additional information that you can optionally use.

Save(Stream, SaveFormat)

Saves the document to a stream using the specified format.

public SaveOutputParameters Save(Stream stream, SaveFormat saveFormat)

Parameters

stream Stream

Stream where to save the document.

saveFormat SaveFormat

The format in which to save the document.

Returns

SaveOutputParameters

Additional information that you can optionally use.

Save(Stream, SaveOptions)

Saves the document to a stream using the specified save options.

public SaveOutputParameters Save(Stream stream, SaveOptions saveOptions)

Parameters

stream Stream

Stream where to save the document.

saveOptions SaveOptions

Specifies the options that control how the document is saved. Can be null. If this is null, the document will be saved in the binary DOC format.

Returns

SaveOutputParameters

Additional information that you can optionally use.

StartTrackRevisions(string, DateTime)

Starts automatically marking all further changes you make to the document programmatically as revision changes.

public void StartTrackRevisions(string author, DateTime dateTime)

Parameters

author string

Initials of the author to use for revisions.

dateTime DateTime

The date and time to use for revisions.

Remarks

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 Aspose.Words.DocumentBuilder

This method does not change the Aspose.Words.Document.TrackRevisions option and does not use its value for the purposes of revision tracking.

See Also

Document.StopTrackRevisions()

StartTrackRevisions(string)

Starts automatically marking all further changes you make to the document programmatically as revision changes.

public void StartTrackRevisions(string author)

Parameters

author string

Initials of the author to use for revisions.

Remarks

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 Aspose.Words.DocumentBuilder

This method does not change the Aspose.Words.Document.TrackRevisions option and does not use its value for the purposes of revision tracking.

See Also

Document.StopTrackRevisions()

StopTrackRevisions()

Stops automatic marking of document changes as revisions.

public void StopTrackRevisions()

See Also

Document.StartTrackRevisions(string, DateTime)

UnlinkFields()

Unlinks fields in the whole document.

public void UnlinkFields()

Remarks

Replaces all the fields in the whole document with their most recent results.

To unlink fields in a specific part of the document use Aspose.Words.Range.UnlinkFields.

Unprotect()

Removes protection from the document regardless of the password.

public void Unprotect()

Remarks

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 Aspose.Words.Document.WriteProtection.

Unprotect(string)

Removes protection from the document if a correct password is specified.

public bool Unprotect(string password)

Parameters

password string

The password to unprotect the document with.

Returns

bool

true if a correct password was specified and the document was unprotected.

Remarks

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 Aspose.Words.Document.WriteProtection.

UpdateActualReferenceMarks()

Updates the Aspose.Words.Notes.Footnote.ActualReferenceMark property of all footnotes and endnotes in the document.

public void UpdateActualReferenceMarks()

Remarks

Updating fields (Aspose.Words.Document.UpdateFields) may be necessary to get the correct result.

UpdateFields()

Updates the values of fields in the whole document.

public void UpdateFields()

Remarks

<p>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 Aspose.Words.Document.UpdatePageLayout.

Use the Aspose.Words.Document.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 Aspose.Words.Range.UpdateFields.

UpdateListLabels()

Updates list labels for all list items in the document.

public void UpdateListLabels()

Remarks

This method updates list label properties such as Aspose.Words.Lists.ListLabel.LabelValue and Aspose.Words.Lists.ListLabel.LabelString for each Aspose.Words.Paragraph.ListLabel 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.

UpdatePageLayout()

Rebuilds the page layout of the document.

public void UpdatePageLayout()

Remarks

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 Aspose.Words.Document.UpdatePageLayout before rendering again.

UpdateTableLayout()

Implements an earlier approach to table column widths re-calculation that has known issues.

[Obsolete("Obsolete, column widths are re-calculated automatically before saving.")]
public void UpdateTableLayout()

Remarks

The method is deprecated and it will be removed in a few releases.

UpdateThumbnail(ThumbnailGeneratingOptions)

Updates Aspose.Words.Properties.BuiltInDocumentProperties.Thumbnail of the document according to the specified options.

public void UpdateThumbnail(ThumbnailGeneratingOptions options)

Parameters

options ThumbnailGeneratingOptions

The generating options to use.

Remarks

The Aspose.Words.Rendering.ThumbnailGeneratingOptions allows you to specify the source of thumbnail, size and other options. If attempt to generate thumbnail fails, doesn’t change one.

UpdateThumbnail()

Updates Aspose.Words.Properties.BuiltInDocumentProperties.Thumbnail of the document using default options.

public void UpdateThumbnail()

UpdateWordCount()

Updates word count properties of the document.

public void UpdateWordCount()

Remarks

Aspose.Words.Document.UpdateWordCount recalculates and updates Characters, Words and Paragraphs properties in the Aspose.Words.Document.BuiltInDocumentProperties collection of the Aspose.Words.Document.

Note that Aspose.Words.Document.UpdateWordCount does not update number of lines and pages properties. Use the Aspose.Words.Document.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.

UpdateWordCount(bool)

Updates word count properties of the document, optionally updates Aspose.Words.Properties.BuiltInDocumentProperties.Lines property.

public void UpdateWordCount(bool updateLinesCount)

Parameters

updateLinesCount bool

true if number of lines in the document shall be calculated.

Remarks

This method will rebuild page layout of the document. </node>

 English