pdfmake supports PDF encryption through two complementary password types and a granular permissions system. You can require a password to open the file, set a separate administrative password for full access, and control exactly what readers are allowed to do — all from the document definition object.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/bpampuch/pdfmake/llms.txt
Use this file to discover all available pages before exploring further.
User Password
SettinguserPassword encrypts the PDF and requires the reader to enter the correct password before the document can be opened. If the password is wrong or missing, the viewer will refuse to display the file.
Owner Password
TheownerPassword grants full, unrestricted access to the document — including the ability to change permissions, print at high resolution, copy text, and so on. Readers who open the file with the owner password bypass all permission restrictions.
userPassword and administrators use ownerPassword to manage it:
Permissions
Thepermissions object lets you fine-tune what actions are permitted for users who open the file with the userPassword. Each flag defaults to the most restrictive value when the ownerPassword is set.
Controls whether printing is allowed, and at what quality.
'highResolution' permits normal printing; 'lowResolution' allows only degraded (draft-quality) printing.Whether the reader can modify the document content (edit text, move objects, etc.).
Whether the reader can copy text and graphics from the document.
Whether the reader can add or modify annotations (comments, highlights, etc.).
Whether the reader can fill in interactive form fields.
Whether assistive technology (screen readers) can access the document content.
Whether the reader can insert, delete, or rotate pages, or create bookmarks and thumbnail images.
Full Example
The following example is taken directly fromexamples/security.js in the pdfmake source repository. It sets an owner password, allows high-resolution printing, and restricts modification and copying while keeping annotation, form-filling, accessibility, and assembly available.
Permissions only apply to users opening the file with the
userPassword. Anyone who opens the file with the ownerPassword has full access regardless of the permissions object.Access Policies (Node.js)
When running in Node.js, pdfmake can embed remote images, fonts, or other resources referenced by URL or local file path. To prevent unintended network or filesystem access, you should configure access policies before callingcreatePdf.
URL Access Policy
setUrlAccessPolicy(callback) registers a function that is called for every URL pdfmake attempts to fetch. Return true to allow the request and false to block it.
Local File Access Policy
setLocalAccessPolicy(callback) registers a function that is called for every local file path pdfmake attempts to read (for example, font files or local images). Return true to allow access and false to deny it.
setLocalAccessPolicy is only available on the Node.js build (require('pdfmake')). The browser build does not have access to the local filesystem.createPdf calls on that instance.