Document module
- class Document.Document
Bases:
DocumentContainer,IDocument,ICompositeObjectRepresents a document.
- AcceptChanges()
Accepts changes tracked from the moment of last change acceptance.
- AddListStyle(listType: ListType, styleName: str) ListStyle
Adds a new list style to the document.
- AddParagraphStyle(styleName: str) ParagraphStyle
Adds a new paragraph style to the document.
- Parameters:
styleName (str) – The name of the paragraph style.
- Returns:
The newly added paragraph style.
- Return type:
- AddSection() Section
Adds a new section to the document.
- Returns:
The newly added section.
- Return type:
- AddStyle(builtinStyle: BuiltinStyle) Style
Adds a style to the document style.
- Parameters:
builtinStyle (BuiltinStyle) – The built-in style to add.
- Returns:
The added style.
- Return type:
- property AutoUpdateStylesByTemplate: bool
Gets or sets a value indicating whether updating the styles in this document to match the styles in the attached template each time you open . if update document styles automatically, set to true.
- property Background: Background
Gets document’s background
- property Bookmarks: BookmarkCollection
Gets document bookmarks.
- property BuiltinDocumentProperties: BuiltinDocumentProperties
Gets document built-in properties object.
- CheckProtectionPassWord(password: str) bool
Checks if the entered password is the same as the permission protection password.
- Parameters:
password – The password to check.
- Returns:
True if the password is correct, False otherwise.
- property ChildObjects: DocumentObjectCollection
Gets the child entities.
- ClearCustomFonts()
Clear the custom fonts.
- static ClearGlobalCustomFonts()
Clear the global custom fonts.
- ClearMacros()
Removes the macros from the document.
- CloneCompatibilityTo(destDoc: Document)
Clones the compatibility settings of the current document to the destination document.
- Parameters:
destDoc (Document) – The destination document.
- Returns:
None
- CloneDefaultStyleTo(destDoc: Document)
Clones the default style of the current document to the destination document.
- Parameters:
destDoc (Document) – The destination document.
- Returns:
None
- CloneThemesTo(destDoc: Document)
Clones the theme style of the current document to the destination document.
- Parameters:
destDoc (Document) – The destination document.
- Returns:
None
- CloneWebSettingsTo(destDoc: Document)
Clone Websettings to other document. :param destDoc: The destination Document object.
- Close()
Closes this instance.
- Returns:
None
- property Comments: CommentsCollection
Gets comments item of the document.
- Compare
Compares this document with another document.
- Parameters:
document – The document to compare.
author – The author to use for revisions.
- CreateMinialDocument()
Creates a minimal document with one empty section and one empty paragraph.
- Returns:
None
- CreateParagraph() Paragraph
Creates a new paragraph in the document.
- Returns:
The newly created paragraph.
- Return type:
- CreateParagraphItem(itemType: ParagraphItemType) ParagraphBase
Creates new paragraph item instance.
- Parameters:
itemType – Paragraph item type.
- Returns:
The ParagraphBase object.
- property CustomDocumentProperties: CustomDocumentProperties
Gets document custom properties object.
- property DetectedFormatType: FileFormat
Returns the detected format type of the document which was loaded. .
- Dispose()
Prerforms application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- Returns:
None
- property DocumentObjectType: DocumentObjectType
Gets the type of the document object.
- property EmbedFontsInFile: bool
Gets or sets a value indicating whether save fonts that are used in the document in the file. Only support for the DOCX file format.
- property EmbedSystemFonts: bool
Gets or sets a value indicating whether save system fonts that are used in the document in the file.
- Encrypt(password: str)
Encrypts the document.
- Parameters:
password (str) – The password.
- property EndnoteOptions: FootEndnoteOptions
Gets or sets options that control numbering and positioning of endnotes in this document.
- property Fields: FieldCollection
Gets fields of the documnet.
- FindAllPattern
Returns all entries of matchString regex.
- Parameters:
pattern (Regex) – The regex pattern.
- Returns:
The found text selections.
- Return type:
List[TextSelection]
- FindAllString(matchString: str, caseSensitive: bool, wholeWord: bool) List[TextSelection]
Returns all entries of matchString string, taking into consideration caseSensitive and wholeWord options. :param matchString: The string to match. :param caseSensitive: If True, the match is case sensitive. :param wholeWord: If True, the match must be a whole word. :return: A list of TextSelection objects.
- FindString
Finds and returns string along with formatting.
- Parameters:
stringValue (str) – The string to find.
caseSensitive (bool) – If set to True, use case sensitive search.
wholeWord (bool) – If it search the whole word, set to True.
- Returns:
The found text selection.
- Return type:
- property FootnoteOptions: FootEndnoteOptions
Gets or sets options that control numbering and positioning of footnotes in this document.
- property ForceTableRelayout: bool
Gets or sets a value indicating whether to force table relayout.
- GetPageCount() int
Gets the total number of pages for the document.
- Returns:
The total number of pages.
- GetProtectionType() ProtectionType
Gets or sets the type of protection of the document.
- GetText() str
Gets the text of the document.
- Returns:
The text of the document.
- Return type:
str
- property HTMLCustomComment: bool
Gets or sets a value specifying whether parsing and writing comment of document in HTML. Supported HTML Tag : span ,when the value of class attribute is comment Supported HTML Tag Attribytes : data-comment / data-user / data-cid / data-date.
- property HTMLSentenceIdentifier: bool
Gets or sets a value specifying whether to add identifier to a sentence when writing to HTML. Writed HTML Attribyte : sentence. Writed HTML Value Of Attribyte : start / end / (start,end).
- property HTMLTrackChanges: bool
Gets or sets a value specifying whether parsing and writing custom Change_Tracking HTML Tags are supported. Supported HTML Tag : insert / delete. Supported HTML Tag Attribytes : data-username / data-time.
- property HasChanges: bool
Gets a value indicating whether the document has tracked changes. if the document has tracked changes, set to true.
- HasWriteProtection() bool
- <summary>
Checks if the document has write protection.
</summary>
- property HtmlBaseUrl: str
Gets or sets the Base path which is used to convert the relative path to absolute path.
- property HtmlExportOptions: HtmlExportOptions
Gets the save options. The save options.
- ImportContent
Imports all content into the document.
- Parameters:
doc (IDocument) – The document to import.
- ImportSection(section: ISection)
Imports a section into the document.
- Parameters:
section (ISection) – The section to be imported.
- Returns:
None
- InsertTextFromFile(fileName: str, fileFormat: FileFormat)
Insert text from a file.
- Parameters:
fileName (Stream) – The file name.
fileFormat (FileFormat) – Type of the format.
- InsertTextFromStream(stream: Stream, fileFormat: FileFormat)
Insert text from stream.
- Parameters:
stream (Stream) – The stream.
fileFormat (FileFormat) – Type of the format.
- IntegrateFontTableTo(destDoc: Document)
- <summary>
Integrate the current document font table to the destination document.
</summary> <param name=”destDoc”>The destination document.</param>
- property IsContainMacro: bool
Indicates whether the document has macros.
- IsEncrypted
A function that is part of a class.
This wrapper provides a mechanism that allows the function to be constructed with a reference to the class that it owns. The construction is deferred until __set_name__ is called.
- Parameters:
class_name (str) – Name of the class that owns the function.
construct_function (function) – Constructor for the function: takes in a reference to the class that owns the function and gives back the function.
- property IsUpdateFields: bool
Gets or sets a value indicating whether to update fields in the document.
- property JPEGQuality: int
Gets or sets the quality (Q%) of the image of JPEG format, this property is only used for doc to pdf. The default value is 80.
- property KeepSameFormat: bool
Gets or sets a value that indicates whether to keep same formatting when this document is merged to other document.
- property LastParagraph: Paragraph
Gets last section object.
- property LastSection: Section
Gets last section of the document.
- property LayoutOptions: DocumentLayoutOptions
- <summary>
Gets the layout options. The related layout settings are only supported for new engines.
</summary>
- property ListStyles: ListStyleCollection
Gets document list styles.
- LoadFromFile
Opens doc file.
- Parameters:
fileName (Stream) – The fileName.
- LoadFromFileInReadMode(strFileName: str, fileFormat: FileFormat)
LoadFromStream new document in read-only mode.
- Parameters:
strFileName (str) – File to open.
fileFormat (FileFormat) – Type of the format.
- LoadFromStream
Opens the HTML document from stream with the specified file format and validation type.
- LoadRtf
Opens the rtf document from a file.
- Parameters:
fileName (str) – Name of the file.
- LoadText
Opens the text document from a file with default encoding utf-8.
- Parameters:
fileName (str) – Name of the file.
- property MailMerge: MailMerge
Gets mail merge engine.
- OpenOnlineBin(fileName: str)
Opens an online binary file.
- Parameters:
fileName (str) – The name of the file.
- property PageCount: int
Gets total number of pages for document.
- property PrivateFontList: List[PrivateFontPath]
Gets the private font list.
- property Properties: DocumentProperties
Gets the document properties.
- Protect
Protects the document.
- Parameters:
type (ProtectionType) – The type of protection.
- property QuiteMode: bool
Get or sets whether is quite mode.
- RejectChanges()
Rejects changes tracked from the moment of last change acceptance.
- RemoveEncryption()
Removes the encryption.
- Replace
Replaces all entries of matchString regular expression with newValue string. :param pattern: The regular expression pattern to match. :param replace: The string to replace the matched pattern with. :return: The number of replacements made.
- property ReplaceFirst: bool
Gets or sets a value indicating whether need first replacing. True indciates need first replacing.
- ReplaceInLine
Replaces all occurrences of matchString text with newValue text in single-line mode.
- Parameters:
matchString – The matchString.
newValue – The newValue.
caseSensitive – If True, the replacement is case sensitive.
wholeWord – If True, only whole words will be replaced.
- Returns:
The number of replacements made.
- ResetFindState()
Resets the FindPattern.
- ResetPageLayoutCache()
Reset the page layout cache data of the new engine.
- SaveImageToStreams
Save the specified range of pages as image return streams. The default is PNG format image.
- Parameters:
pageIndex (int) – Index of the page.
pageCount (int) – The page count.
type (ImageType) – The type.
- Returns:
The streams.
- Return type:
List[Stream]
- SaveToEpub
Saves the EPUB document.
- Parameters:
fileName (str) – The fileName.
coverImage (DocPicture) – The cover image.
- SaveToFile
Saves document to file and digitally sign, Only DOC and DOCX are supported.
- Parameters:
fileName (str) – The file.
fileFormat (FileFormat) – The file format.
certificatePath (str) – Path to the file certificate.
securePassword (str) – Password of the certificate.
- Returns:
None
- SaveToOnlineBin(fileName: str) bool
Saves the document in Spire.Online format.
- SaveToSVG
Saves the SVG.
- Parameters:
fileName (str) – The file name.
- SaveToStream
Saves the document into stream with the specified parameters.
- SaveToTxt(fileName: str, encoding: Encoding)
Saves the document to a text file with the specified encoding.
- Parameters:
fileName (str) – The name of the file.
encoding (Encoding) – The encoding.
- property Sections: SectionCollection
Gets document sections.
- SetCustomFonts(fontStreamList: List[Stream])
Sets the custom font stream array.
- SetCustomFontsFolders(fileName: str)
Sets the path to the folder where the custom font is located.
- SetDateTimeOfUnitTest(dateTime: DateTime)
Sets date and time of the unit test. For unit testing use only.
- static SetGlobalCustomFonts(fontStreamList: List[Stream])
Sets the global custom font stream array.
- static SetGlobalCustomFontsFolders(fileName: str)
Sets the path to the folder where the custom font is located.
- SetProtectionType(value: ProtectionType)
Sets the protection type of the document.
- SetWriteProtection
- <summary>
Sets the write protection for a document using the provided password.
</summary>
- StartTrackRevisions
- <summary>
Begins making all subsequent changes made to the document programmatically as revisions.
</summary>
- StopTrackRevisions()
- <summary>
Stops making changes programmatically as revisions.
</summary>
- property Styles: StyleCollection
Gets document styles.
- property TOC: TableOfContent
Gets or sets the TOC element of the word document.
- property TextBoxes: TextBoxCollection
Get/set textbox items of main document
- property TrackChanges: bool
Gets or sets a value indicating whether tracking changes is turn on. if track changes in on, set to true.
- UnWriteProtection
- <summary>
Removes the write protection from a document by clearing the password and disabling the read-only recommendation.
</summary>
- Unprotect
- <summary>
Unprotect the document.
</summary>
- UpdateTOCPageNumbers
Updates the Table of Contents page numbers in the document.
- UpdateTableLayout()
Update table grid before saving the document when using the new engine.
- UpdateTableOfContents
Updates the Table of Contents in the document.
- UpdateWordCount
Update Paragraphs count, Word count and Character count.
- property UseNewEngine: bool
Gets a value indicating whether the new engine layout is enabled. The Spire.Doc product conversion feature has enabled the new engine way layout by default. If you want to switch to the old engine layout, use the Document constructor with the “useNewEngine” parameter and set the parameter “useNewEngine” to false.
- property Variables: VariableCollection
Gets or sets the document variables.
- property ViewSetup: ViewSetup
Gets view setup options in Microsoft word.
- property Watermark: WatermarkBase
Gets or sets document’s watermark.
- property XHTMLValidateOption: XHTMLValidationType
Gets or sets the HTML validate option.the default value is None.
- add_BookmarkLayout(value: BookmarkLevelHandler)
- add_EvalInformation(value: SpireDocEvalInfo)
- add_PageLayout(value: PageLayoutHandler)
- add_UpdateFields(value: UpdateFieldsHandler)
- remove_BookmarkLayout(value: BookmarkLevelHandler)
- remove_EvalInformation(value: SpireDocEvalInfo)
- remove_PageLayout(value: PageLayoutHandler)
- remove_UpdateFields(value: UpdateFieldsHandler)
