Getting Started
@manojcoder/pdf-utils is a lightweight, framework-agnostic, browser-compatible, privacy-first PDF manipulation library powered by pdf-lib. It runs 100% locally in the browser, keeping all documents completely secure.
Privacy First: All calculations execute in the browser's RAM memory. No network uploads or server-side data transfers are performed.
Installation
Install the package alongside pdf-lib (peer dependency):
npm install @manojcoder/pdf-utils pdf-lib
Basic Example
Here is how you can import and unlock a password-protected PDF in standard client-side JavaScript or TypeScript:
import { unlockPDF } from "@manojcoder/pdf-utils";
async function handleDecrypt(file: File) {
try {
const password = "my-secure-password";
// Decrypt the file locally
const decryptedBytes = await unlockPDF(file, password);
// Convert output Uint8Array to a Blob for downloading or previewing
const blob = new Blob([decryptedBytes], { type: "application/pdf" });
const downloadUrl = URL.createObjectURL(blob);
// Create an anchor and trigger download
const link = document.createElement("a");
link.href = downloadUrl;
link.download = `unlocked_${file.name}`;
link.click();
} catch (error) {
console.error("Decryption failed:", error);
}
}
Input/Output Types
All utilities in this package consistently accept:
FileBlobArrayBufferUint8Array
And they return a unified Uint8Array which is highly flexible and memory efficient.