---
title: "Save a PDF incrementally in C#"
url: https://recursiveai.org/onepdf/cookbook/save-pdf-incrementally/
description: "Save a PDF incrementally in C# with OnePDF. Append a metadata edit without rewriting the original bytes, and see when you need a full save instead."
version: "1.25.0"
---

# Save a PDF incrementally in C#

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

[NuGet](https://www.nuget.org/packages/RecursiveAI.OnePdf) · [GitHub](https://github.com/recursive-ai-oss/onepdf-csharp) · [Docs](https://recursiveai.org/onepdf/docs/) · [Download example (.zip)](https://recursiveai.org/onepdf/cookbook/save-pdf-incrementally/save-pdf-incrementally.zip)

An incremental save appends changes to a byte-for-byte copy, keeping the original bytes intact for signature checks.

```shell
dotnet add package RecursiveAI.OnePdf
```

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

```csharp
using OnePdf;

using var doc = PdfDocument.Open("sample.pdf",
    new PdfOpenOptions { AllowEditing = true });
doc.SetInfo("Title", "Approved");
using var output = File.Create("updated.pdf");
doc.SaveIncremental(output);
Console.WriteLine("Wrote updated.pdf");
```

Unzip [the example](https://recursiveai.org/onepdf/cookbook/save-pdf-incrementally/save-pdf-incrementally.zip), then `dotnet run`.

```text
Wrote updated.pdf
```

`updated.pdf` has the new title. Keep the output path different from the input path: `File.Create` truncates the file it opens.

## The full program

The one-page `sample.pdf` in the zip has the title “Draft.” The download reopens the output and compares its title and revision count with the original.

```csharp
using OnePdf;

var edit = new PdfOpenOptions { AllowEditing = true };
using var doc = PdfDocument.Open("sample.pdf", edit);
Console.WriteLine($"Original title: {doc.Info.Title}");
doc.SetInfo("Title", "Approved");
using (var output = File.Create("updated.pdf"))
{
    doc.SaveIncremental(output);
}

using var saved = PdfDocument.Open("updated.pdf");
Console.WriteLine($"Saved title: {saved.Info.Title}");
Console.WriteLine($"Revisions: {doc.Revisions.Count} -> {saved.Revisions.Count}");
```

```text
Original title: Draft
Saved title: Approved
Revisions: 1 -> 2
```

If the PDF had to be rebuilt by scanning, `SaveIncremental` throws `PdfFormatException`: there’s no original cross-reference section to link to. Use a full `Save` for repaired files.

## Variations

**Write to memory.** Replace the last three lines of the snippet at the top with this to get a complete PDF as a byte array:

```csharp
using var output = new MemoryStream();
doc.SaveIncremental(output);
byte[] pdf = output.ToArray();
```

**Use a full save instead.** Replace those same lines with this when you don’t want to carry over the original file as an earlier revision:

```csharp
doc.Save("rewritten.pdf");
```

## Related recipes

- [Repair a damaged PDF](https://recursiveai.org/onepdf/cookbook/repair-damaged-pdf/)
- [Sign and verify a PDF](https://recursiveai.org/onepdf/cookbook/sign-and-verify/)
- [Fill a PDF form](https://recursiveai.org/onepdf/cookbook/fill-pdf-form/)

## The short answer

To save an incremental PDF update in C#, open an existing file with `AllowEditing = true`, edit it, then call `doc.SaveIncremental(output)` with a new writable stream. The result is a whole PDF, not a patch you have to apply. Its first bytes are identical to the input, and the appended revision is what makes a reader see the new title in this example.

## What is an incremental update in a PDF?

A PDF reader uses cross-reference data to find the objects that make up the document. Instead of writing every object again, an incremental save appends the changed or added objects, cross-reference entries for the update, and a trailer that points back to the previous cross-reference section via `/Prev`. The viewer follows that chain to get unchanged objects from earlier revisions. In this example, the original title is still in the old revision, even though a viewer opening the latest one sees “Approved.” The [writing reference](https://recursiveai.org/onepdf/docs/writing/) describes how OnePDF writes the update.

Since the output includes the original, it still has to copy the original bytes to the destination. The benefit is keeping those bytes untouched and writing the edit on top rather than rebuilding the PDF. This is not a way to shrink the file or remove data from it.

## How do I save changes to a PDF more than once?

Every call saves the changes since the document was **opened**, not the changes since the last call. If you want the next edit to produce a third revision after the two in the example, close the output, open `updated.pdf` for editing, make the next change, and save to another new stream. If you instead keep the original `doc` open, each save still starts with `sample.pdf`; it does not extend the first saved copy.

## When should I use a full save instead of an incremental update?

Use a full save when writing a repaired PDF, removing or changing encryption, or asking for a PDF/A or PDF/UA conformance save. OnePDF also refuses an incremental save when it finds lost page-tree entries or when you’ve applied redaction, because the appended revision can’t remove bytes from the source. If the file is signed, keeping the original bytes is not the same as being allowed to edit it: a certification signature may restrict the changes a reader accepts. See [signature verification](https://recursiveai.org/onepdf/docs/signatures/) before relying on an updated file’s signature status.
