Open password-protected PDFs in JavaScript
Nutrient Web SDK 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).
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 (Document Engine only)
To include the password in the JWT used by Document Engine 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.
