API Reference
RtfDocument
Semantic Rich Text Format document model.
Inheritance
- Object
- RtfDocument
Usage
This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.
Returned or exposed by
- Method RtfDocument.AddRevisionSaveId
- Method RtfDocument.Clone
- Method RtfDocument.Create
- Method RtfDocument.Load
- Method RtfDocument.Load
- Method RtfDocument.Load
- Method RtfDocument.LoadAsync
- Method RtfDocument.LoadAsync
- Method RtfDocument.Parse
- Method RtfDocument.SetRevisionRootSaveId
- Method RtfDocumentMergeResult.RequireNoLoss
- Method RtfDocumentMergeResult.RequireValue
- Property RtfDocumentMergeResult.Document
- Property RtfDocumentMergeResult.Value
- Method RtfReadResult.RequireValue
- Property RtfReadResult.Document
- Property RtfReadResult.Value
Accepted by parameters
- Method RtfDocument.AppendDocument
- Method RtfDocument.AppendDocument
- Constructor RtfListNumbering.RtfListNumbering
Methods
public Void AddBlock(IRtfBlock block) #VoidAdds an existing semantic block at the end of the document.
Parameters
- block OfficeIMO.Rtf.IRtfBlock
public Int32 AddColor(Byte red, Byte green, Byte blue) #Int32Adds a color to the color table and returns its RTF color index.
Parameters
- red System.Byte
- green System.Byte
- blue System.Byte
public RtfDocumentVariable AddDocumentVariable(String name, String value) #RtfDocumentVariableAdds a document variable.
Parameters
- name System.String
- value System.String
public RtfFileReference AddFileReference(String path, RtfFileSource sources = Ntfs) #RtfFileReferenceAdds a file table reference and returns it.
Parameters
- path System.String
- sources OfficeIMO.Rtf.RtfFileSource = Ntfs
public Int32 AddFont(String name) #Int32Adds a font to the font table or returns the existing id.
Parameters
- name System.String
public RtfImage AddImage(RtfImageFormat format, Byte[] data) #RtfImageAdds a picture block to the document.
Parameters
- format OfficeIMO.Rtf.RtfImageFormat
- data System.Byte[]
public RtfListDefinition AddListDefinition(Int32 id, String name = null) #RtfListDefinitionAdds or returns a list definition.
Parameters
- id System.Int32
- name System.String = null
public RtfListOverride AddListOverride(Int32 id, Int32 listId) #RtfListOverrideAdds or returns a list override.
Parameters
- id System.Int32
- listId System.Int32
public RtfNote AddNote(RtfNoteKind kind) #RtfNoteAdds a detached footnote or annotation.
Parameters
- kind OfficeIMO.Rtf.RtfNoteKind
public RtfObject AddObject(RtfObjectKind kind = Unknown, Byte[] data = null) #RtfObjectAdds an embedded or linked object block to the document.
Parameters
- kind OfficeIMO.Rtf.RtfObjectKind = Unknown
- data System.Byte[] = null
public RtfParagraph AddParagraph(String text = null) #RtfParagraphAdds a paragraph to the document.
Parameters
- text System.String = null
public Int32 AddRevisionAuthor(String name) #Int32Adds a revision author and returns its zero-based table index.
Parameters
- name System.String
public RtfDocument AddRevisionSaveId(Int32 id) #RtfDocumentAdds a revision save identifier to the document rsidtbl.
Parameters
- id System.Int32
public RtfSection AddSection(RtfSectionBreakKind breakKind = NextPage) #RtfSectionAdds a semantic section to the document.
Parameters
- breakKind OfficeIMO.Rtf.RtfSectionBreakKind = NextPage
public RtfStyle AddStyle(Int32 id, String name, RtfStyleKind kind = Paragraph) #RtfStyleAdds or replaces a stylesheet entry.
Parameters
- id System.Int32
- name System.String
- kind OfficeIMO.Rtf.RtfStyleKind = Paragraph
public RtfTable AddTable(Int32 rows, Int32 columns) #RtfTableAdds a table block to the document.
Parameters
- rows System.Int32
- columns System.Int32
public RtfUserProperty AddUserProperty(String name, Nullable<Int32> typeCode = null, String staticValue = null) #RtfUserPropertyAdds a custom document property.
Parameters
- name System.String
- typeCode System.Nullable{System.Int32} = null
- staticValue System.String = null
public RtfUserProperty AddUserProperty(RtfUserProperty property) #RtfUserPropertyAdds an existing custom document property.
Parameters
- property OfficeIMO.Rtf.RtfUserProperty
public RtfXmlNamespace AddXmlNamespace(Int32 id, String uri) #RtfXmlNamespaceAdds an XML namespace declaration to the document namespace table.
Parameters
- id System.Int32
- uri System.String
public RtfDocumentMergeResult AppendDocument(RtfDocument source) #RtfDocumentMergeResultAppends 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
public RtfDocumentMergeResult AppendDocument(RtfDocument source, RtfDocumentMergeOptions options) #RtfDocumentMergeResultAppends an independent copy with imported resources and optional source section preservation.
Parameters
- source OfficeIMO.Rtf.RtfDocument
- options OfficeIMO.Rtf.RtfDocumentMergeOptions
public RtfDocument Clone() #RtfDocumentCreates an independent semantic clone, retaining resources, ownership, and shared references.
public RtfColor GetColor(Int32 colorIndex) #RtfColorResolves an authored RTF color index. Automatic and missing colors return null.
Parameters
- colorIndex System.Int32
public RtfPageSetup GetEffectivePageSetup(RtfSection section) #RtfPageSetupReturns an independent page setup with document defaults applied beneath the section's authored values.
Parameters
- section OfficeIMO.Rtf.RtfSection
public Void InsertBlock(Int32 index, IRtfBlock block) #VoidInserts an existing semantic block at the specified document block index.
Parameters
- index System.Int32
- block OfficeIMO.Rtf.IRtfBlock
public RtfImage InsertImage(Int32 index, RtfImageFormat format, Byte[] data) #RtfImageCreates and inserts an image at the specified document block index.
Parameters
- index System.Int32
- format OfficeIMO.Rtf.RtfImageFormat
- data System.Byte[]
public RtfParagraph InsertParagraph(Int32 index, String text = null) #RtfParagraphCreates and inserts a paragraph at the specified document block index.
Parameters
- index System.Int32
- text System.String = null
public RtfTable InsertTable(Int32 index, Int32 rows, Int32 columns) #RtfTableCreates and inserts a table at the specified document block index.
Parameters
- index System.Int32
- rows System.Int32
- columns System.Int32
public static OfficeContentSafetyReport InspectContentSafety(Byte[] rtf, OfficeContentSafetyOptions options = null, RtfReadOptions readOptions = null) #OfficeContentSafetyReportInspects native RTF visibility, revision, geometry, contrast, and non-primary story evidence.
Parameters
- arg1 System.Byte[]
- arg2 OfficeIMO.ContentSafety.OfficeContentSafetyOptions = null
- arg3 OfficeIMO.Rtf.RtfReadOptions = null
public static OfficeContentSafetyReport InspectContentSafety(String filePath, OfficeContentSafetyOptions options = null, RtfReadOptions readOptions = null) #OfficeContentSafetyReportInspects an RTF file without treating concealment as evidence of AI authorship.
Parameters
- arg1 System.String
- arg2 OfficeIMO.ContentSafety.OfficeContentSafetyOptions = null
- arg3 OfficeIMO.Rtf.RtfReadOptions = null
public static RtfDocument Load(String path, RtfReadOptions options = null, Encoding encoding = null, CancellationToken cancellationToken = default) #RtfDocumentLoads RTF from a file into the semantic document model.
Parameters
- path System.String
- options OfficeIMO.Rtf.RtfReadOptions = null
- encoding System.Text.Encoding = null
- cancellationToken System.Threading.CancellationToken = default
public static RtfDocument Load(Byte[] bytes, RtfReadOptions options = null, CancellationToken cancellationToken = default) #RtfDocumentLoads RTF bytes into the semantic document model.
Parameters
- bytes System.Byte[]
- options OfficeIMO.Rtf.RtfReadOptions = null
- cancellationToken System.Threading.CancellationToken = default
public static RtfDocument Load(Stream stream, RtfReadOptions options = null, Encoding encoding = null, CancellationToken cancellationToken = default) #RtfDocumentLoads RTF from a stream into the semantic document model.
Parameters
- stream System.IO.Stream
- options OfficeIMO.Rtf.RtfReadOptions = null
- encoding System.Text.Encoding = null
- cancellationToken System.Threading.CancellationToken = default
public static async Task<RtfDocument> LoadAsync(String path, RtfReadOptions options = null, Encoding encoding = null, CancellationToken cancellationToken = default) #Task<RtfDocument>Asynchronously loads RTF from a file into the semantic document model.
Parameters
- path System.String
- options OfficeIMO.Rtf.RtfReadOptions = null
- encoding System.Text.Encoding = null
- cancellationToken System.Threading.CancellationToken = default
public static async Task<RtfDocument> LoadAsync(Stream stream, RtfReadOptions options = null, Encoding encoding = null, CancellationToken cancellationToken = default) #Task<RtfDocument>Asynchronously loads RTF from a stream into the semantic document model.
Parameters
- stream System.IO.Stream
- options OfficeIMO.Rtf.RtfReadOptions = null
- encoding System.Text.Encoding = null
- cancellationToken System.Threading.CancellationToken = default
public static RtfReadResult LoadResult(String path, RtfReadOptions options = null, Encoding encoding = null, CancellationToken cancellationToken = default) #RtfReadResultLoads RTF from a file with lossless syntax and diagnostics.
Parameters
- path System.String
- options OfficeIMO.Rtf.RtfReadOptions = null
- encoding System.Text.Encoding = null
- cancellationToken System.Threading.CancellationToken = default
public static RtfReadResult LoadResult(Byte[] bytes, RtfReadOptions options = null, CancellationToken cancellationToken = default) #RtfReadResultLoads RTF from source bytes using the byte-preserving lossless representation.
Parameters
- bytes System.Byte[]
- options OfficeIMO.Rtf.RtfReadOptions = null
- cancellationToken System.Threading.CancellationToken = default
public static RtfReadResult LoadResult(Stream stream, RtfReadOptions options = null, Encoding encoding = null, CancellationToken cancellationToken = default) #RtfReadResultLoads RTF from a stream with lossless syntax and diagnostics.
Parameters
- stream System.IO.Stream
- options OfficeIMO.Rtf.RtfReadOptions = null
- encoding System.Text.Encoding = null
- cancellationToken System.Threading.CancellationToken = default
public static async Task<RtfReadResult> LoadResultAsync(String path, RtfReadOptions options = null, Encoding encoding = null, CancellationToken cancellationToken = default) #Task<RtfReadResult>Asynchronously loads RTF from a file with lossless syntax and diagnostics.
Parameters
- path System.String
- options OfficeIMO.Rtf.RtfReadOptions = null
- encoding System.Text.Encoding = null
- cancellationToken System.Threading.CancellationToken = default
public static async Task<RtfReadResult> LoadResultAsync(Stream stream, RtfReadOptions options = null, Encoding encoding = null, CancellationToken cancellationToken = default) #Task<RtfReadResult>Asynchronously loads RTF from a stream with lossless syntax and diagnostics.
Parameters
- stream System.IO.Stream
- options OfficeIMO.Rtf.RtfReadOptions = null
- encoding System.Text.Encoding = null
- cancellationToken System.Threading.CancellationToken = default
public Void MoveBlock(Int32 fromIndex, Int32 toIndex) #VoidMoves a document block to its final zero-based index.
Parameters
- fromIndex System.Int32
- toIndex System.Int32
public static RtfDocument Parse(String rtf, RtfReadOptions options = null, CancellationToken cancellationToken = default) #RtfDocumentParses RTF text into the semantic document model.
Parameters
- rtf System.String
- options OfficeIMO.Rtf.RtfReadOptions = null
- cancellationToken System.Threading.CancellationToken = default
public static RtfReadResult ParseResult(String rtf, RtfReadOptions options = null, CancellationToken cancellationToken = default) #RtfReadResultParses RTF text and returns the semantic document, lossless syntax, and diagnostics.
Parameters
- rtf System.String
- options OfficeIMO.Rtf.RtfReadOptions = null
- cancellationToken System.Threading.CancellationToken = default
public static RtfReadResult Read(String rtf, RtfReadOptions options = null) #RtfReadResultReads RTF from a string.
Parameters
- rtf System.String
- options OfficeIMO.Rtf.RtfReadOptions = null
public static RtfReadResult Read(String rtf, RtfReadOptions options, CancellationToken cancellationToken) #RtfReadResultReads RTF from a string with cooperative cancellation during CPU-bound parsing.
Parameters
- rtf System.String
- options OfficeIMO.Rtf.RtfReadOptions
- cancellationToken System.Threading.CancellationToken
public Boolean RemoveBlock(IRtfBlock block) #BooleanRemoves a block when it belongs to this document.
Parameters
- block OfficeIMO.Rtf.IRtfBlock
public IRtfBlock RemoveBlockAt(Int32 index) #IRtfBlockRemoves and returns the block at the specified index.
Parameters
- index System.Int32
public static OfficeContentCleanupResult RemoveSelectedContent(Byte[] rtf, OfficeContentCleanupSelection selection, OfficeContentCleanupOptions options = null, RtfReadOptions readOptions = null, RtfWriteOptions writeOptions = null) #OfficeContentCleanupResultRemoves exact selected RTF run payloads and verifies the normalized rewritten artifact.
Parameters
- rtf System.Byte[]
- selection OfficeIMO.ContentSafety.OfficeContentCleanupSelection
- options OfficeIMO.ContentSafety.OfficeContentCleanupOptions = null
- readOptions OfficeIMO.Rtf.RtfReadOptions = null
- writeOptions OfficeIMO.Rtf.RtfWriteOptions = null
public static OfficeContentCleanupResult RemoveSelectedContent(String inputPath, String outputPath, OfficeContentCleanupSelection selection, OfficeContentCleanupOptions options = null, RtfReadOptions readOptions = null, RtfWriteOptions writeOptions = null) #OfficeContentCleanupResultAtomically writes an explicitly cleaned RTF artifact.
Parameters
- inputPath System.String
- outputPath System.String
- selection OfficeIMO.ContentSafety.OfficeContentCleanupSelection
- options OfficeIMO.ContentSafety.OfficeContentCleanupOptions = null
- readOptions OfficeIMO.Rtf.RtfReadOptions = null
- writeOptions OfficeIMO.Rtf.RtfWriteOptions = null
public Boolean ReplaceBookmarkText(String name, String replacement) #BooleanReplaces all inline content inside the first matching named bookmark range.
Parameters
- name System.String
- replacement System.String
public Int32 ReplaceText(String oldText, String newText, StringComparison comparison = Ordinal) #Int32Replaces text across adjacent runs throughout the document body, headers, footers, and notes.
Parameters
- oldText System.String
- newText System.String
- comparison System.StringComparison = Ordinal
public RtfListFormatting ResolveListFormatting(RtfParagraph paragraph) #RtfListFormattingResolves the list instance, definition and targeted level beneath a paragraph. The returned level is an independent copy.
Parameters
- paragraph OfficeIMO.Rtf.RtfParagraph
public RtfParagraph ResolveParagraphFormatting(RtfParagraph paragraph) #RtfParagraphReturns 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
public RtfRun ResolveRunFormatting(RtfParagraph paragraph, RtfRun run) #RtfRunReturns an independent run copy with paragraph and character styles applied beneath direct formatting.
Parameters
- paragraph OfficeIMO.Rtf.RtfParagraph
- run OfficeIMO.Rtf.RtfRun
public Void Save(String path, RtfWriteOptions options = null, Encoding encoding = null) #VoidSaves the document to an RTF file.
Parameters
- path System.String
- options OfficeIMO.Rtf.RtfWriteOptions = null
- encoding System.Text.Encoding = null
public Void Save(Stream stream, RtfWriteOptions options = null, Encoding encoding = null) #VoidSaves the document to an RTF stream without closing the stream.
Parameters
- stream System.IO.Stream
- options OfficeIMO.Rtf.RtfWriteOptions = null
- encoding System.Text.Encoding = null
public async Task SaveAsync(String path, RtfWriteOptions options = null, Encoding encoding = null, CancellationToken cancellationToken = default) #TaskSaves the document to an RTF file.
Parameters
- path System.String
- options OfficeIMO.Rtf.RtfWriteOptions = null
- encoding System.Text.Encoding = null
- cancellationToken System.Threading.CancellationToken = default
public async Task SaveAsync(Stream stream, RtfWriteOptions options = null, Encoding encoding = null, CancellationToken cancellationToken = default) #TaskSaves the document to an RTF stream without closing the stream.
Parameters
- stream System.IO.Stream
- options OfficeIMO.Rtf.RtfWriteOptions = null
- encoding System.Text.Encoding = null
- cancellationToken System.Threading.CancellationToken = default
public RtfDocument SetRevisionRootSaveId(Nullable<Int32> id) #RtfDocumentSets the root revision save identifier represented by \rsidroot.
Parameters
- id System.Nullable{System.Int32}
public Byte[] ToBytes(RtfWriteOptions options = null, Encoding encoding = null) #Byte[]Serializes the document to encoded RTF bytes.
Parameters
- options OfficeIMO.Rtf.RtfWriteOptions = null
- encoding System.Text.Encoding = null
public String ToRtf(RtfWriteOptions options = null) #StringSerializes the document to RTF.
Parameters
- options OfficeIMO.Rtf.RtfWriteOptions = null
public RtfConversionResult<String> ToRtfResult(RtfWriteOptions options = null) #RtfConversionResult<String>Writes normalized semantic RTF with an operation-scoped report of source content that cannot survive normalization.
Parameters
- options OfficeIMO.Rtf.RtfWriteOptions = null
public MemoryStream ToStream(RtfWriteOptions options = null, Encoding encoding = null) #MemoryStreamSerializes the document to an encoded RTF memory stream.
Parameters
- options OfficeIMO.Rtf.RtfWriteOptions = null
- encoding System.Text.Encoding = null
Inherited Methods
public override Boolean Equals(Object obj) #BooleanParameters
- obj Object
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<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<Int32> RevisionSaveIds { get; } #Revision save identifiers from the RTF rsidtbl destination.
public Nullable<Int32> 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 Info { get; set; } #Document information metadata.
public RtfPageSetup PageSetup { get; set; } #Document page size and margins.
public RtfDocumentSettings Settings { get; set; } #Document-level settings such as view, protection, and default tabs.
public RtfNoteSettings NoteSettings { get; set; } #Document-level footnote and endnote numbering settings.
public RtfHtmlEncapsulation HtmlEncapsulation { get; set; } #Original Outlook/Exchange HTML encapsulation, when present.
public Boolean IsHtmlEncapsulationCurrent { get; } #Whether the encapsulated HTML still corresponds to the current semantic document.