Password-Protected PDFs

PSPDFKit for Web supports opening and editing password-protected PDFs. Passwords can be included in the JSON Web Token (JWT), supplied when loading the PDF, or entered by the user when accessing the document.

Set the Default Document Password

To supply the password when loading a PDF, set the password via the initial Configuration#password option:

1
2
3
4
PSPDFKit.load({
  password: "secr3t",
  ...,
});
1
2
3
4
PSPDFKit.load({
  password: "secr3t",
  ...
});

Note that setting this property will make loading PDF documents that are not protected by a password fail. As such, be sure to only add it for documents protected by a password.

Include the Password in the JWT (Server Only)

To include the password in the JWT used to authenticate clients, add the password claim to your JWT:

Copy
1
2
3
4
5
6
7
8
9
10
11
12
jwt.sign(
  {
    document_id: document_id,
    password: "secr3t"
    // ...
  },
  fs.readFileSync("./jwt.pem"),
  {
    algorithm: "RS256",
    expiresIn: 10 * 365 * 24 * 60 * 60 // 10 yrs
  }
);
Copy
1
2
3
4
5
6
7
8
9
10
11
12
jwt.sign(
  {
    document_id: document_id,
    password: "secr3t"
    // ...
  },
  fs.readFileSync("./jwt.pem"),
  {
    algorithm: "RS256",
    expiresIn: 10 * 365 * 24 * 60 * 60 // 10 yrs
  }
);

User Enters the Password

If the password is neither included in the JWT or set via the Configuration#password option, the user will be asked to enter the password via a password prompt.

Password Prompt