Skip to content

Flatten annotations in a PDF in C#

Since 1.1View as Markdown

Make review marks part of the page, so nobody can move, edit or hide them.

PdfDocument.FlattenAnnotations draws the appearance of every markup annotation (notes, text markup, free text, stamps, ink, shapes and file attachments) into its page’s content and removes the annotation with its pop up. Links and form fields stay unless you ask for them.

PdfDocument doc = PdfDocument.Open("contract-reviewed.pdf");
int flattened = doc.FlattenAnnotations(); // every page; links and form fields stay
doc.Save("contract-flat.pdf");
Console.WriteLine($"{flattened} annotations are now page content");

To flatten a single annotation, pass it to its page’s collection:

PdfDocument other = PdfDocument.Open("contract-reviewed.pdf");
PdfPage page = other.Pages[0];
PdfAnnotation stamp = page.Annotations.First(a => a.Subtype == "Stamp");
page.Annotations.Flatten(stamp); // only the stamp; the rest stay editable
other.Save("contract-stamped.pdf");
  • new PdfFlattenOptions { IncludeLinks = true } also flattens links: they keep their look and stop working. IncludeWidgets = true also flattens form fields, which show their current value and leave the form. doc.Form.Flatten() flattens a whole form.
  • Hidden annotations, and annotations without an appearance, stay as they are.