/ PDF Viewer / How To / Locking annotations in a PDF document
Search results

Locking annotations in a PDF document in Angular PDF Viewer component

21 Dec 2022 / 1 minute to read

The PDF Viewer provides a support to enable or disable lock option for the annotation in a pdf document. When an annotation is locked, it cannot be moved, resized, and removed.

Lock an annotation from code behind

The annotation can be locked either by default settings or by an event using the IsLocked API.

The following code sample illustrates how to lock custom stamp annotation in a PDF document through ajaxRequestSuccess event .

Copied to clipboard
<!--Render PDF Viewer component-->
<ejs-pdfviewer id="pdfViewer"
               [serviceUrl]="service"
               [documentPath]="document"
               (ajaxRequestSuccess)="fireAjaxRequestSuccess($event, $event.data)"
               style="height:640px;display:block">
</ejs-pdfviewer>
Copied to clipboard
//Method to lock the custom stamp annotation.
public fireAjaxRequestSuccess(event: any, data: any) {
  debugger;
  if (event.action == 'RenderAnnotationComments') {
    for (var i = data.startPageIndex; i < data.endPageIndex; i++) {
      for (
        var j = 0;
        j < data.annotationDetails[i].stampAnnotations.length;
        j++
      ) {
        //Subject becomes null only for custom stamps.
        if (data.annotationDetails[i].stampAnnotations[j].Subject == null) {
          //Iterate the annotations, check if the subject is null, then set the islocked as true.
          data.annotationDetails[i].stampAnnotations[j].IsLocked = true;
        }
      }
    }
  }
}

View sample in GitHub