Annotation Editability

By default, PSPDFKit for Windows enables editing of all supported annotation types. Restricting annotation editing to specific types can be done either by using the ViewState or dynamically through an event.

It is important to note that when customizing the annotations available to the user in the toolbar, hiding a certain annotation is not enough to prevent the editability of already existing annotations of that type; one of the two approaches detailed below is also required.

Examples for both can also be found on the Editable Annotation Rules page of the Catalog.

Static Restrictions

When loading a document, you can use the EditableAnnotationTypes property of the ViewState to indicate which annotation types your users will be able to modify. If the set is null or empty, the user is allowed to select, create, edit, or delete every annotation type.

This property can only be set when opening a document, through the ShowDocumentWithViewStateAsync method, as shown below:

await pdfView.Controller.ShowDocumentWithViewStateAsync(document, new ViewState
    EditableAnnotationTypes = new HashSet<AnnotationType>

Dynamic Rules

A second solution to annotation editability is using the IsEditableAnnotation event handler found in the Controller. It allows for finer control, along with the possibility of more complex and specific rules to determine whether or not an existing annotation should be editable. To achieve this, the event takes precedence over the ViewState’s EditableAnnotationTypes property, and it’s able to override definitions made there:

private async void PDFView_InitializationCompletedHandler(PdfView sender, PSPDFKit.Pdf.Document args)
    // Wire up a handler to be called whenever the UI needs to know whether or not the annotation is editable.
    sender.Controller.IsEditableAnnotation += Controller_IsEditableAnnotation;

private void Controller_IsEditableAnnotation(Controller sender, AnnotationPermissionQuery args)
    // Decide whether or not this annotation should be editable based on the page.
    args.Editable = args.Annotation.PageIndex == 1;

Note that this event is closely related to the UI. As such, both user interaction and internal UI calls can trigger it, depending on circumstances. Multiple non-user-driven triggers are to be expected.