Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

RtfDocument

OfficeIMO.Rtf

Namespace
OfficeIMO.Rtf
Assembly
OfficeIMO.Rtf
Source revision
ba882f6b0d07 with working tree changes
Implements
IRtfCloneable IDisposable
Modifiers
sealed

Semantic Rich Text Format document model.

Inheritance

  • object
  • RtfDocument

Usage

Explore 16 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Accepted by parameters 3

Methods

public void AddBlock(IRtfBlock block) #

Adds an existing semantic block at the end of the document.

Parameters

block OfficeIMO.Rtf.IRtfBlock required
public int AddColor(byte red, byte green, byte blue) #

Adds a color to the color table and returns its RTF color index.

Parameters

red byte required
green byte required
blue byte required

Returns

int
public RtfDocumentVariable AddDocumentVariable(string name, string value) #

Adds a document variable.

Parameters

name string required
value string required
public RtfFileReference AddFileReference(string path, RtfFileSource sources = Ntfs) #

Adds a file table reference and returns it.

Parameters

path string required
sources OfficeIMO.Rtf.RtfFileSource = Ntfs optional
public int AddFont(string name) #

Adds a font to the font table or returns the existing id.

Parameters

name string required

Returns

int
public RtfHeaderFooter AddFooter(RtfHeaderFooterKind kind = Footer) #

Adds a footer destination.

Parameters

kind OfficeIMO.Rtf.RtfHeaderFooterKind = Footer optional
public RtfHeaderFooter AddHeader(RtfHeaderFooterKind kind = Header) #

Adds a header destination.

Parameters

kind OfficeIMO.Rtf.RtfHeaderFooterKind = Header optional
public RtfHeaderFooter AddHeaderFooter(RtfHeaderFooterKind kind) #

Adds a header or footer destination.

Parameters

kind OfficeIMO.Rtf.RtfHeaderFooterKind required
public RtfImage AddImage(RtfImageFormat format, byte[] data) #

Adds a picture block to the document.

Parameters

format OfficeIMO.Rtf.RtfImageFormat required
data byte[] required

Returns

RtfImage
public RtfListDefinition AddListDefinition(int id, string? name = null) #

Adds or returns a list definition.

Parameters

id int required
name string? = null optional
public RtfListOverride AddListOverride(int id, int listId) #

Adds or returns a list override.

Parameters

id int required
listId int required
public RtfNote AddNote(RtfNoteKind kind) #

Adds a detached footnote or annotation.

Parameters

kind OfficeIMO.Rtf.RtfNoteKind required

Returns

RtfNote
public RtfObject AddObject(RtfObjectKind kind = Unknown, byte[]? data = null) #

Adds an embedded or linked object block to the document.

Parameters

kind OfficeIMO.Rtf.RtfObjectKind = Unknown optional
data byte[]? = null optional

Returns

RtfObject
public RtfParagraph AddParagraph(string? text = null) #

Adds a paragraph to the document.

Parameters

text string? = null optional
public int AddRevisionAuthor(string name) #

Adds a revision author and returns its zero-based table index.

Parameters

name string required

Returns

int
public RtfDocument AddRevisionSaveId(int id) #

Adds a revision save identifier to the document rsidtbl.

Parameters

id int required
public RtfSection AddSection(RtfSectionBreakKind breakKind = NextPage) #

Adds a semantic section to the document.

Parameters

breakKind OfficeIMO.Rtf.RtfSectionBreakKind = NextPage optional

Returns

RtfSection
public RtfShape AddShape() #

Adds a drawing shape block to the document.

Returns

RtfShape
public RtfStyle AddStyle(int id, string name, RtfStyleKind kind = Paragraph) #

Adds or replaces a stylesheet entry.

Parameters

id int required
name string required
kind OfficeIMO.Rtf.RtfStyleKind = Paragraph optional

Returns

RtfStyle
public RtfTable AddTable(int rows, int columns) #

Adds a table block to the document.

Parameters

rows int required
columns int required

Returns

RtfTable
AddUserProperty 2 overloads
public RtfUserProperty AddUserProperty(string name, int? typeCode = null, string? staticValue = null) #

Adds a custom document property.

Parameters

name string required
typeCode int? = null optional
staticValue string? = null optional
public RtfUserProperty AddUserProperty(RtfUserProperty property) #

Adds an existing custom document property.

Parameters

property OfficeIMO.Rtf.RtfUserProperty required
public RtfXmlNamespace AddXmlNamespace(int id, string uri) #

Adds an XML namespace declaration to the document namespace table.

Parameters

id int required
uri string required
AppendDocument 2 overloads
public RtfDocumentMergeResult AppendDocument(RtfDocument source) #

Appends an independent semantic clone of another document, remapping fonts, colors, styles, lists, and revision authors. Section layout and headers are omitted when content is appended into the destination's layout.

Parameters

source OfficeIMO.Rtf.RtfDocument required
public RtfDocumentMergeResult AppendDocument(RtfDocument source, RtfDocumentMergeOptions? options) #

Appends an independent copy with imported resources and optional source section preservation.

Parameters

source OfficeIMO.Rtf.RtfDocument required
options OfficeIMO.Rtf.RtfDocumentMergeOptions? required
public RtfDocument ApplyTheme(OfficeTheme theme) #

Explicitly applies shared theme typography, paragraph spacing and table appearance to this document.

Parameters

theme OfficeIMO.OfficeTheme required

Returns

RtfDocument The current document.
public RtfDocument Clone() #

Creates an independent semantic clone, retaining resources, ownership, and shared references.

Create 2 overloads
public static RtfDocument Create() #

Creates an empty RTF document.

public static RtfDocument Create(string path) #

Creates an empty document associated with a path, without writing it.

Parameters

path string required
public void Dispose() #

Releases the document without saving. The in-memory model owns no external resources.

public RtfColor? GetColor(int colorIndex) #

Resolves an authored RTF color index. Automatic and missing colors return null.

Parameters

colorIndex int required

Returns

RtfColor?
public IReadOnlyList<RtfHeaderFooter> GetEffectiveHeaderFooters(RtfSection section) #

Returns the effective headers and footers for a section, including inherited kinds.

Parameters

section OfficeIMO.Rtf.RtfSection required

Returns

IReadOnlyList<RtfHeaderFooter>
public RtfPageSetup GetEffectivePageSetup(RtfSection section) #

Returns an independent page setup with document defaults applied beneath the section's authored values.

Parameters

section OfficeIMO.Rtf.RtfSection required
public void InsertBlock(int index, IRtfBlock block) #

Inserts an existing semantic block at the specified document block index.

Parameters

index int required
block OfficeIMO.Rtf.IRtfBlock required
public RtfImage InsertImage(int index, RtfImageFormat format, byte[] data) #

Creates and inserts an image at the specified document block index.

Parameters

index int required
format OfficeIMO.Rtf.RtfImageFormat required
data byte[] required

Returns

RtfImage
public RtfParagraph InsertParagraph(int index, string? text = null) #

Creates and inserts a paragraph at the specified document block index.

Parameters

index int required
text string? = null optional
public RtfTable InsertTable(int index, int rows, int columns) #

Creates and inserts a table at the specified document block index.

Parameters

index int required
rows int required
columns int required

Returns

RtfTable
InspectContentSafety 2 overloads
public static OfficeContentSafetyReport InspectContentSafety(byte[] rtf, OfficeContentSafetyOptions? options = null, RtfLoadOptions? readOptions = null) #

Inspects native RTF visibility, revision, geometry, contrast, and non-primary story evidence.

Parameters

rtf byte[] required
options OfficeIMO.ContentSafety.OfficeContentSafetyOptions? = null optional
readOptions OfficeIMO.Rtf.RtfLoadOptions? = null optional

Returns

OfficeContentSafetyReport
public static OfficeContentSafetyReport InspectContentSafety(string filePath, OfficeContentSafetyOptions? options = null, RtfLoadOptions? readOptions = null) #

Inspects an RTF file without treating concealment as evidence of AI authorship.

Parameters

filePath string required
options OfficeIMO.ContentSafety.OfficeContentSafetyOptions? = null optional
readOptions OfficeIMO.Rtf.RtfLoadOptions? = null optional

Returns

OfficeContentSafetyReport
public OfficeContentSafetyReport InspectLoadedContentSafety(OfficeContentSafetyOptions? options = null, CancellationToken cancellationToken = default) #

Inspects the loaded semantic document without reparsing, saving or executing object content. Source-load limits remain the caller's responsibility.

Parameters

options OfficeIMO.ContentSafety.OfficeContentSafetyOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

OfficeContentSafetyReport
Load 3 overloads
public static RtfDocument Load(string path, RtfLoadOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default) #

Loads RTF from a file into the semantic document model.

Parameters

path string required
options OfficeIMO.Rtf.RtfLoadOptions? = null optional
encoding System.Text.Encoding? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public static RtfDocument Load(byte[] bytes, RtfLoadOptions? options = null, CancellationToken cancellationToken = default) #

Loads RTF bytes into the semantic document model.

Parameters

bytes byte[] required
options OfficeIMO.Rtf.RtfLoadOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public static RtfDocument Load(Stream stream, RtfLoadOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default) #

Loads RTF from a stream into the semantic document model.

Parameters

stream System.IO.Stream required
options OfficeIMO.Rtf.RtfLoadOptions? = null optional
encoding System.Text.Encoding? = null optional
cancellationToken System.Threading.CancellationToken = default optional
LoadAsync 2 overloads
public static async Task<RtfDocument> LoadAsync(string path, RtfLoadOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default) #

Asynchronously loads RTF from a file into the semantic document model.

Parameters

path string required
options OfficeIMO.Rtf.RtfLoadOptions? = null optional
encoding System.Text.Encoding? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task<RtfDocument>
public static async Task<RtfDocument> LoadAsync(Stream stream, RtfLoadOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default) #

Asynchronously loads RTF from a stream into the semantic document model.

Parameters

stream System.IO.Stream required
options OfficeIMO.Rtf.RtfLoadOptions? = null optional
encoding System.Text.Encoding? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task<RtfDocument>
LoadResult 3 overloads
public static RtfReadResult LoadResult(string path, RtfLoadOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default) #

Loads RTF from a file with lossless syntax and diagnostics.

Parameters

path string required
options OfficeIMO.Rtf.RtfLoadOptions? = null optional
encoding System.Text.Encoding? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public static RtfReadResult LoadResult(byte[] bytes, RtfLoadOptions? options = null, CancellationToken cancellationToken = default) #

Loads RTF from source bytes using the byte-preserving lossless representation.

Parameters

bytes byte[] required
options OfficeIMO.Rtf.RtfLoadOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public static RtfReadResult LoadResult(Stream stream, RtfLoadOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default) #

Loads RTF from a stream with lossless syntax and diagnostics.

Parameters

stream System.IO.Stream required
options OfficeIMO.Rtf.RtfLoadOptions? = null optional
encoding System.Text.Encoding? = null optional
cancellationToken System.Threading.CancellationToken = default optional
LoadResultAsync 2 overloads
public static async Task<RtfReadResult> LoadResultAsync(string path, RtfLoadOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default) #

Asynchronously loads RTF from a file with lossless syntax and diagnostics.

Parameters

path string required
options OfficeIMO.Rtf.RtfLoadOptions? = null optional
encoding System.Text.Encoding? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task<RtfReadResult>
public static async Task<RtfReadResult> LoadResultAsync(Stream stream, RtfLoadOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default) #

Asynchronously loads RTF from a stream with lossless syntax and diagnostics.

Parameters

stream System.IO.Stream required
options OfficeIMO.Rtf.RtfLoadOptions? = null optional
encoding System.Text.Encoding? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task<RtfReadResult>
public void MoveBlock(int fromIndex, int toIndex) #

Moves a document block to its final zero-based index.

Parameters

fromIndex int required
toIndex int required
public static RtfDocument Parse(string rtf, RtfLoadOptions? options = null, CancellationToken cancellationToken = default) #

Parses RTF text into the semantic document model.

Parameters

rtf string required
options OfficeIMO.Rtf.RtfLoadOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public static RtfReadResult ParseResult(string rtf, RtfLoadOptions? options = null, CancellationToken cancellationToken = default) #

Parses RTF text and returns the semantic document, lossless syntax, and diagnostics.

Parameters

rtf string required
options OfficeIMO.Rtf.RtfLoadOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public bool RemoveBlock(IRtfBlock block) #

Removes a block when it belongs to this document.

Parameters

block OfficeIMO.Rtf.IRtfBlock required

Returns

bool
public IRtfBlock RemoveBlockAt(int index) #

Removes and returns the block at the specified index.

Parameters

index int required

Returns

IRtfBlock
RemoveSelectedContent 2 overloads
public static OfficeContentCleanupResult RemoveSelectedContent(byte[] rtf, OfficeContentCleanupSelection selection, OfficeContentCleanupOptions? options = null, RtfLoadOptions? readOptions = null, RtfSaveOptions? writeOptions = null) #

Removes exact selected RTF run payloads and verifies the normalized rewritten artifact.

Parameters

rtf byte[] required
selection OfficeIMO.ContentSafety.OfficeContentCleanupSelection required
options OfficeIMO.ContentSafety.OfficeContentCleanupOptions? = null optional
readOptions OfficeIMO.Rtf.RtfLoadOptions? = null optional
writeOptions OfficeIMO.Rtf.RtfSaveOptions? = null optional

Returns

OfficeContentCleanupResult
public static OfficeContentCleanupResult RemoveSelectedContent(string inputPath, string outputPath, OfficeContentCleanupSelection selection, OfficeContentCleanupOptions? options = null, RtfLoadOptions? readOptions = null, RtfSaveOptions? writeOptions = null) #

Atomically writes an explicitly cleaned RTF artifact.

Parameters

inputPath string required
outputPath string required
selection OfficeIMO.ContentSafety.OfficeContentCleanupSelection required
options OfficeIMO.ContentSafety.OfficeContentCleanupOptions? = null optional
readOptions OfficeIMO.Rtf.RtfLoadOptions? = null optional
writeOptions OfficeIMO.Rtf.RtfSaveOptions? = null optional

Returns

OfficeContentCleanupResult
public bool ReplaceBookmarkText(string name, string replacement) #

Replaces all inline content inside the first matching named bookmark range.

Parameters

name string required
replacement string required

Returns

bool
public int ReplaceText(string oldText, string newText, StringComparison comparison = Ordinal) #

Replaces text across adjacent runs throughout the document body, headers, footers, and notes.

Parameters

oldText string required
newText string required
comparison System.StringComparison = Ordinal optional

Returns

int
public RtfListFormatting? ResolveListFormatting(RtfParagraph paragraph) #

Resolves the list instance, definition and targeted level beneath a paragraph. The returned level is an independent copy.

Parameters

paragraph OfficeIMO.Rtf.RtfParagraph required
public RtfParagraph ResolveParagraphFormatting(RtfParagraph paragraph) #

Returns an independent paragraph copy with inherited paragraph formatting applied. Missing bases and cycles stop the style chain at the last reachable entry.

Parameters

paragraph OfficeIMO.Rtf.RtfParagraph required
public RtfRun ResolveRunFormatting(RtfParagraph paragraph, RtfRun run) #

Returns an independent run copy with paragraph and character styles applied beneath direct formatting.

Parameters

paragraph OfficeIMO.Rtf.RtfParagraph required
run OfficeIMO.Rtf.RtfRun required

Returns

RtfRun
Save 3 overloads
public void Save(string path, RtfSaveOptions? options = null, Encoding? encoding = null) #

Saves the document to an RTF file.

Parameters

path string required
options OfficeIMO.Rtf.RtfSaveOptions? = null optional
encoding System.Text.Encoding? = null optional
public void Save(Stream stream, RtfSaveOptions? options = null, Encoding? encoding = null) #

Saves the document to an RTF stream without closing the stream.

Parameters

stream System.IO.Stream required
options OfficeIMO.Rtf.RtfSaveOptions? = null optional
encoding System.Text.Encoding? = null optional
public void Save(RtfSaveOptions? options = null, Encoding? encoding = null) #

Saves to the associated path. In-memory documents must first supply a file destination.

Parameters

options OfficeIMO.Rtf.RtfSaveOptions? = null optional
encoding System.Text.Encoding? = null optional
SaveAsync 3 overloads
public async Task SaveAsync(string path, RtfSaveOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default) #

Saves the document to an RTF file.

Parameters

path string required
options OfficeIMO.Rtf.RtfSaveOptions? = null optional
encoding System.Text.Encoding? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task
public async Task SaveAsync(Stream stream, RtfSaveOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default) #

Saves the document to an RTF stream without closing the stream.

Parameters

stream System.IO.Stream required
options OfficeIMO.Rtf.RtfSaveOptions? = null optional
encoding System.Text.Encoding? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task
public Task SaveAsync(RtfSaveOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default) #

Asynchronously saves to the associated path without changing caller-owned streams.

Parameters

options OfficeIMO.Rtf.RtfSaveOptions? = null optional
encoding System.Text.Encoding? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task
public RtfDocument SetRevisionRootSaveId(int? id) #

Sets the root revision save identifier represented by \rsidroot.

Parameters

id int? required
public byte[] ToBytes(RtfSaveOptions? options = null, Encoding? encoding = null) #

Serializes the document to encoded RTF bytes.

Parameters

options OfficeIMO.Rtf.RtfSaveOptions? = null optional
encoding System.Text.Encoding? = null optional

Returns

byte[]
public string ToRtf(RtfSaveOptions? options = null) #

Serializes the document to RTF.

Parameters

options OfficeIMO.Rtf.RtfSaveOptions? = null optional

Returns

string
public RtfConversionResult<string> ToRtfResult(RtfSaveOptions? options = null) #

Writes normalized semantic RTF with an operation-scoped report of source content that cannot survive normalization.

Parameters

options OfficeIMO.Rtf.RtfSaveOptions? = null optional
public MemoryStream ToStream(RtfSaveOptions? options = null, Encoding? encoding = null) #

Serializes the document to an encoded RTF memory stream.

Parameters

options OfficeIMO.Rtf.RtfSaveOptions? = null optional
encoding System.Text.Encoding? = null optional

Returns

MemoryStream

Properties

public IReadOnlyList<RtfParagraph> Paragraphs { get; } #

Paragraphs contained by the document.

public IReadOnlyList<IRtfBlock> Blocks { get; } #

Top-level document blocks in order.

public IReadOnlyList<RtfFont> Fonts { get; } #

Font table entries.

public IReadOnlyList<RtfColor> Colors { get; } #

Color table entries, including interior automatic-color slots.

public IReadOnlyList<RtfStyle> Styles { get; } #

Stylesheet entries.

public IReadOnlyList<RtfListDefinition> ListDefinitions { get; } #

List table definitions.

public IReadOnlyList<RtfListOverride> ListOverrides { get; } #

List override table entries.

public IReadOnlyList<RtfHeaderFooter> HeaderFooters { get; } #

Document headers and footers in write order.

public IReadOnlyList<RtfNote> Notes { get; } #

Footnotes, endnotes, and annotations in read or creation order.

public IReadOnlyList<RtfSection> Sections { get; } #

Semantic sections in document order when section structure is present.

public IReadOnlyList<RtfUserProperty> UserProperties { get; } #

Custom document properties from the RTF user properties table.

public IReadOnlyList<RtfDocumentVariable> DocumentVariables { get; } #

Document variables from RTF document variable destinations.

public IReadOnlyList<RtfRevisionAuthor> RevisionAuthors { get; } #

Revision author table entries used by run-level revision metadata.

public IReadOnlyList<int> RevisionSaveIds { get; } #

Revision save identifiers from the RTF rsidtbl destination.

public int? RevisionRootSaveId { get; set; } #

Root revision save identifier from \rsidroot.

public IReadOnlyList<RtfFileReference> FileReferences { get; } #

File table references from the document header.

public IReadOnlyList<RtfXmlNamespace> XmlNamespaces { get; } #

XML namespace declarations from the RTF xmlnstbl destination.

public RtfDocumentInfo Properties { get; private set; } #

Standard document properties stored in the RTF information group.

public RtfPageSetup PageSetup { get; private set; } #

Document page size and margins.

public RtfDocumentSettings Settings { get; private set; } #

Document-level settings such as view, protection, and default tabs.

public RtfNoteSettings NoteSettings { get; private set; } #

Document-level footnote and endnote numbering settings.

public RtfHtmlEncapsulation? HtmlEncapsulation { get; internal set; } #

Original Outlook/Exchange HTML encapsulation, when present.

public bool IsHtmlEncapsulationCurrent { get; } #

Whether the encapsulated HTML still corresponds to the current semantic document.

public string? FilePath { get; private set; } #

Gets the associated destination set by path creation, loading or a successful file save.