# Flatten annotations in a PDF in C#

> Turn comments, highlights, stamps and other PDF annotations into page content in .NET, so they print and show the same everywhere. MIT, pure C#.

Available since 1.1.

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

## Short answer

`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.

```csharp
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:

```csharp
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");
```

## Notes

- `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.

## Related

- [Annotations](https://www.jadev-corp.com/guides/annotations/): adding, reading and flattening annotations
- [Fill and flatten a PDF form](https://www.jadev-corp.com/recipes/fill-and-flatten-pdf-form/)
- API: [PdfDocument](https://www.jadev-corp.com/api/pdfnetstack/pdfdocument/), [PdfAnnotationCollection](https://www.jadev-corp.com/api/pdfnetstack/pdfannotationcollection/), [PdfFlattenOptions](https://www.jadev-corp.com/api/pdfnetstack/pdfflattenoptions/)

Source: https://www.jadev-corp.com/pdfnetstack/recipes/flatten-pdf-annotations/
