RtfDocument
OfficeIMO.Rtf
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.
Returned or exposed by 13
- Method RtfDocument.AddRevisionSaveId
- Method RtfDocument.ApplyTheme
- Method RtfDocument.Clone
- Method RtfDocument.Create
- Method RtfDocument.Load
- Method RtfDocument.LoadAsync
- Method RtfDocument.Parse
- Method RtfDocument.SetRevisionRootSaveId
- Property RtfDocumentMergeResult.Document
- Property RtfDocumentMergeResult.Value
- Method RtfReadResult.RequireValue
- Property RtfReadResult.Document
- Property RtfReadResult.Value
Accepted by parameters 3
- Method RtfDocument.AppendDocument
- Method RtfDocumentMergeResult.Deconstruct
- Constructor RtfListNumbering.RtfListNumbering
Methods
public void AddBlock(IRtfBlock block) #Adds an existing semantic block at the end of the document.
Parameters
- block OfficeIMO.Rtf.IRtfBlock
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
- green byte
- blue byte
Returns
intpublic RtfDocumentVariable AddDocumentVariable(string name, string value) #Adds a document variable.
Parameters
- name string
- value string
Returns
RtfDocumentVariablepublic RtfFileReference AddFileReference(string path, RtfFileSource sources = Ntfs) #Adds a file table reference and returns it.
Parameters
- path string
- sources OfficeIMO.Rtf.RtfFileSource = Ntfs
Returns
RtfFileReferencepublic int AddFont(string name) #Adds a font to the font table or returns the existing id.
Parameters
- name string
Returns
intpublic RtfImage AddImage(RtfImageFormat format, byte[] data) #Adds a picture block to the document.
Parameters
- format OfficeIMO.Rtf.RtfImageFormat
- data byte[]
Returns
RtfImagepublic RtfListDefinition AddListDefinition(int id, string? name = null) #Adds or returns a list definition.
Parameters
- id int
- name string? = null
Returns
RtfListDefinitionpublic RtfListOverride AddListOverride(int id, int listId) #Adds or returns a list override.
Parameters
- id int
- listId int
Returns
RtfListOverridepublic RtfNote AddNote(RtfNoteKind kind) #Adds a detached footnote or annotation.
Parameters
- kind OfficeIMO.Rtf.RtfNoteKind
Returns
RtfNotepublic RtfObject AddObject(RtfObjectKind kind = Unknown, byte[]? data = null) #Adds an embedded or linked object block to the document.
Parameters
- kind OfficeIMO.Rtf.RtfObjectKind = Unknown
- data byte[]? = null
Returns
RtfObjectpublic RtfParagraph AddParagraph(string? text = null) #Adds a paragraph to the document.
Parameters
- text string? = null
Returns
RtfParagraphpublic int AddRevisionAuthor(string name) #Adds a revision author and returns its zero-based table index.
Parameters
- name string
Returns
intpublic RtfDocument AddRevisionSaveId(int id) #Adds a revision save identifier to the document rsidtbl.
Parameters
- id int
Returns
RtfDocumentpublic RtfSection AddSection(RtfSectionBreakKind breakKind = NextPage) #Adds a semantic section to the document.
Parameters
- breakKind OfficeIMO.Rtf.RtfSectionBreakKind = NextPage
Returns
RtfSectionpublic RtfStyle AddStyle(int id, string name, RtfStyleKind kind = Paragraph) #Adds or replaces a stylesheet entry.
Parameters
- id int
- name string
- kind OfficeIMO.Rtf.RtfStyleKind = Paragraph
Returns
RtfStylepublic RtfTable AddTable(int rows, int columns) #Adds a table block to the document.
Parameters
- rows int
- columns int
Returns
RtfTablepublic RtfUserProperty AddUserProperty(string name, int? typeCode = null, string? staticValue = null) #Adds a custom document property.
Parameters
- name string
- typeCode int? = null
- staticValue string? = null
Returns
RtfUserPropertypublic RtfUserProperty AddUserProperty(RtfUserProperty property) #Adds an existing custom document property.
Parameters
- property OfficeIMO.Rtf.RtfUserProperty
Returns
RtfUserPropertypublic RtfXmlNamespace AddXmlNamespace(int id, string uri) #Adds an XML namespace declaration to the document namespace table.
Parameters
- id int
- uri string
Returns
RtfXmlNamespacepublic 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
Returns
RtfDocumentMergeResultpublic RtfDocumentMergeResult AppendDocument(RtfDocument source, RtfDocumentMergeOptions? options) #Appends an independent copy with imported resources and optional source section preservation.
Parameters
- source OfficeIMO.Rtf.RtfDocument
- options OfficeIMO.Rtf.RtfDocumentMergeOptions?
Returns
RtfDocumentMergeResultpublic RtfDocument ApplyTheme(OfficeTheme theme) #Explicitly applies shared theme typography, paragraph spacing and table appearance to this document.
Parameters
- theme OfficeIMO.OfficeTheme
public RtfDocument Clone() #Creates an independent semantic clone, retaining resources, ownership, and shared references.
Returns
RtfDocumentpublic static RtfDocument Create(string path) #Creates an empty document associated with a path, without writing it.
Parameters
- path string
Returns
RtfDocumentpublic 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
Returns
RtfColor?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
Returns
RtfPageSetuppublic void InsertBlock(int index, IRtfBlock block) #Inserts an existing semantic block at the specified document block index.
Parameters
- index int
- block OfficeIMO.Rtf.IRtfBlock
public RtfImage InsertImage(int index, RtfImageFormat format, byte[] data) #Creates and inserts an image at the specified document block index.
Parameters
- index int
- format OfficeIMO.Rtf.RtfImageFormat
- data byte[]
Returns
RtfImagepublic RtfParagraph InsertParagraph(int index, string? text = null) #Creates and inserts a paragraph at the specified document block index.
Parameters
- index int
- text string? = null
Returns
RtfParagraphpublic RtfTable InsertTable(int index, int rows, int columns) #Creates and inserts a table at the specified document block index.
Parameters
- index int
- rows int
- columns int
Returns
RtfTablepublic 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[]
- options OfficeIMO.ContentSafety.OfficeContentSafetyOptions? = null
- readOptions OfficeIMO.Rtf.RtfLoadOptions? = null
Returns
OfficeContentSafetyReportpublic 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
- options OfficeIMO.ContentSafety.OfficeContentSafetyOptions? = null
- readOptions OfficeIMO.Rtf.RtfLoadOptions? = null
Returns
OfficeContentSafetyReportpublic 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
- cancellationToken System.Threading.CancellationToken = default
Returns
OfficeContentSafetyReportpublic 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
- options OfficeIMO.Rtf.RtfLoadOptions? = null
- encoding System.Text.Encoding? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
RtfDocumentpublic static RtfDocument Load(byte[] bytes, RtfLoadOptions? options = null, CancellationToken cancellationToken = default) #Loads RTF bytes into the semantic document model.
Parameters
- bytes byte[]
- options OfficeIMO.Rtf.RtfLoadOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
RtfDocumentpublic 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
- options OfficeIMO.Rtf.RtfLoadOptions? = null
- encoding System.Text.Encoding? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
RtfDocumentpublic 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
- options OfficeIMO.Rtf.RtfLoadOptions? = null
- encoding System.Text.Encoding? = null
- cancellationToken System.Threading.CancellationToken = default
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
- options OfficeIMO.Rtf.RtfLoadOptions? = null
- encoding System.Text.Encoding? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
Task<RtfDocument>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
- options OfficeIMO.Rtf.RtfLoadOptions? = null
- encoding System.Text.Encoding? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
RtfReadResultpublic 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[]
- options OfficeIMO.Rtf.RtfLoadOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
RtfReadResultpublic 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
- options OfficeIMO.Rtf.RtfLoadOptions? = null
- encoding System.Text.Encoding? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
RtfReadResultpublic 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
- options OfficeIMO.Rtf.RtfLoadOptions? = null
- encoding System.Text.Encoding? = null
- cancellationToken System.Threading.CancellationToken = default
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
- options OfficeIMO.Rtf.RtfLoadOptions? = null
- encoding System.Text.Encoding? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
Task<RtfReadResult>public void MoveBlock(int fromIndex, int toIndex) #Moves a document block to its final zero-based index.
Parameters
- fromIndex int
- toIndex int
public static RtfDocument Parse(string rtf, RtfLoadOptions? options = null, CancellationToken cancellationToken = default) #Parses RTF text into the semantic document model.
Parameters
- rtf string
- options OfficeIMO.Rtf.RtfLoadOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
RtfDocumentpublic 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
- options OfficeIMO.Rtf.RtfLoadOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
RtfReadResultpublic bool RemoveBlock(IRtfBlock block) #Removes a block when it belongs to this document.
Parameters
- block OfficeIMO.Rtf.IRtfBlock
Returns
boolpublic IRtfBlock RemoveBlockAt(int index) #Removes and returns the block at the specified index.
Parameters
- index int
Returns
IRtfBlockpublic 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[]
- selection OfficeIMO.ContentSafety.OfficeContentCleanupSelection
- options OfficeIMO.ContentSafety.OfficeContentCleanupOptions? = null
- readOptions OfficeIMO.Rtf.RtfLoadOptions? = null
- writeOptions OfficeIMO.Rtf.RtfSaveOptions? = null
Returns
OfficeContentCleanupResultpublic 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
- outputPath string
- selection OfficeIMO.ContentSafety.OfficeContentCleanupSelection
- options OfficeIMO.ContentSafety.OfficeContentCleanupOptions? = null
- readOptions OfficeIMO.Rtf.RtfLoadOptions? = null
- writeOptions OfficeIMO.Rtf.RtfSaveOptions? = null
Returns
OfficeContentCleanupResultpublic bool ReplaceBookmarkText(string name, string replacement) #Replaces all inline content inside the first matching named bookmark range.
Parameters
- name string
- replacement string
Returns
boolpublic 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
- newText string
- comparison System.StringComparison = Ordinal
Returns
intpublic 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
Returns
RtfListFormatting?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
Returns
RtfParagraphpublic 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
- run OfficeIMO.Rtf.RtfRun
Returns
RtfRunpublic void Save(string path, RtfSaveOptions? options = null, Encoding? encoding = null) #Saves the document to an RTF file.
Parameters
- path string
- options OfficeIMO.Rtf.RtfSaveOptions? = null
- encoding System.Text.Encoding? = null
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
- options OfficeIMO.Rtf.RtfSaveOptions? = null
- encoding System.Text.Encoding? = null
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
- encoding System.Text.Encoding? = null
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
- options OfficeIMO.Rtf.RtfSaveOptions? = null
- encoding System.Text.Encoding? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
Taskpublic 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
- options OfficeIMO.Rtf.RtfSaveOptions? = null
- encoding System.Text.Encoding? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
Taskpublic 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
- encoding System.Text.Encoding? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
Taskpublic RtfDocument SetRevisionRootSaveId(int? id) #Sets the root revision save identifier represented by \rsidroot.
Parameters
- id int?
Returns
RtfDocumentpublic byte[] ToBytes(RtfSaveOptions? options = null, Encoding? encoding = null) #Serializes the document to encoded RTF bytes.
Parameters
- options OfficeIMO.Rtf.RtfSaveOptions? = null
- encoding System.Text.Encoding? = null
Returns
byte[]public string ToRtf(RtfSaveOptions? options = null) #Serializes the document to RTF.
Parameters
- options OfficeIMO.Rtf.RtfSaveOptions? = null
Returns
stringpublic 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
Returns
RtfConversionResult<string>public MemoryStream ToStream(RtfSaveOptions? options = null, Encoding? encoding = null) #Serializes the document to an encoded RTF memory stream.
Parameters
- options OfficeIMO.Rtf.RtfSaveOptions? = null
- encoding System.Text.Encoding? = null
Returns
MemoryStreamInherited Methods
Properties
public IReadOnlyList<RtfParagraph> Paragraphs { get; } #Paragraphs contained by the document.
public IReadOnlyList<IRtfBlock> Blocks { get; } #Top-level document blocks in order.
public IReadOnlyList<RtfColor> Colors { get; } #Color table entries, including interior automatic-color slots.
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<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.