Password protection
Open encrypted documents with a password your app provides, or ask the user for it with a built-in or custom form.
Basics
passwordPrompt shows a password form when a document is encrypted, and asks again after a wrong password.
The form is labeled, announces an incorrect password as an alert, and marks the field invalid. Without passwordPrompt, an encrypted document reports a PASSWORD_REQUIRED error.
A known password
Pass password when your app already has it; changing it reloads the document.
Customization
renderPasswordPrompt({ incorrect, submit }) replaces the form with your own.
Default texts are labels.passwordPrompt, passwordLabel, passwordSubmit and passwordIncorrect; see Labels and locale and the customization guide.
Advanced / escape hatch
With usePdfDocument, pass password in the options and handle error.code === 'PASSWORD_REQUIRED' or 'INCORRECT_PASSWORD' in your own UI.
Limitations
- The password is held in memory. Anything that controls
password(props, state) can read it. Workaround: clear it from your state after the document opens if that matters in your threat model. - Owner restrictions are not enforced. Permissions such as “no printing” or “no copying” set by the PDF author are not applied by the viewer. Workaround: hide
printanddownloadfrom the toolbar and leavetextLayeroff for such documents.
API
PdfViewerProps— Props for PdfViewer. Every piece of state supports the value / defaultValue / onChange trio.