Check if document is password-protected

Q: How can I check and reject if a document is password-protected?

A: This can be done by setting PSPDFKit.Configuration#maxPasswordRetries to 0 and catch when the PSPDFKit.load promise rejects.

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
PSPDFKit.load({ 
  maxPasswordRetries: 0,
  // your configuration
   })
    .then(instance => {
      console.log("PSPDFKit for Web successfully loaded!!", instance);
      return instance;
    })
    .catch(err => {
      if (err.message === "INVALID_PASSWORD") {
        console.log("Attempted to load a password-protected document.");
      }
    });

This has been tested with PSPDFKit for Web 2020.4.2.