Skip to content

Encrypted documents

An encrypted document waits for its password with status "password"; passwordReason says whether one is "required" or the last one was "incorrect". Answer with viewer.submitPassword(password), or submitPassword(null) to give up, which fails the document:

function PasswordPrompt() {
const viewer = usePdfViewer();
const reason = usePdfState((state) => state.passwordReason);
const [password, setPassword] = useState("");
if (!reason) return null;
return (
<form onSubmit={(event) => { event.preventDefault(); viewer.submitPassword(password); }}>
<label>
{reason === "incorrect" ? "Wrong password, try again" : "Password"}
<input type="password" value={password} onChange={(event) => setPassword(event.target.value)} />
</label>
<button type="submit">Open</button>
</form>
);
}

The password is parapdf. Cancel fails the document instead.

A source can carry the password too (see Sources); the viewer asks only when it is wrong. Changing source.password tries the new value on the shared document still loading, even before its password request arrives. This also works with passwordPrompt: false.

An application without such a prompt passes passwordPrompt: false in options: an encrypted document then fails at once with status "error" instead of waiting for a password no one can type.

What an encrypted document permits is in Permissions.