Skip to content

Set Annotations Permissions in Web

ComPDFKit for Web supports setting annotation permissions for users.

Admin

After WebViewer has been initialized, the default role is Admin, and the current username is set to Guest. At this point, the user is considered an administrator role and is allowed to edit, delete, and add any annotations. After initialization, the username can be set using setCurrentUser. Additionally, the user role can be set as an administrator by calling promoteUserToAdmin, or revoked by calling demoteUserFromAdmin.

javascript
// Import the JS file of ComPDFKit Demo.
import ComPDFKitViewer from "@compdfkit_pdf_sdk/webviewer";

const viewer = document.getElementById('webviewer');
ComPDFKitViewer.init(..., viewer)
  .then((core) => {
    const docViewer = core.docViewer;
    docViewer.setCurrentUser('Test')
  });

User

When a user is not an administrator, the default username is "Guest". At this point, the username can be set using setCurrentUser. When a user creates an annotation, the current username will be set as the author property of the annotation. If the username matches the author of the annotation, the user can edit and delete those annotations.

javascript
docViewer.setCurrentUser('Test')

Read Only Mode

When the mode is set to readonly, all annotations cannot be created, modified, or deleted, and replies to annotations cannot also be added. The readonly mode can be enabled by calling enableReadOnlyMode, or disabled by calling disableReadOnlyMode. The current readonly mode status can be checked using isReadOnlyModeEnabled.

javascript
// enable readonly
docViewer.enableReadOnlyMode()
// disable readonly
docViewer.disableReadOnlyMode()
// Whether it is in readonly mode
docViewer.isReadOnlyModeEnabled