Unlock PDF Utility
The unlockPDF function allows you to decrypt a password-protected PDF file and save a copy without passwords or usage restrictions.
API Signature
function unlockPDF(
file: File | Blob | ArrayBuffer | Uint8Array,
password?: string
): Promise<Uint8Array>
Parameters
file: The input PDF file or buffer.password: The current decryption password.
Code Example
import { unlockPDF } from "@manojcoder/pdf-utils";
async function performDecrypt(file: File, userKey: string) {
try {
// Decrypt the file client-side
const decryptedBytes = await unlockPDF(file, userKey);
// Save to a local Blob
const blob = new Blob([decryptedBytes], { type: "application/pdf" });
const url = URL.createObjectURL(blob);
console.log("Decrypted PDF URL:", url);
} catch (error) {
console.error("Decryption failed. Ensure the password is correct.", error);
}
}
Notice: This tool runs completely locally. Passwords and credentials never leave your browser RAM, satisfying strict enterprise security standards.