Recursive AI

PDF incremental update vs. full save

When to append an incremental update and when to rewrite the whole PDF, with a C# example that tests both.

An incremental update appends changes and keeps every byte of the input PDF. A full save writes a new file from the current document. Use an incremental update when earlier revisions need to stay available. Use a full save when the output should drop that history, including after redaction.

OnePDF is a free, open-source PDF library for .NET from Recursive AI, licensed MIT OR Apache-2.0. NuGet · GitHub
Install on .NET 10: dotnet add package RecursiveAI.OnePdf --version 1.25.1

Run this to change “Draft” to “Final” and see what each save keeps.

Program.csOnePDF 1.25.1 · .NET 10
using OnePdf;
 
using (var original = PdfDocument.CreateEmpty())
{
    original.InsertBlankPage(0, 612, 792);
    original.SetInfo("Title", "Draft");
    original.Save("original.pdf");
}
 
using (var doc = PdfDocument.Open("original.pdf",
    new PdfOpenOptions { AllowEditing = true }))
{
    doc.SetInfo("Title", "Final");
    using (var output = File.Create("incremental.pdf"))
        doc.SaveIncremental(output);
    doc.Save("rewritten.pdf");
}
 
byte[] originalBytes = File.ReadAllBytes("original.pdf");
foreach (var path in new[] { "incremental.pdf", "rewritten.pdf" })
{
    using var saved = PdfDocument.Open(path);
    bool keepsPrefix = File.ReadAllBytes(path).AsSpan().StartsWith(originalBytes);
    Console.WriteLine($"{path}: title={saved.Info.Title}, " +
        $"revisions={saved.Revisions.Count}, original prefix={keepsPrefix}");
}
Outputdotnet run
incremental.pdf: title=Final, revisions=2, original prefix=True
rewritten.pdf: title=Final, revisions=1, original prefix=False

Both outputs show “Final” in their current metadata. But only incremental.pdf still contains the earlier revision with the title “Draft.” The current view alone doesn’t tell you what is still in the file.

When to append and when to rewrite

If you need to…Save mode and why
Keep earlier revisions for reviewSaveIncremental
The original stays intact. The update contains the changed objects and a cross-reference section whose trailer points back with /Prev. Reopen the result and inspect Revisions.
Make an allowed edit after a signatureSaveIncremental, then verify
The signed bytes aren’t rewritten. That alone doesn’t make the change acceptable: a certification signature can permit only certain changes or forbid all changes.
Remove sensitive contentApply redaction, then Save
Appending keeps the bytes you want to remove. A full save drops earlier revisions but does not redact anything still in the current document.
Discard obsolete objects or repair cross-referencesSave
The writer follows reachable objects from the current catalog and Info dictionary instead of copying the old file. A file rebuilt by scanning has no cross-reference section for an update to chain to.
Change or remove encryption, or write PDF/A or PDF/UASave
OnePDF’s incremental writer keeps the original encryption and rejects the PDF/A and PDF/UA options.

These rules follow OnePDF’s pinned writing guide and save API. For signed PDFs, see how OnePDF checks changes after signing. For sensitive files, use the redaction workflow and check the finished file before sharing it.

What repeated saves do

SaveIncremental writes a complete PDF to a separate output stream. It copies the source first, even when the edit is small. If you call it twice on the same open document, each output starts from the file you opened, not the output of the preceding call. To build a chain of revisions, reopen the latest output before making the next edit.

Each appended revision leaves the old bytes in place, so a chain grows. A full rewrite can discard that history and any unreachable objects, but the result is not guaranteed to be smaller: the output structure and stream compression also affect its size. Keep a separate original if you need history as well as a rewritten copy.