Some test text!

menu

Define user permissions in WebViewer with JavaScript

This JavaScript sample demonstrates how you can apply permissions to users viewing your PDF, DOCX, XLSX, or PPTX document (no other external dependencies required). In this specific example you define how a user interacts with annotations in the PDF viewer. One common use case is removing a user’s ability to add annotation by providing them read-only access. Another example would be defining the types of annotations a user sees on a document – they can see highlighted text from another user but not the sticky notes they added. For other users you can give them the ability to respond to comments or give administrative rights to delete annotations. This sample works on all browsers (including IE10) and mobile devices without using plug-ins. To see an example visit our WebViewer User Permission demo. Learn more about our JavaScript PDF Library.

Get StartedSamplesDownload

To run this sample, get started with a free trial of PDFTron SDK.

JavaScript

HTML

WebViewer({
  path: '../../../lib',
  pdftronServer: 'https://demo.pdftron.com/', // comment this out to do client-side only
  initialDoc: 'https://pdftron.s3.amazonaws.com/downloads/pl/demo-annotated.pdf'
}, document.getElementById('viewer'))
  .then(function(instance) {
    instance.setAnnotationUser('Justin');
    instance.setAdminUser(true);
    instance.openElement('notesPanel');

    document.getElementById('justin').onchange = function() {
      instance.setAnnotationUser('Justin');
      instance.setAdminUser(true);
      instance.setReadOnly(false);
      instance.setToolMode('AnnotationEdit');
    };

    document.getElementById('sally').onchange = function() {
      instance.setAnnotationUser('Sally');
      instance.setAdminUser(false);
      instance.setReadOnly(false);
      instance.setToolMode('AnnotationEdit');
    };

    document.getElementById('brian').onchange = function() {
      instance.setAnnotationUser('Brian');
      instance.setAdminUser(false);
      instance.setReadOnly(true);
      instance.setToolMode('AnnotationEdit');
    };

    document.getElementById('display').onchange = function(e) {
      var currentUser = instance.getAnnotationUser();
      var allAnnotations = instance.annotManager.getAnnotationsList().filter(function(annot) {
        return annot.Listable
      });

      if (e.target.checked) {
        instance.annotManager.showAnnotations(allAnnotations);
      } else {
        var annotationsToHide = allAnnotations.filter(function(annot) {
          return annot.Author !== currentUser
        });
        instance.annotManager.hideAnnotations(annotationsToHide);
      }
    };
  });
close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.