Skip to main content

Document Model

  • 4 minutes to read

A document model defines the logical structure of a document reflecting its logical organization and hierarchically groups the logical entities in a document. It is illustrated in the following diagram.

RichTextDocumentModelTest

The root of the document model is the object exposing the SubDocument interface. It delivers the basic document functionality that is common for the main document body, header and footer. Specific functionality belongs to its descendant, the Document interface. Use the RichEditControl.Document property to get access to the Document interface.

The document is divided into logical Document.Sections. Each section in a SectionCollection defines its own page settings, such as paper size, page orientation and margins. The SectionPage.PaperKind, SectionPage.Landscape, Section.Page and Section.Margins properties enable you to access these settings.

To insert a section into an arbitrary position, use the Document.InsertSection method.

The section consists of paragraphs. The Paragraph class represents the paragraph entity in the document model. The Section.Paragraphs property of a section gives you a collection of paragraphs in a particular section of a document. If you need to access the collection of paragraphs in a whole document, use the SubDocument.Paragraphs property.

To modify paragraph formatting, you can use either the Paragraph object or the ParagraphProperties interface. The interface is more convenient to use, since it can be easily accessed for a particular document range via the SubDocument.BeginUpdateParagraphs method. Do not forget to call the SubDocument.EndUpdateParagraphs method to finish the modification appropriately.

To insert a paragraph at an arbitrary position, use the ParagraphCollection.Insert method.

The paragraph consists of runs - groups of characters with a uniform format. This is an internal entity, not available via API. Manage the Positions and Ranges instead.

Note

For the specified DocumentPosition, use the ReadOnlyParagraphCollection.Get method to get an encompassing Paragraph, use the Document.GetSection to get an encompassing Section.

The document model also includes entities that do not comprise the hierarchy, such as lists, styles, tables,inline pictures, floating objects (pictures and text boxes), bookmarks, hyperlinks and comments.

Object

Description

Collection containing an object:

Exposed By

Lists

Represented by a specific collection of paragraphs. This collection is composed of items with a NumberingList interface. Each item is an instance of a certain abstract numbering definition, which is represented by an AbstractNumberingList interface.

NumberingListCollection

AbstractNumberingListCollection

Document.AbstractNumberingLists

NumberingList.AbstractNumberingList

ParagraphCollection.AddParagraphsToList

ParagraphStyle

CharacterStyle

Pertains to a document and belongs to a particular document model. You cannot add the style object from a style collection of one document to the style collection of another document.

ParagraphStyleCollection

CharacterStyleCollection

Document.CharacterStyles

Document.ParagraphStyles

CharacterStyleCollection.CreateNew

ParagraphStyleCollection.CreateNew

Table

Specific structure based on paragraphs. To change the cell content, you should operate with a corresponding paragraph.

TableCollection

ReadOnlyTableCollection

SubDocument.Tables

TableCollection.Create

ReadOnlyTableCollection.Get

DocumentImage

Represents the inline picture entity in the document model. Occupies the range equivalent to one character, i.e., the DocumentRange.Length of the range is equal to 1.

DocumentImageCollection

ReadOnlyDocumentImageCollection

DocumentImage.Image

DocumentImageCollection.Insert

DocumentImageCollection.Append

ReadOnlyDocumentImageCollection.Get

Shape

Represents floating object (pictures and text boxes) entities in the document model. Anchored to the position, but can be placed anywhere on the page that contains the anchor - within, above and below the main document body.

ShapeCollection

ReadOnlyShapeCollection

SubDocument.Shapes

Shape.TextBox

ReadOnlyShapeCollection.Get

Bookmark

Represents bookmark entity in the document model. Linked to the position, so the range can have a zero length.

BookmarkCollection

ReadOnlyBookmarkCollection

SubDocument.Bookmarks

BookmarkCollection.Create

ReadOnlyBookmarkCollection.Get

Hyperlink

Represents a hyperlink entity in the document model. Can be linked to the bookmark.

HyperlinkCollection

ReadOnlyHyperlinkCollection

SubDocument.Hyperlinks

HyperlinkCollection.Create

ReadOnlyHyperlinkCollection.Get

Comment

Represents a comment entity in the document model. Linked to the document range. Can be nested - one comment can relate to another. In this case, only the parent comment is linked to the document range, whereas the child comment is linked to its parent.

CommentCollection

ReadOnlyCommentCollection

SubDocument.Comments

Comment.ParentComment

ReadOnlyCommentCollection.Get