OfficeIMO.Rtf 3.2.2

Prefix Reserved
dotnet add package OfficeIMO.Rtf --version 3.2.2
                    
NuGet\Install-Package OfficeIMO.Rtf -Version 3.2.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OfficeIMO.Rtf" Version="3.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OfficeIMO.Rtf" Version="3.2.2" />
                    
Directory.Packages.props
<PackageReference Include="OfficeIMO.Rtf" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OfficeIMO.Rtf --version 3.2.2
                    
#r "nuget: OfficeIMO.Rtf, 3.2.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OfficeIMO.Rtf@3.2.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OfficeIMO.Rtf&version=3.2.2
                    
Install as a Cake Addin
#tool nuget:?package=OfficeIMO.Rtf&version=3.2.2
                    
Install as a Cake Tool

OfficeIMO.Rtf

OfficeIMO.Rtf is the managed Rich Text Format engine for OfficeIMO. It parses RTF into both a source-preserving syntax tree and an editable semantic model, writes deterministic RTF, enforces resource limits, and reports content that cannot be represented semantically.

Install

dotnet add package OfficeIMO.Rtf

Create and read RTF

using OfficeIMO.Rtf;

RtfDocument document = RtfDocument.Create();
document.AddParagraph().AddText("Quarterly report").SetBold();
document.AddParagraph("Prepared by OfficeIMO");

string rtf = document.ToRtf();
RtfReadResult read = RtfDocument.Read(rtf);

RtfDocument.ToRtf() writes a normalized semantic document. Use the lossless path when untouched source syntax, unknown destinations, binary payloads, or trailing bytes must remain exact:

RtfReadResult read = RtfDocument.Load("input.rtf");
read.SaveLossless("unchanged-copy.rtf");

Byte, stream, and file reads retain the exact original bytes. HasOriginalBytes, ToBytesLossless(), and TryGetLosslessBytes(...) make that contract observable. Character-only input can be written as lossless bytes only when every source character has an exact single-byte representation; the API reports or throws instead of silently transcoding it.

RTF field instructions are tokenized by RtfFieldCodeSyntax, including quoted arguments, switches, escapes, and unterminated-token state. Hyperlink projection uses this syntax rather than regular-expression extraction.

Read untrusted RTF

The default OfficeIMO profile is bounded, does not materialize embedded objects or file-table references, and accepts only web and mail hyperlinks. Uploaded files can state that policy explicitly and provide a cancellation token:

RtfReadOptions options = RtfReadOptions.CreateUntrustedProfile();
using FileStream input = File.OpenRead("upload.rtf");

RtfReadResult read = await RtfDocument.LoadAsync(
    input,
    options,
    cancellationToken: cancellationToken);

The profile caps input bytes and characters, group depth/count, token count, text, binary payloads, images, objects, and semantic block count. A breached limit throws RtfReadLimitException with a stable Code, LimitSource, observed value, configured limit, and source position.

The core never fetches external resources. RtfReadOptions.CreateCompatibilityProfile() restores the former unbounded, object-materializing, all-schemes behavior for trusted legacy inputs only.

Require no conversion loss

All adapters use RtfConversionReport for preserved, flattened, omitted, and blocked content:

var report = new RtfConversionReport();
report.AddReadDiagnostics(read.Diagnostics, "upload.rtf");

// Merge an adapter's report here.
report.Merge(adapterReport);
report.RequireNoLoss();

RequireNoLoss() throws RtfConversionLossException whenever a conversion flattened, omitted, blocked, or failed content. For permissive workflows, inspect report.Diagnostics and accept only the actions appropriate for that destination.

Semantic editing

Semantic editing produces normalized RTF and is the simplest option when the document meaning is more important than its original control-word layout:

RtfDocument document = RtfDocument.Load("input.rtf").Document;

document.InsertParagraph(0, "Confidential");
document.MoveBlock(0, document.Blocks.Count - 1);
document.ReplaceText("Contoso Ltd.", "Contoso Europe");
document.ReplaceBookmarkText("CustomerName", "Contoso Europe");

RtfDocument independentCopy = document.Clone();
RtfDocumentMergeResult merge = document.AppendDocument(otherDocument);
merge.Report.RequireNoLoss();

AppendDocument remaps fonts, colors, revision authors, blocks, tables, and notes. It reports style/list flattening and source header/footer omission rather than hiding those tradeoffs.

Lossless structural editing

RtfLosslessEditor changes selected syntax nodes while retaining every untouched node:

RtfLosslessEditor editor = RtfDocument.Load("input.rtf").EditLossless();

editor.ReplaceText("Old text", "New text");
editor.SetInfo(RtfDocumentInfoField.Title, "Updated title");
editor.InsertRootParagraph(editor.RootNodeCount, "Appended note");
editor.ReplaceImage(0, replacementImage);
editor.ReplaceDestinationContent("header", @"\pard Updated header\par");

editor.SaveLossless("edited.rtf");

Root nodes can also be inserted, removed, or moved with InsertRootRtf, RemoveRootNodes, and MoveRootNodes. Those APIs are syntax-indexed; bookmark and rich-text operations belong to the semantic model.

Encoding and interoperability

The reader supports Unicode escapes, single-byte Windows code pages 874 and 1250-1258, IBM 437/850, Mac Roman, and East Asian Windows code pages 932/936/949/950. Font charset changes can switch the active decoder within a document. Unsupported code pages emit diagnostic RTF103 and use the documented Windows-1252 fallback while lossless source remains intact.

Interoperability coverage includes RTF produced by Microsoft Word, Outlook, LibreOffice, Google Docs, macOS TextEdit/RTFD, an Epic EHI export, CRM and helpdesk workflows, and GemBox.Document. Each external sample is exercised through bounded reading, web-safe HTML, Markdown, and diagnostic-preserving Word conversion. See the RTF support matrix for exact producer classifications and known limits.

  • OfficeIMO.Word.Rtf: Word/DOCX conversion and result-bearing mail merge, find/replace, fields, merge, and compare workflows.
  • OfficeIMO.Html: web-safe or trusted round-trip HTML conversion.
  • OfficeIMO.Rtf.Markdown: Markdown conversion with footnotes and media callbacks.
  • OfficeIMO.Rtf.Pdf: visual PDF export and extractive PDF import.
  • OfficeIMO.Reader.Rtf: bounded chunk and provenance extraction.

See the living support matrix for feature-level boundaries and evidence.

Dependency footprint

  • External: No third-party RTF engine. System.Text.Encoding.CodePages supplies legacy encodings.
  • OfficeIMO: OfficeIMO.Core. Lexing, parsing, semantic binding, editing, and writing are first-party.

See the complete OfficeIMO package map for related formats and conversion paths.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on OfficeIMO.Rtf:

Package Downloads
OfficeIMO.Email

Managed email and Outlook data engine for EML, MSG/OFT, TNEF, ICS, vCard, Mbox, PST/OST, OLM, EMLX, Maildir, and Offline Address Book artifacts.

OfficeIMO.Reader.Rtf

Bounded RTF chunk, table, visual, warning, and provenance adapter for OfficeIMO.Reader.

OfficeIMO.Word.Rtf

Result-bearing RTF converter and document workflow bridge for OfficeIMO.Word.

OfficeIMO.Rtf.Pdf

Bidirectional semantic RTF/PDF converter with shared fidelity diagnostics and managed image handling.

OfficeIMO.Rtf.Markdown

Semantic Rich Text Format and Markdown conversion bridge for OfficeIMO.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.2.2 248 8/13/2026
3.2.1 350 8/11/2026
3.2.0 628 8/7/2026
3.1.1 747 8/7/2026
3.1.0 762 8/6/2026
3.0.3 1,388 7/27/2026
3.0.2 3,190 7/26/2026
3.0.1 1,181 7/26/2026
3.0.0 1,774 7/20/2026
2.0.1 1,736 7/14/2026
2.0.0 1,227 7/14/2026
0.1.10 1,266 7/9/2026
0.1.9 1,158 7/8/2026
0.1.8 1,315 7/5/2026
0.1.7 1,087 7/4/2026
0.1.6 1,991 6/27/2026
0.1.5 920 6/27/2026
0.1.4 1,192 6/24/2026
0.1.3 979 6/23/2026
0.1.2 1,067 6/21/2026
Loading failed