Open Password-Protected PDFs in JavaScript

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

Try for Free Launch Demo

Setting the Default Document Password

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

PSPDFKit.load({
  password: "secr3t",
  ...,
});
PSPDFKit.load({
  password: "secr3t",
  ...
});

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

Including the Password in the JWT (Server-Backed Only)

To include the password in the JWT used by the Server-Backed mode to authenticate clients, add the password claim to your JWT:

jwt.sign(
  {
    document_id: document_id,
    password: "secr3t"
    // ...
  },
  fs.readFileSync("./jwt.pem"),
  {
    algorithm: "RS256",
    expiresIn: 10 * 365 * 24 * 60 * 60 // 10 yrs
  }
);
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