Class WordDocument
Represents a Word document containing text, formatting, and other content elements.
Inheritance
Namespace: IronWord
Assembly: IronWord.dll
Syntax
public class WordDocument : Object, IElementContainer, ITextContainer, IDrawContainer
Constructors
WordDocument()
Initializes a new instance of the WordDocument class, creating a new blank document.
Declaration
public WordDocument()
WordDocument(ContentElement[])
Initializes a new instance of the WordDocument class with the specified content elements.
Declaration
public WordDocument(params ContentElement[] children)
Parameters
| Type | Name | Description |
|---|---|---|
| ContentElement[] | children | The child content elements to be added to the document. |
WordDocument(Byte[])
Initializes a new instance of the WordDocument class from an existing document file.
Declaration
public WordDocument(byte[] bytes)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | bytes | The bytes of the document file. |
WordDocument(String)
Initializes a new instance of the WordDocument class from an existing document file.
Declaration
public WordDocument(string filePath)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | filePath | The path to the document file. |
Properties
Children
Declaration
public ContentElementCollection Children { get; }
Property Value
| Type | Description |
|---|---|
| ContentElementCollection |
MultiLevelTextLists
Gets a list of all MultiLevelTextList elements contained within the document.
Declaration
public List<MultiLevelTextList> MultiLevelTextLists { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<MultiLevelTextList> | A List object containing all MultiLevelTextList elements. |
PageCount
Declaration
public int PageCount { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Paragraphs
Gets a list of all Paragraph elements contained within the document.
Declaration
public List<Paragraph> Paragraphs { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<Paragraph> | A List object containing all Paragraph elements. |
Sections
Gets a list of all DocumentSection elements contained within the document.
Declaration
public List<DocumentSection> Sections { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<DocumentSection> | A List object containing all DocumentSection elements. |
Tables
A list of all table elements contained within this element or its children
Declaration
public List<Table> Tables { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<Table> |
Texts
A list of all text elements contained within this element or its children
Declaration
public List<TextContent> Texts { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<TextContent> |
Methods
AddChild(ContentElement[])
Adds one or more child content elements to the current document.
Declaration
public void AddChild(params ContentElement[] children)
Parameters
| Type | Name | Description |
|---|---|---|
| ContentElement[] | children | The content elements to be added as children. |
AddImage(AnyBitmap)
Adds an image to this document from an IronSoftware.Drawing.AnyBitmap object.
Declaration
public ImageContent AddImage(AnyBitmap anyBitmap)
Parameters
| Type | Name | Description |
|---|---|---|
| IronSoftware.Drawing.AnyBitmap | anyBitmap |
Returns
| Type | Description |
|---|---|
| ImageContent |
AddImage(ImageContent)
Adds a new Image object to the document.
Declaration
public ImageContent AddImage(ImageContent imageContent)
Parameters
| Type | Name | Description |
|---|---|---|
| ImageContent | imageContent | The Image object to be added. |
Returns
| Type | Description |
|---|---|
| ImageContent |
AddImage(Stream)
Adds an image to the document.
Declaration
public ImageContent AddImage(Stream imageStream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | imageStream | The stream image to be loaded. |
Returns
| Type | Description |
|---|---|
| ImageContent | The added Image. |
AddImage(String)
Adds an image to the document.
Declaration
public ImageContent AddImage(string imagePath)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | imagePath | The physical path of Image to be loaded. |
Returns
| Type | Description |
|---|---|
| ImageContent | The added Image. |
AddMultiLevelTextList(MultiLevelTextList)
Adds a new multiLevelTextList object to the document.
Declaration
public MultiLevelTextList AddMultiLevelTextList(MultiLevelTextList multiLevelTextList)
Parameters
| Type | Name | Description |
|---|---|---|
| MultiLevelTextList | multiLevelTextList | The multiLevelTextList object to be added. |
Returns
| Type | Description |
|---|---|
| MultiLevelTextList | A instance of the added MultiLevelTextList. |
AddParagraph(Paragraph)
Adds a new Paragraph object to the document.
Declaration
public Paragraph AddParagraph(Paragraph paragraph)
Parameters
| Type | Name | Description |
|---|---|---|
| Paragraph | paragraph | The Paragraph object to be added. |
Returns
| Type | Description |
|---|---|
| Paragraph |
AddSection()
Adds a new document section to this document.
Declaration
public void AddSection()
AddSection(DocumentSection)
Creates a new DocumentSection object with the specified type and adds it to the document.
Declaration
public void AddSection(DocumentSection documentSection)
Parameters
| Type | Name | Description |
|---|---|---|
| DocumentSection | documentSection | The type of the section to be added. |
AddShape(ShapeContent)
Adds a new Shape object to the document.
Declaration
public ShapeContent AddShape(ShapeContent shapeContent)
Parameters
| Type | Name | Description |
|---|---|---|
| ShapeContent | shapeContent | The Shape object to be added. |
Returns
| Type | Description |
|---|---|
| ShapeContent |
AddTable(Table)
Adds a new Table object to the document.
Declaration
public Table AddTable(Table table)
Parameters
| Type | Name | Description |
|---|---|---|
| Table | table | The Table object to be added. |
Returns
| Type | Description |
|---|---|
| Table |
AddText(TextContent)
Adds a new TextRun object to the last paragraph of the document.
Declaration
public TextContent AddText(TextContent textContentRun)
Parameters
| Type | Name | Description |
|---|---|---|
| TextContent | textContentRun | The TextRun object to be added. |
Returns
| Type | Description |
|---|---|
| TextContent |
AddText(String)
Adds a text to the last paragraph of document.
Declaration
public TextContent AddText(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | text | The text to be added. |
Returns
| Type | Description |
|---|---|
| TextContent |
ExtractImages()
Extract all images from this container
Declaration
public List<AnyBitmap> ExtractImages()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<IronSoftware.Drawing.AnyBitmap> | List of images |
ExtractShapes()
Extract all shapes from this container
Declaration
public List<IReadOnlyCollection<IPathSegment>> ExtractShapes()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<System.Collections.Generic.IReadOnlyCollection<IronSoftware.IPathSegment>> | List of path segment collections |
ExtractText()
Extract all text from the container
Declaration
public string ExtractText()
Returns
| Type | Description |
|---|---|
| System.String | Extracted text |
ExtractTextFromPage(Int32)
Declaration
public string ExtractTextFromPage(int PageIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | PageIndex |
Returns
| Type | Description |
|---|---|
| System.String |
ExtractTextFromPages(IEnumerable<Int32>)
Declaration
public string ExtractTextFromPages(IEnumerable<int> PageIndices)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<System.Int32> | PageIndices |
Returns
| Type | Description |
|---|---|
| System.String |
FindText(String)
Find the first text element which contains the specified text
Declaration
public TextContent FindText(string find)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | find | Text to find |
Returns
| Type | Description |
|---|---|
| TextContent | Text element containing the specified text |
LogObjectTree()
Initiates logging of the object tree by traversing from the current object.
Declaration
public void LogObjectTree()
Remove(TextContent)
Remove the specified text element
Declaration
public bool Remove(TextContent element)
Parameters
| Type | Name | Description |
|---|---|---|
| TextContent | element | Text element to remove |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the element was found and removed, False otherwise |
ReplaceText(String, String)
Replace all instances of the specified text
Declaration
public void ReplaceText(string find, string replace)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | find | Text to replace |
| System.String | replace | Replacement text |
Save()
Saves the current document to a file. If a file path is not provided, a new temporary file will be created.
Declaration
public byte[] Save()
Returns
| Type | Description |
|---|---|
| System.Byte[] |
Save(String)
Saves the current document to a specific file path.
Declaration
public void Save(string filePath)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | filePath | The full path to the file where the document will be saved. |
SaveAs(String)
Saves the current document as a new file with the specified name.
Declaration
public void SaveAs(string filePath)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | filePath | The file path for the new document file. |
ToJson()
Declaration
public string ToJson()
Returns
| Type | Description |
|---|---|
| System.String |