Foxit PDF SDK for Web

How to Set Annotation Flags for Different Users with Foxit PDF SDK for Web

This article aims to demonstrate how to set annotation flags for different users with our Web SDK. Follow the two steps below to perform the function.

We use Foxit PDF SDK to do it and you can get a free 30 day trial here.

Platform: Web

Programming Language: JavaScript

License Key Requirement: Standard

SDK Version: Foxit PDF SDK 8.3

Step 1:

Set annotation flags to lock annotations of other users at the application level:

//Get pdfViewer
const pdfViewer = await pdfui.getPDFViewer();

//Get annotations manager
const annotManager = pdfViewer.getAnnotManager();
const annotFlags = PDFViewCtrl.PDF.annots.constant.Annot_Flags;
//Set annotation flags for PDFViewer
annotManager.setViewerAnnotFlag(annot=>{
//Set custom permissions for different users. As follows:
if (annot.getTitle() === 'Foxit Web') {
return annotFlags.invisible;
}
return 0
})

Step 2:

Set annotation flags at document level with the following code:

//Get current PDF Document
const doc = await pdfui.getCurrentPDFDoc();

//Get first page
const page = await doc.getPageByIndex(0);
const point = page.reverseDevicePoint([50, 400], 1, 0);
//Add square annotation
const square = await page.addAnnot({
type: "square",
rect: {
left: point[0],
top: point[1],
right: point[0] + 100,
bottom: point[1] - 100,
},
})
const annotFlags = PDFViewCtrl.PDF.annots.constant.Annot_Flags;
//Set Annotation flags
await square[0].setFlags(annotFlags.hidden);

Updated on May 17, 2022

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: