• DR-IT Software
  • Products
  • Documentation
  • Product page
  • Examples
  • API reference
  • Support
Show / Hide Table of Contents

Class Document

Represents a Document.

Inheritance
object
Node
CompositeNode
DocumentBase
Document
Implements
IEnumerable<Node>
IEnumerable
IDisposable
Inherited Members
DocumentBase.FontInfos
DocumentBase.Styles
DocumentBase.Lists
CompositeNode.ChildNodes
CompositeNode.GetAllChildNodes()
CompositeNode.Count
CompositeNode.FirstChild
CompositeNode.HasChildNodes
CompositeNode.IsComposite
CompositeNode.LastChild
CompositeNode.GetEnumerator()
Node.Document
Node.NextSibling
Node.ParentNode
Node.PreviousSibling
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: DRIT.Document
Assembly: DRIT.Document.dll
Syntax
public class Document : DocumentBase, IEnumerable<Node>, IEnumerable, IDisposable

Constructors

Document()

Creates an empty document with one initial section.

Declaration
public Document()

Document(byte[])

Loads a document from the specified package or text bytes.

Declaration
public Document(byte[] packageBytes)
Parameters
Type Name Description
byte[] packageBytes

The bytes containing the document package or text.

Document(byte[], DocumentLoadOptions)

Loads a document from bytes using the specified load options.

Declaration
public Document(byte[] packageBytes, DocumentLoadOptions options)
Parameters
Type Name Description
byte[] packageBytes

The bytes containing the document package or text.

DocumentLoadOptions options

The options that control format detection, loading, and cancellation.

Document(Stream)

Loads a document from the specified stream.

Declaration
public Document(Stream stream)
Parameters
Type Name Description
Stream stream

The readable stream containing the document package or text.

Document(Stream, DocumentLoadOptions)

Loads a document from a stream using the specified load options.

Declaration
public Document(Stream stream, DocumentLoadOptions options)
Parameters
Type Name Description
Stream stream

The readable stream containing the document package or text.

DocumentLoadOptions options

The options that control format detection, loading, and cancellation.

Document(string)

Loads a document from the specified file.

Declaration
public Document(string fileName)
Parameters
Type Name Description
string fileName

The path of the file to load.

Document(string, DocumentLoadOptions)

Loads a document from a file using the specified load options.

Declaration
public Document(string fileName, DocumentLoadOptions options)
Parameters
Type Name Description
string fileName

The path of the file to load.

DocumentLoadOptions options

The options that control format detection, loading, and cancellation.

Properties

AttachedTemplate

Gets or sets the template attached to this document.

Declaration
public string AttachedTemplate { get; set; }
Property Value
Type Description
string

AutomaticallyUpdateSyles

Gets or sets whether styles are automatically updated from the attached template.

Declaration
public bool AutomaticallyUpdateSyles { get; set; }
Property Value
Type Description
bool

Bibliography

Gets the bibliography sources associated with this document.

Declaration
public Bibliography Bibliography { get; }
Property Value
Type Description
Bibliography

Bookmarks

Gets the bookmarks declared in this document.

Declaration
public BookmarkCollection Bookmarks { get; }
Property Value
Type Description
BookmarkCollection

BuiltInDocumentProperties

Gets the built-in properties associated with this document.

Declaration
public BuiltInDocumentProperties BuiltInDocumentProperties { get; }
Property Value
Type Description
BuiltInDocumentProperties

Comments

Gets the comments contained in this document.

Declaration
public CommentCollection Comments { get; }
Property Value
Type Description
CommentCollection

CompatibilityOptions

Gets the Microsoft Word compatibility settings for the document.

Declaration
public CompatibilityOptions CompatibilityOptions { get; }
Property Value
Type Description
CompatibilityOptions

Content

Gets an aggregate range covering the document's section-owned main story.

Declaration
public DocumentContentRange Content { get; }
Property Value
Type Description
DocumentContentRange

ConversionDiagnostics

Gets read-only outcomes from the most recent cross-format conversion. The snapshot contains semantic diagnostics without exposing format implementation types.

Declaration
public ConversionIssueCollection ConversionDiagnostics { get; }
Property Value
Type Description
ConversionIssueCollection

CustomXmlParts

Gets the collection of custom XML parts stored in the document package.

Declaration
public CustomXmlPartCollection CustomXmlParts { get; }
Property Value
Type Description
CustomXmlPartCollection

DocumentSettings

Gets the settings that control this document's WordprocessingML behavior.

Declaration
public DocumentSettings DocumentSettings { get; }
Property Value
Type Description
DocumentSettings

EditableRanges

Gets the editable ranges declared in the document.

Declaration
public EditableRangeCollection EditableRanges { get; }
Property Value
Type Description
EditableRangeCollection

Endnotes

Gets the endnotes contained in this document.

Declaration
public NoteCollection Endnotes { get; }
Property Value
Type Description
NoteCollection

FileName

Gets or sets the file name of the document. When the document was loaded from disk this is the source path; after Save(string) it is the save path.

Declaration
public string FileName { get; set; }
Property Value
Type Description
string

FootnoteSeparators

Gets the editable separator stories for footnotes and endnotes.

Declaration
public FootnoteSeparatorCollection FootnoteSeparators { get; }
Property Value
Type Description
FootnoteSeparatorCollection

Footnotes

Gets the footnotes contained in this document.

Declaration
public NoteCollection Footnotes { get; }
Property Value
Type Description
NoteCollection

FormFieldsData

Gets a collection of all form fields in the document, accessible by name or index. Returns a snapshot of the form fields currently in the document model.

Declaration
public FormFieldDataCollection FormFieldsData { get; }
Property Value
Type Description
FormFieldDataCollection

Frameset

Gets the legacy Word frames page and its child frames.

Declaration
public Frameset Frameset { get; }
Property Value
Type Description
Frameset

GlossaryDocument

Gets the glossary document containing the document's Quick Parts and building blocks.

Declaration
public GlossaryDocument GlossaryDocument { get; }
Property Value
Type Description
GlossaryDocument

MailMerge

Gets the mail-merge engine for this document.

Declaration
public MailMerge MailMerge { get; }
Property Value
Type Description
MailMerge

NodeType

Gets the node type for this object, which is Document.

Declaration
public override NodeType NodeType { get; }
Property Value
Type Description
NodeType
Overrides
Node.NodeType

Properties

Gets the document properties (summary, statistics, and custom properties). On a from-scratch document this returns a default DocumentProperties instance. On a loaded document this returns the properties read from the package.

Declaration
public DocumentProperties Properties { get; }
Property Value
Type Description
DocumentProperties

RevisionOptions

Gets the display options and selected original/final view for revisions.

Declaration
public RevisionOptions RevisionOptions { get; }
Property Value
Type Description
RevisionOptions

Revisions

Gets a collection of all tracked-change revisions in this document. Use AcceptAll()/RejectAll() or iterate and call Accept()/Reject() per revision.

Declaration
public RevisionCollection Revisions { get; }
Property Value
Type Description
RevisionCollection

Sections

Gets the sections that make up this document.

Declaration
public SectionCollection Sections { get; }
Property Value
Type Description
SectionCollection

TemplateGlossaryEntries

Gets the names of glossary entries supplied by the attached template.

Declaration
public IReadOnlyList<string> TemplateGlossaryEntries { get; }
Property Value
Type Description
IReadOnlyList<string>

Theme

Gets the document theme used for theme-aware formatting.

Declaration
public Theme Theme { get; }
Property Value
Type Description
Theme

Variables

Gets the document variables collection (string name → string value). Maps to w:docVars in settings.xml. Used by fields and macros.

Declaration
public VariableCollection Variables { get; }
Property Value
Type Description
VariableCollection

VbaProject

Gets the VBA project for this document, creating a ThisDocument project when needed.

Declaration
public Project VbaProject { get; }
Property Value
Type Description
Project

ViewOptions

Gets the view and zoom settings used when the document is opened.

Declaration
public ViewOptions ViewOptions { get; }
Property Value
Type Description
ViewOptions

Methods

Accept(DocumentVisitor)

Traverses this document with the supplied visitor.

Declaration
public VisitorAction Accept(DocumentVisitor visitor)
Parameters
Type Name Description
DocumentVisitor visitor

The visitor that receives callbacks for document nodes.

Returns
Type Description
VisitorAction

The action that stopped traversal, or Continue when traversal completed.

AddEndnote(string)

Adds an endnote containing the specified text.

Declaration
public Footnote AddEndnote(string text)
Parameters
Type Name Description
string text

The text of the endnote.

Returns
Type Description
Footnote

The newly added endnote.

AddFootnote(string)

Adds a footnote containing the specified text.

Declaration
public Footnote AddFootnote(string text)
Parameters
Type Name Description
string text

The text of the footnote.

Returns
Type Description
Footnote

The newly added footnote.

AddSection()

Adds a section to the end of the document.

Declaration
public Section AddSection()
Returns
Type Description
Section

The newly added section.

AppendDigitalSignature(string, DocxDigitalSignatureSaveOptions)

Appends a single digital signature to an existing DOCX file.

Declaration
public static void AppendDigitalSignature(string path, DocxDigitalSignatureSaveOptions signature)
Parameters
Type Name Description
string path
DocxDigitalSignatureSaveOptions signature

AppendDigitalSignatures(Stream, DocumentLoadOptions, DocumentSaveOptions, IEnumerable<DocxDigitalSignatureSaveOptions>)

Appends signatures to an encrypted or unencrypted DOCX stream and applies the requested output encryption.

Declaration
public static void AppendDigitalSignatures(Stream stream, DocumentLoadOptions loadOptions, DocumentSaveOptions saveOptions, IEnumerable<DocxDigitalSignatureSaveOptions> signatures)
Parameters
Type Name Description
Stream stream

The readable and writable DOCX stream.

DocumentLoadOptions loadOptions

The options used to decrypt the existing package.

DocumentSaveOptions saveOptions

The options used to encrypt the updated package, or null for unencrypted output.

IEnumerable<DocxDigitalSignatureSaveOptions> signatures

The signatures to append.

AppendDigitalSignatures(Stream, IEnumerable<DocxDigitalSignatureSaveOptions>)

Appends digital signatures to a DOCX stream without closing the stream.

Declaration
public static void AppendDigitalSignatures(Stream stream, IEnumerable<DocxDigitalSignatureSaveOptions> signatures)
Parameters
Type Name Description
Stream stream

The readable and writable DOCX stream.

IEnumerable<DocxDigitalSignatureSaveOptions> signatures

The signatures to append.

AppendDigitalSignatures(string, DocumentLoadOptions, DocumentSaveOptions, IEnumerable<DocxDigitalSignatureSaveOptions>)

Appends signatures to an encrypted or unencrypted DOCX file and applies the requested output encryption.

Declaration
public static void AppendDigitalSignatures(string path, DocumentLoadOptions loadOptions, DocumentSaveOptions saveOptions, IEnumerable<DocxDigitalSignatureSaveOptions> signatures)
Parameters
Type Name Description
string path

The DOCX file path.

DocumentLoadOptions loadOptions

The options used to decrypt the existing package.

DocumentSaveOptions saveOptions

The options used to encrypt the updated package, or null for unencrypted output.

IEnumerable<DocxDigitalSignatureSaveOptions> signatures

The signatures to append.

AppendDigitalSignatures(string, IEnumerable<DocxDigitalSignatureSaveOptions>)

Appends multiple digital signatures to an existing DOCX file.

Declaration
public static void AppendDigitalSignatures(string path, IEnumerable<DocxDigitalSignatureSaveOptions> signatures)
Parameters
Type Name Description
string path
IEnumerable<DocxDigitalSignatureSaveOptions> signatures

AppendDocument(Document, ImportFormatMode)

Appends the content of another document to the active story.

Declaration
public void AppendDocument(Document sourceDocument, ImportFormatMode importFormatMode)
Parameters
Type Name Description
Document sourceDocument

The document whose content should be appended.

ImportFormatMode importFormatMode

The formatting policy for imported content.

AppendSection(Section, ImportFormatMode)

Appends a copy of one source section, including its body, page setup, headers, footers, and section-scoped preservation data.

Declaration
public void AppendSection(Section sourceSection, ImportFormatMode importFormatMode)
Parameters
Type Name Description
Section sourceSection

The section to append.

ImportFormatMode importFormatMode

The formatting policy for imported content.

Clone()

Creates an independent copy of this document's in-memory content model.

Declaration
public Document Clone()
Returns
Type Description
Document

A document containing copied content and formatting.

Compare(Document, string, DateTime)

Compares this document with a revised document and records tracked changes.

Declaration
public void Compare(Document revisedDocument, string author, DateTime date)
Parameters
Type Name Description
Document revisedDocument

The document containing the revised content.

string author

The author recorded on generated revisions.

DateTime date

The date recorded on generated revisions.

Compare(Document, string, DateTime, CompareOptions)

Compares this document with a revised document and records tracked changes according to the supplied options.

Declaration
public void Compare(Document revisedDocument, string author, DateTime date, CompareOptions options)
Parameters
Type Name Description
Document revisedDocument

The document containing the revised content.

string author

The author recorded on generated revisions.

DateTime date

The date recorded on generated revisions.

CompareOptions options

Comparison scope and granularity options.

CreatePaginator()

Creates a DocumentPaginator for this document. The paginator can be used to get page count and extract page text.

Declaration
public DocumentPaginator CreatePaginator()
Returns
Type Description
DocumentPaginator

Dispose()

Releases the resources used by this document.

Declaration
public void Dispose()

Dispose(bool)

Releases managed resources when requested.

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing

Whether to release managed resources in addition to unmanaged resources.

Find(string)

Finds ordinal matches for text in the active story.

Declaration
public IReadOnlyList<ContentRange> Find(string text)
Parameters
Type Name Description
string text

The text to find.

Returns
Type Description
IReadOnlyList<ContentRange>

The matching content ranges.

Find(string, FindReplaceOptions)

Finds matches in the active story using the specified options.

Declaration
public IReadOnlyList<ContentRange> Find(string text, FindReplaceOptions options)
Parameters
Type Name Description
string text

The literal or regular expression pattern to find.

FindReplaceOptions options

The find options, or null for the defaults.

Returns
Type Description
IReadOnlyList<ContentRange>

The matching content ranges.

Find(string, StringComparison)

Finds matches for text in the active story using the specified comparison.

Declaration
public IReadOnlyList<ContentRange> Find(string text, StringComparison comparisonType)
Parameters
Type Name Description
string text

The text to find.

StringComparison comparisonType

The comparison used to find the text.

Returns
Type Description
IReadOnlyList<ContentRange>

The matching content ranges.

Find(Regex)

Finds regular expression matches in the active story.

Declaration
public IReadOnlyList<ContentRange> Find(Regex regex)
Parameters
Type Name Description
Regex regex

The regular expression to find.

Returns
Type Description
IReadOnlyList<ContentRange>

The matching content ranges.

Find(Regex, FindReplaceOptions)

Finds regular expression matches in the active story using the specified options.

Declaration
public IReadOnlyList<ContentRange> Find(Regex regex, FindReplaceOptions options)
Parameters
Type Name Description
Regex regex

The regular expression to find.

FindReplaceOptions options

The find options, or null for the defaults.

Returns
Type Description
IReadOnlyList<ContentRange>

The matching content ranges.

GetPageCount()

Gets the total number of pages in the document by running the layout engine. This is a layout operation and may be slow for large documents.

Declaration
public int GetPageCount()
Returns
Type Description
int

GetRange(int, int)

Creates a range in the active story using zero-based offsets.

Declaration
public ContentRange GetRange(int start, int length)
Parameters
Type Name Description
int start

The inclusive start offset.

int length

The number of characters in the range.

Returns
Type Description
ContentRange

The requested content range.

GetText()

Gets the text from the document's active story.

Declaration
public string GetText()
Returns
Type Description
string

The text represented by the document content.

GetText(bool, bool)

Gets the document text with optional headers, footers, and template glossary entries.

Declaration
public string GetText(bool includeHeadersFooters, bool includeTemplateGlossary)
Parameters
Type Name Description
bool includeHeadersFooters

Whether to include header and footer stories.

bool includeTemplateGlossary

Whether to include text from the template glossary.

Returns
Type Description
string

The text represented by the selected document stories.

InsertDocument(ContentPosition, Document)

Inserts a copy of another document at the specified content position.

Declaration
public void InsertDocument(ContentPosition position, Document sourceDocument)
Parameters
Type Name Description
ContentPosition position

The position at which the source content is inserted.

Document sourceDocument

The document whose active-story content should be inserted.

InsertSection(int)

Inserts a section at the specified index and creates its section-break paragraph.

Declaration
public Section InsertSection(int index)
Parameters
Type Name Description
int index

The zero-based section index.

Returns
Type Description
Section

The inserted section.

ListDigitalSignatures(Stream)

Lists all digital signatures in a DOCX stream without closing the stream.

Declaration
public static IList<DocxDigitalSignatureInfo> ListDigitalSignatures(Stream stream)
Parameters
Type Name Description
Stream stream

The readable DOCX stream.

Returns
Type Description
IList<DocxDigitalSignatureInfo>

ListDigitalSignatures(Stream, DocumentLoadOptions)

Lists signatures from an encrypted or unencrypted DOCX stream.

Declaration
public static IList<DocxDigitalSignatureInfo> ListDigitalSignatures(Stream stream, DocumentLoadOptions options)
Parameters
Type Name Description
Stream stream

The readable DOCX stream.

DocumentLoadOptions options

The load options used to decrypt an encrypted package.

Returns
Type Description
IList<DocxDigitalSignatureInfo>

ListDigitalSignatures(string)

Lists all digital signatures in an existing DOCX file.

Declaration
public static IList<DocxDigitalSignatureInfo> ListDigitalSignatures(string path)
Parameters
Type Name Description
string path
Returns
Type Description
IList<DocxDigitalSignatureInfo>

ListDigitalSignatures(string, DocumentLoadOptions)

Lists signatures from an encrypted or unencrypted DOCX file.

Declaration
public static IList<DocxDigitalSignatureInfo> ListDigitalSignatures(string path, DocumentLoadOptions options)
Parameters
Type Name Description
string path

The DOCX file path.

DocumentLoadOptions options

The load options used to decrypt an encrypted package.

Returns
Type Description
IList<DocxDigitalSignatureInfo>

Load(Stream, CancellationToken)

Loads a document from a stream with cancellation support.

Declaration
public static Document Load(Stream stream, CancellationToken cancellationToken)
Parameters
Type Name Description
Stream stream

The source stream.

CancellationToken cancellationToken

Token for cooperative cancellation.

Returns
Type Description
Document

Load(string, CancellationToken)

Loads a document from a file with cancellation support.

Declaration
public static Document Load(string fileName, CancellationToken cancellationToken)
Parameters
Type Name Description
string fileName

The source file path.

CancellationToken cancellationToken

Token for cooperative cancellation.

Returns
Type Description
Document

Merge(object)

Executes a mail merge using the specified data source.

Declaration
public int Merge(object data)
Parameters
Type Name Description
object data

The data source used to populate merge fields.

Returns
Type Description
int

The number of merged records processed.

Merge(object, DocumentMailMergeOptions)

Executes a mail merge using the specified data source and options.

Declaration
public int Merge(object data, DocumentMailMergeOptions options)
Parameters
Type Name Description
object data

The data source used to populate merge fields.

DocumentMailMergeOptions options

The options that control mail-merge behavior.

Returns
Type Description
int

The number of merged records processed.

RemoveDigitalSignature(Stream, DocumentLoadOptions, DocumentSaveOptions, string)

Removes one signature from an encrypted or unencrypted DOCX stream and applies the requested output encryption.

Declaration
public static void RemoveDigitalSignature(Stream stream, DocumentLoadOptions loadOptions, DocumentSaveOptions saveOptions, string signaturePartUri)
Parameters
Type Name Description
Stream stream

The readable and writable DOCX stream.

DocumentLoadOptions loadOptions

The options used to decrypt the existing package.

DocumentSaveOptions saveOptions

The options used to encrypt the updated package, or null for unencrypted output.

string signaturePartUri

The signature-part URI returned by listing.

RemoveDigitalSignature(Stream, string)

Removes one digital signature from a DOCX stream by signature-part URI.

Declaration
public static void RemoveDigitalSignature(Stream stream, string signaturePartUri)
Parameters
Type Name Description
Stream stream

The readable and writable DOCX stream.

string signaturePartUri

The signature-part URI returned by listing.

RemoveDigitalSignature(string, DocumentLoadOptions, DocumentSaveOptions, string)

Removes one signature from an encrypted or unencrypted DOCX file and applies the requested output encryption.

Declaration
public static void RemoveDigitalSignature(string path, DocumentLoadOptions loadOptions, DocumentSaveOptions saveOptions, string signaturePartUri)
Parameters
Type Name Description
string path

The DOCX file path.

DocumentLoadOptions loadOptions

The options used to decrypt the existing package.

DocumentSaveOptions saveOptions

The options used to encrypt the updated package, or null for unencrypted output.

string signaturePartUri

The signature-part URI returned by listing.

RemoveDigitalSignature(string, string)

Removes one digital signature from an existing DOCX file by signature-part URI.

Declaration
public static void RemoveDigitalSignature(string path, string signaturePartUri)
Parameters
Type Name Description
string path

The DOCX file path.

string signaturePartUri

The signature-part URI returned by listing.

RemoveDigitalSignatures(Stream)

Removes all digital signatures from a DOCX stream without closing the stream.

Declaration
public static void RemoveDigitalSignatures(Stream stream)
Parameters
Type Name Description
Stream stream

The readable and writable DOCX stream.

RemoveDigitalSignatures(Stream, DocumentLoadOptions, DocumentSaveOptions)

Removes all signatures from an encrypted or unencrypted DOCX stream and applies the requested output encryption.

Declaration
public static void RemoveDigitalSignatures(Stream stream, DocumentLoadOptions loadOptions, DocumentSaveOptions saveOptions)
Parameters
Type Name Description
Stream stream

The readable and writable DOCX stream.

DocumentLoadOptions loadOptions

The options used to decrypt the existing package.

DocumentSaveOptions saveOptions

The options used to encrypt the updated package, or null for unencrypted output.

RemoveDigitalSignatures(string)

Removes all digital signatures from an existing DOCX file.

Declaration
public static void RemoveDigitalSignatures(string path)
Parameters
Type Name Description
string path

RemoveDigitalSignatures(string, DocumentLoadOptions, DocumentSaveOptions)

Removes all signatures from an encrypted or unencrypted DOCX file and applies the requested output encryption.

Declaration
public static void RemoveDigitalSignatures(string path, DocumentLoadOptions loadOptions, DocumentSaveOptions saveOptions)
Parameters
Type Name Description
string path

The DOCX file path.

DocumentLoadOptions loadOptions

The options used to decrypt the existing package.

DocumentSaveOptions saveOptions

The options used to encrypt the updated package, or null for unencrypted output.

RemoveSectionAt(int)

Removes the section at the specified index and its section-break paragraph, if present.

Declaration
public void RemoveSectionAt(int index)
Parameters
Type Name Description
int index

The zero-based section index.

Replace(string, string)

Replaces ordinal matches in the active story.

Declaration
public int Replace(string oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The text to replace.

string newValue

The replacement text.

Returns
Type Description
int

The number of replacements performed.

Replace(string, string, FindReplaceOptions)

Replaces matches in the active story using the specified options.

Declaration
public int Replace(string oldValue, string newValue, FindReplaceOptions options)
Parameters
Type Name Description
string oldValue

The literal or regular expression pattern to replace.

string newValue

The replacement text.

FindReplaceOptions options

The replacement options, or null for the defaults.

Returns
Type Description
int

The number of replacements performed.

Replace(string, string, StringComparison)

Replaces matches in the active story using the specified comparison.

Declaration
public int Replace(string oldValue, string newValue, StringComparison comparisonType)
Parameters
Type Name Description
string oldValue

The text to replace.

string newValue

The replacement text.

StringComparison comparisonType

The comparison used to find matches.

Returns
Type Description
int

The number of replacements performed.

Replace(Regex, string)

Replaces regular expression matches in the active story.

Declaration
public int Replace(Regex regex, string replacement)
Parameters
Type Name Description
Regex regex

The regular expression pattern to replace.

string replacement

The replacement text.

Returns
Type Description
int

The number of replacements performed.

Replace(Regex, string, FindReplaceOptions)

Replaces regular expression matches in the active story using the specified options.

Declaration
public int Replace(Regex regex, string replacement, FindReplaceOptions options)
Parameters
Type Name Description
Regex regex

The regular expression pattern to replace.

string replacement

The replacement text.

FindReplaceOptions options

The replacement options, or null for the defaults.

Returns
Type Description
int

The number of replacements performed.

Save(Stream)

Saves the document to the specified stream.

Declaration
public void Save(Stream stream)
Parameters
Type Name Description
Stream stream

The writable destination stream.

Save(Stream, DocumentSaveOptions)

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

Declaration
public void Save(Stream stream, DocumentSaveOptions options)
Parameters
Type Name Description
Stream stream

The writable destination stream.

DocumentSaveOptions options

The options that control output format, encryption, signatures, and cancellation.

Save(Stream, ImageSaveOptions)

Saves one selected document page as a raster image to a stream.

Declaration
public void Save(Stream stream, ImageSaveOptions options)
Parameters
Type Name Description
Stream stream

The destination stream, which remains open.

ImageSaveOptions options

The image rendering options.

Save(Stream, CancellationToken)

Saves the document to a stream with cancellation support.

Declaration
public void Save(Stream stream, CancellationToken cancellationToken)
Parameters
Type Name Description
Stream stream

The destination stream.

CancellationToken cancellationToken

Token for cooperative cancellation.

Save(string)

Saves the document to the specified file.

Declaration
public void Save(string fileName)
Parameters
Type Name Description
string fileName

The destination file path.

Save(string, DocumentSaveOptions)

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

Declaration
public void Save(string fileName, DocumentSaveOptions options)
Parameters
Type Name Description
string fileName

The destination file path.

DocumentSaveOptions options

The options that control output format, encryption, signatures, and cancellation.

Save(string, ImageSaveOptions)

Saves the selected document pages as raster image files.

Declaration
public void Save(string fileName, ImageSaveOptions options)
Parameters
Type Name Description
string fileName

The output path or page-aware path pattern.

ImageSaveOptions options

The image rendering options.

Save(string, CancellationToken)

Saves the document to a file with cancellation support.

Declaration
public void Save(string fileName, CancellationToken cancellationToken)
Parameters
Type Name Description
string fileName

The destination file path.

CancellationToken cancellationToken

Token for cooperative cancellation.

SaveSigned(Stream, DocumentSaveOptions)

Saves the document to a stream with the specified options, applying any digital signatures in DigitalSignatures.

Declaration
public void SaveSigned(Stream stream, DocumentSaveOptions options)
Parameters
Type Name Description
Stream stream

The writable output stream.

DocumentSaveOptions options

The document save options.

SaveSigned(Stream, DocxDigitalSignatureSaveOptions)

Saves the document to a stream and applies a single digital signature.

Declaration
public void SaveSigned(Stream stream, DocxDigitalSignatureSaveOptions signature)
Parameters
Type Name Description
Stream stream

The writable output stream.

DocxDigitalSignatureSaveOptions signature

The digital signature to apply.

SaveSigned(string, DocumentSaveOptions)

Saves the document to a file with the specified save options, applying any digital signatures in DigitalSignatures.

Declaration
public void SaveSigned(string path, DocumentSaveOptions options)
Parameters
Type Name Description
string path
DocumentSaveOptions options

SaveSigned(string, DocxDigitalSignatureSaveOptions)

Saves the document to a file and applies a single digital signature.

Declaration
public void SaveSigned(string path, DocxDigitalSignatureSaveOptions signature)
Parameters
Type Name Description
string path

The output file path.

DocxDigitalSignatureSaveOptions signature

The digital signature to apply.

SaveSigned(string, IEnumerable<DocxDigitalSignatureSaveOptions>)

Saves the document to a file and applies multiple digital signatures.

Declaration
public void SaveSigned(string path, IEnumerable<DocxDigitalSignatureSaveOptions> signatures)
Parameters
Type Name Description
string path

The output file path.

IEnumerable<DocxDigitalSignatureSaveOptions> signatures

The digital signatures to apply.

SetWatermark(Watermark)

Sets a watermark (text or picture) on every section in the document. The watermark appears behind the body text on every page.

Declaration
public void SetWatermark(Watermark watermark)
Parameters
Type Name Description
Watermark watermark

The watermark to apply.

UpdateFields()

Updates all fields in the document body, sections, headers and footers by recomputing their result text from the field instruction. Locked fields are skipped.

Declaration
public int UpdateFields()
Returns
Type Description
int

The number of fields that were updated.

UpdateTableOfContents()

Updates the table of contents on every section by walking the document headings and rebuilding the entries. Also updates any TOC fields in the document so their result text reflects the current headings.

Declaration
public void UpdateTableOfContents()

VerifyDigitalSignatures(Stream, DocumentLoadOptions, DocxDigitalSignatureTrustMode)

Verifies signatures in an encrypted or unencrypted DOCX stream.

Declaration
public static IList<DocxDigitalSignatureInfo> VerifyDigitalSignatures(Stream stream, DocumentLoadOptions options, DocxDigitalSignatureTrustMode trustMode = DocxDigitalSignatureTrustMode.None)
Parameters
Type Name Description
Stream stream

The readable DOCX stream.

DocumentLoadOptions options

The load options used to decrypt an encrypted package.

DocxDigitalSignatureTrustMode trustMode

The certificate trust policy to apply.

Returns
Type Description
IList<DocxDigitalSignatureInfo>

VerifyDigitalSignatures(Stream, DocxDigitalSignatureTrustMode)

Verifies all digital signatures in a DOCX stream.

Declaration
public static IList<DocxDigitalSignatureInfo> VerifyDigitalSignatures(Stream stream, DocxDigitalSignatureTrustMode trustMode = DocxDigitalSignatureTrustMode.None)
Parameters
Type Name Description
Stream stream

The readable DOCX stream.

DocxDigitalSignatureTrustMode trustMode

The certificate trust policy to apply.

Returns
Type Description
IList<DocxDigitalSignatureInfo>

VerifyDigitalSignatures(string, DocumentLoadOptions, DocxDigitalSignatureTrustMode)

Verifies signatures in an encrypted or unencrypted DOCX file.

Declaration
public static IList<DocxDigitalSignatureInfo> VerifyDigitalSignatures(string path, DocumentLoadOptions options, DocxDigitalSignatureTrustMode trustMode = DocxDigitalSignatureTrustMode.None)
Parameters
Type Name Description
string path

The DOCX file path.

DocumentLoadOptions options

The load options used to decrypt an encrypted package.

DocxDigitalSignatureTrustMode trustMode

The certificate trust policy to apply.

Returns
Type Description
IList<DocxDigitalSignatureInfo>

VerifyDigitalSignatures(string, DocxDigitalSignatureTrustMode)

Verifies all digital signatures in an existing DOCX file.

Declaration
public static IList<DocxDigitalSignatureInfo> VerifyDigitalSignatures(string path, DocxDigitalSignatureTrustMode trustMode = DocxDigitalSignatureTrustMode.None)
Parameters
Type Name Description
string path

The DOCX file path.

DocxDigitalSignatureTrustMode trustMode

The certificate trust policy to apply.

Returns
Type Description
IList<DocxDigitalSignatureInfo>

Events

ProgressChanged

Raised periodically during long-running operations (save, load, merge) to report progress.

Declaration
public event EventHandler<OperationProgressEventArgs> ProgressChanged
Event Type
Type Description
EventHandler<OperationProgressEventArgs>

Implements

IEnumerable<T>
IEnumerable
IDisposable

Extension Methods

DocumentHtmlExporter.SaveAsHtml(Document, Stream, HtmlSaveOptions)
DocumentHtmlExporter.SaveAsHtml(Document, string, HtmlSaveOptions)
DocumentImageExporter.RenderToImages(Document, ImageSaveOptions)
DocumentImageExporter.SaveAsImage(Document, Stream, ImageSaveOptions)
DocumentImageExporter.SaveAsImage(Document, string, ImageSaveOptions)
DocumentPdfExporter.SaveAsPdf(Document, Stream, DocumentPdfSaveOptions?)
DocumentPdfExporter.SaveAsPdf(Document, string, DocumentPdfSaveOptions?)
Back to top

DR-IT Software documentation

DR-IT Software · Products · Documentation index · Product page · Downloads · Support · Licensing

Generated by DocFX