# Read RTF Files and Extract Text

Open RTF files safely, extract paragraph text and document properties, check read diagnostics, inspect embedded pictures and objects, and chunk RTF for search.

**Packages**

- [OfficeIMO.Rtf](https://www.nuget.org/packages/OfficeIMO.Rtf) `dotnet add package OfficeIMO.Rtf`
- [OfficeIMO.Reader.Rtf](https://www.nuget.org/packages/OfficeIMO.Reader.Rtf) `dotnet add package OfficeIMO.Reader.Rtf`

**Works with**

- .NET
- [PowerShell](/docs/pswriteoffice/install/) `Install-Module PSWriteOffice`
- [CLI](/docs/cli/install/) `dotnet tool install --global OfficeIMO.Tool`

**Target frameworks**

netstandard2.0, net8.0, net10.0, net472

**APIs**

- [`RtfDocument`](/api/rtf/officeimo-rtf-rtfdocument/)
- [`RtfReadResult`](/api/rtf/officeimo-rtf-rtfreadresult/)
- [`RtfLoadOptions`](/api/rtf/officeimo-rtf-rtfloadoptions/)
- [`RtfReadLimitException`](/api/rtf/officeimo-rtf-rtfreadlimitexception/)
- [`OfficeDocumentReader`](/api/reader/officeimo-reader-officedocumentreader/)
- [`OfficeDocumentReaderBuilder`](/api/reader/officeimo-reader-officedocumentreaderbuilder/)
- [`OfficeEmbeddedPayloadInfo`](/api/core/officeimo-officeembeddedpayloadinfo/)
- [`OfficeEmbeddedPayloadInspection`](/api/core/officeimo-officeembeddedpayloadinspection/)
- [`OfficeEmbeddedPayloadInspectionOptions`](/api/core/officeimo-officeembeddedpayloadinspectionoptions/)
- [`ReaderChunk`](/api/reader/officeimo-reader-readerchunk/)
- [`RtfParagraph`](/api/rtf/officeimo-rtf-rtfparagraph/)

**Cmdlets**

- [`Open-OfficeRtf`](/api/powershell/open-officertf/)
- [`Read-OfficeDocument`](/api/powershell/read-officedocument/)

**Commands**

- [`officeimo reader read`](/docs/cli/extract-and-inspect/)

**Limits**

The reader never fetches external resources or activates embedded objects; object bytes are available only for inspection. [OfficeIMO.Rtf support matrix](/compatibility/#package-rtf)

**Verified**

Examples compiled against the source on 2026-11-14

**Data**

- [OfficeIMO.Rtf API index](/api/rtf/index.json)
- [OfficeIMO.Reader.Rtf API index](/api/reader-rtf/index.json)
- [PSWriteOffice command catalog](/data/powershell/commands.json)
- [CLI command catalog](/data/cli/commands.json)
- [Capability catalog (JSON)](/data/capabilities.json)

`RtfDocument.Load` returns the semantic model. `RtfDocument.LoadResult` returns an `RtfReadResult` that also carries the read diagnostics and the original bytes, so you can report what the parser skipped and still save an exact copy. For uploads and other untrusted input, pass `RtfLoadOptions.UntrustedDefaults`.

## Extract text and properties

### C#

```csharp
using OfficeIMO.Rtf;

RtfDocument sample = RtfDocument.Create();
sample.Properties.Title = "Visit summary";
sample.Properties.Author = "Front desk";
sample.AddParagraph("Patient arrived at 09:00.");
sample.AddParagraph("Follow-up booked for next week.");
File.WriteAllText("note.rtf", sample.ToRtf());

RtfDocument document = RtfDocument.Load("note.rtf");
Console.WriteLine($"{document.Properties.Title} by {document.Properties.Author}");

foreach (RtfParagraph paragraph in document.Paragraphs) {
    Console.WriteLine(paragraph.ToPlainText());
}
```

### PowerShell

```powershell
$rtf = Open-OfficeRtf -Path .\note.rtf
Read-OfficeDocument -Path .\note.rtf -As Text
```

### CLI

```sh
officeimo reader read note.rtf --format markdown --output note.md
```

## Read uploaded RTF safely

The untrusted profile caps input size, group depth, tokens, text, pictures and objects. It does not materialize embedded objects or file references and keeps only web and mail hyperlinks. A breached limit throws `RtfReadLimitException` with the limit that was hit.

### C#

```csharp
using OfficeIMO.Rtf;

File.WriteAllText("upload.rtf", @"{\rtf1\ansi Uploaded \b text\b0.\par}");

using FileStream input = File.OpenRead("upload.rtf");
RtfReadResult read = await RtfDocument.LoadResultAsync(input, RtfLoadOptions.UntrustedDefaults);

foreach (var diagnostic in read.Diagnostics) {
    Console.WriteLine($"{diagnostic.Severity} {diagnostic.Code} at {diagnostic.Position}: {diagnostic.Message}");
}

Console.WriteLine(read.Document.Paragraphs.Count);
```

## Keep an exact copy of the source

`SaveLossless` writes the original bytes back, including content the semantic model does not represent.

### C#

```csharp
using OfficeIMO.Rtf;

File.WriteAllText("legacy.rtf", @"{\rtf1\ansi{\*\customdest kept as is}Legacy text\par}");

RtfReadResult read = RtfDocument.LoadResult("legacy.rtf");
read.SaveLossless("legacy-copy.rtf");

Console.WriteLine(File.ReadAllText("legacy-copy.rtf") == File.ReadAllText("legacy.rtf"));
```

## Inspect embedded pictures and objects

With `DeferBinaryPayloads`, picture and object data stay as source fragments until you ask for them. The inspection lists every payload, and `OpenRead` returns a read-only copy of one. Objects are never activated.

### C#

```csharp
using OfficeIMO;
using OfficeIMO.Rtf;

File.WriteAllText("report.rtf", @"{\rtf1\ansi Report\par}");

RtfReadResult read = RtfDocument.LoadResult("report.rtf", new RtfLoadOptions {
    DeferBinaryPayloads = true
});

using OfficeEmbeddedPayloadInspection payloads = read.InspectEmbeddedPayloads(
    new OfficeEmbeddedPayloadInspectionOptions {
        MaxPayloadBytes = 8L * 1024 * 1024,
        MaxTotalPayloadBytes = 32L * 1024 * 1024
    });

foreach (OfficeEmbeddedPayloadInfo payload in payloads.Payloads) {
    Console.WriteLine($"{payload.Ordinal}: {payload.Id}");
}
```

## Split RTF into chunks for search

`OfficeIMO.Reader.Rtf` turns the semantic model into block-aware chunks with Markdown text, ready for an index or a retrieval pipeline.

### C#

```csharp
using OfficeIMO.Reader;
using OfficeIMO.Reader.Rtf;
using OfficeIMO.Rtf;

RtfDocument sample = RtfDocument.Create();
sample.AddParagraph("Retention policy");
sample.AddParagraph("Records are kept for seven years.");
File.WriteAllText("policy.rtf", sample.ToRtf());

OfficeDocumentReader reader = new OfficeDocumentReaderBuilder()
    .AddRtfHandler()
    .Build();

foreach (ReaderChunk chunk in reader.Enumerate("policy.rtf")) {
    Console.WriteLine($"{chunk.Id}: {chunk.Markdown ?? chunk.Text}");
}
```

### PowerShell

```powershell
Read-OfficeDocument -Path .\policy.rtf
```

### CLI

```sh
officeimo reader read policy.rtf --format json --output policy.json
```

<!-- PowerForge markdown source sha256:FF001DEED97964A1A7D0265975C0A3772998ABA6832EFAAE50552CA67C5DBB15; title=True -->

<!-- PowerForge markdown artifact sha256:16A5ED39422EAF9C7377F29810B2FD3CD8347CB11C3A95A11C2998B6746E5F8B -->
