How to: Flatten Annotations
- 2 minutes to read
The following article describes how to use PDF Document Facade to flatten PDF annotations.
Important
The Universal Subscription or an additional Office File API Subscription is required to use this example in production code. Refer to the DevExpress Subscription page for pricing information.
The PdfViewerExtensions.GetDocumentFacade(IPdfViewer) method retrieves the PdfDocumentFacade class object that allows you to change the PDF document without access to its inner structure.
The PdfDocumentFacade allows you to flatten all document annotations, annotations on a specific page, and a single annotation. Utilize one of the following methods to complete the task:
Method | Description |
---|---|
PdfDocumentFacade.FlattenAnnotations() | Flattens document annotations. |
PdfPageFacade.FlattenAnnotations() | Flattens the page annotations. |
PdfAnnotationFacade.Flatten() | Flattens a specific annotation. |
The code sample below flattens document annotations:
PdfDocumentFacade documentFacade = pdfViewer.GetDocumentFacade();
// Flatten all text annotations in the document:
documentFacade.FlattenAnnotations(PdfAnnotationType.Text);
PdfPageFacade pageFacade = documentFacade.Pages[0];
SizeF pageSize = pdfViewer.GetPageSize(0);
double halfPage = pageSize.Height / 2;
// Flatten annotations that are located
// on the lower half of the page:
pageFacade.FlattenAnnotations(x => x.Rectangle.Top < halfPage);
var annotations = documentFacade.Pages[0].Annotations;
// Flatten the first annotation:
annotations[0].Flatten();