Select PDF Annotations Using JavaScript

The PSPDFKit for Web SDK enables you to select annotations using the built-in user interface (UI) or programmatically.

Using the Built-In UI

To select a single annotation, click on it in the UI.

To select multiple annotations, use one of the following methods:

  • Click the Select Multiple Annotations toolbar item, left-click, and draw a rectangle with your mouse around the annotations you want to select.

Select multiple annotations toolbar item
  • Press Shift and select the annotations one by one.

  • Press Control (Windows) or Command (macOS), left-click, and draw a rectangle with your mouse around the annotations you want to select.

  • Press Control-A (Windows) or Command-A (macOS) to select all annotations on the page.

Grouping Annotations

Grouping multiple annotations enables you to quickly select the same set of annotations in the future and perform actions on all of them in one go. After grouping annotations, you can select the whole group by clicking only one of the annotations in the group.

Group the selected annotations in one of the following ways:

  • Click the Group toolbar item.

Group multiple annotations toolbar item
  • Press Control-G (Windows) or Command-G (macOS).

Ungroup the annotations in one of the following ways:

  • Click one of the annotations in the group, and click the Group toolbar item.

  • Click one of the annotations in the group, and press Control-Shift-G (Windows) or Command-Shift-G (macOS).

Modifying Multiple Annotations

After selecting multiple annotations, perform one of the following actions:

  • Drag all the selected annotations to a new location on the page.

  • Copy all the selected annotations by pressing Control-C (Windows) or Command-C (macOS).

  • Paste all the selected annotations by pressing Control-V (Windows) or Command-V (macOS).

  • Duplicate all the selected annotations by pressing Control-D (Windows) or Command-D (macOS).

  • Delete all the selected annotations by pressing Del (Windows) or Command-Backspace (macOS).

Programmatically

To select an annotation, pass the annotation ID to the setSelectedAnnotation method:

instance.setSelectedAnnotation("ANNOTATION_ID");

To deselect the currently selected annotation, pass null to the setSelectedAnnotation method.

Programmatically, you can only select single annotations. You cannot select multiple annotations.