---
title: "Render a text comparison as a PDF redline in C#"
url: https://recursiveai.org/onediff/cookbook/render-text-document-redline-as-pdf/
description: "Compare two plain-text files in C# and render the changes into a new PDF with selectable text. Use inline marks or put the versions side by side."
version: "1.0.1"
---

# Render a text comparison as a PDF redline in C#

**OneDiff** is a free, open-source diff library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneDiff.Pdf) · [GitHub](https://github.com/recursive-ai-oss/onediff-csharp) · [Docs](https://recursiveai.org/onediff/docs/) · [Download example (.zip)](https://recursiveai.org/onediff/cookbook/render-text-document-redline-as-pdf/render-text-document-redline-as-pdf.zip)

Compare `before.txt` and `after.txt` from the zip to lay out a new PDF with changes marked.

```shell
dotnet add package RecursiveAI.OneDiff.Pdf
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneDiff.Documents;
using OneDiff.Pdf;

var comparison = Comparison.Of(
    "before.txt", "after.txt");
comparison.SaveAs("redline.pdf",
    PdfRedline.Rendered);
Console.WriteLine("Saved redline.pdf");
```

The zip contains two one-line documents, each ending with a newline:

| `before.txt` | `after.txt` |
|---|---|
| Please submit the draft on Monday. | Please submit the draft on Friday. |

The default inline style strikes through “Monday” and double-underlines “Friday.” On the redline page, select both words in your PDF viewer to copy the old and new text. The small example has a cover page before the comparison.

If the comparison is too large for the renderer to lay out, it throws `InvalidOperationException`; try the HTML redline instead.

Unzip [the example](https://recursiveai.org/onediff/cookbook/render-text-document-redline-as-pdf/render-text-document-redline-as-pdf.zip), then `dotnet run`.

Writes `redline.pdf` and prints:

```text
Saved redline.pdf
```

## Variations

Replace the `SaveAs` call with one of these, and update the filename in `Console.WriteLine` to match:

**Put the old and new text in separate columns on landscape pages.** Writes `side.pdf`.

```csharp
comparison.SaveAs("side.pdf",
    PdfRedline.RenderedSideBySide);
```

**Use US Letter instead of A4.** Writes `letter.pdf`.

```csharp
var letter = new RenderedPdfRedline
{
    Paper = PdfPaper.Letter
};
comparison.SaveAs("letter.pdf", letter);
```

## Related recipes

- [Compare PDFs and highlight differences on the original pages](https://recursiveai.org/onediff/cookbook/compare-pdf-highlight-changes/)
- [Write an inline document redline as HTML](https://recursiveai.org/onediff/cookbook/write-inline-document-redline-html/)

## The short answer

Compare the old and new files with `Comparison.Of`, then save the result with `PdfRedline.Rendered` from `RecursiveAI.OneDiff.Pdf`. The output is a new, paginated PDF with selectable text, not a copy of either input. Deletions and insertions appear together in the body, so the reader can see the old wording and its replacement in context. Use the side-by-side form when you want to read each version in its own column.

## What is a PDF redline?

A redline, also called a blackline, is a review copy that shows the changes between two versions. In the [default inline layout](https://recursiveai.org/onediff/docs/pdf/#4-rendered-redline), deleted text stays in the flow but is struck through; additions are double-underlined. That lets a reviewer see the change without opening both source files. The cover identifies the inputs and summarizes the changes. The footer gives their names and hashes so the review copy identifies the versions used to make it.

## How do you compare two PDFs and highlight differences?

Choose the output based on what you want to keep. A rendered redline uses the comparison to lay out new pages. That makes it useful for plain text, where there are no source pages to preserve. You can also render a comparison of digital PDFs, but the new result should not be treated as a copy of their page layouts, graphics, or form fields. Those items are not all present in the [PDF comparison model](https://recursiveai.org/onediff/docs/pdf/#1-reading-a-pdf).

If a reviewer needs the original page design, use [markup on the revised PDF](https://recursiveai.org/onediff/cookbook/compare-pdf-highlight-changes/) instead. That form adds marks on the existing pages using locations from the PDF text. It needs the revised PDF’s bytes; there’s no equivalent page to mark when your input is a text file.

## How can I tell if a PDF is text searchable?

Try selecting a changed word and searching for it in the viewer. In the sample, search for “Friday” on the redline page. You may also find “Monday”: deleted wording is still in the PDF, with a strike-through. Text copied from an inline redline can put old and new text next to each other, so don’t use it as the clean revised text. Share the revised source separately if readers need a clean copy.

Text being searchable does not guarantee the same characters are visible. The renderer ships with Liberation Sans. For scripts it doesn’t cover, [reference the OneRender font package for that script](https://recursiveai.org/onediff/docs/pdf/#fonts-for-other-scripts). Check how those words render as well as whether they can be selected.
