Compare commits

...
7 Commits
Author SHA1 Message Date
abdullahalam123 f3e7ef25fa Release v1.1.2 2025-10-24 13:42:18 +05:30
abdullahalam123 ba20536436 feat(pdf-tools): add remove-restrictions tool for unlocking pdfs
Implement new feature to remove security restrictions from PDFs including password protection and digital signature limitations. The tool allows users to unlock PDFs they have legitimate access to for editing and printing purposes. Includes UI components, error handling, and legal disclaimer about proper usage.
2025-10-24 13:42:09 +05:30
abdullahalam123 e3468e3aaa refactor(qpdf): move initialization logic to helpers module
Consolidate qpdf initialization code into helpers.ts to avoid duplication
Improve error message for password protected PDFs
Fortify encryption logic by auto-filling owner password when empty
2025-10-24 11:37:15 +05:30
abdullahalam123 e0d3075609 feat(permissions): rewrite pdf permission handling using qpdf-wasm
- Replace PDFKit with qpdf-wasm for more reliable encryption and permission handling
- Improve error handling for password-related cases
- Update UI text and styling for better clarity
- Add support for additional permission controls (page extraction)
- Optimize performance by removing page-by-page rendering
2025-10-24 00:47:39 +05:30
abdullahalam123 466646d15b feat(pdf): implement qpdf-wasm for secure encryption/decryption
- Replace PDFKit with qpdf-wasm for more robust and secure PDF encryption/decryption
- Add support for owner password and granular permission controls
- Improve UI with better security explanations and options
2025-10-24 00:11:18 +05:30
abdullahalam123 be6c15fef2 Release v1.1.1 2025-10-22 21:37:10 +05:30
abdullahalam123 d5a15bce78 remove(simpleanalytics): remove simple analytics for self hosted version
feat(fonts): replace google fonts with self-hosted fontsource packages

Add fontsource packages for all fonts previously loaded from Google Fonts.
Remove google fonts CDN links and update CSS to use local font imports.
This improves privacy by removing external dependencies and tracking.
2025-10-22 21:37:03 +05:30
14 changed files with 749 additions and 320 deletions
-22
View File
@@ -4,28 +4,6 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>BentoPDF - The Privacy First PDF Toolkit</title>
<script
async
src="https://scripts.simpleanalyticscdn.com/latest.js"
></script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.6.1/cropper.min.css"
/>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Dancing+Script:[email protected]&family=Great+Vibes&family=Kalam:wght@300;400;700&family=Lato:ital,wght@0,400;0,700;1,400&family=Merriweather:ital,wght@0,400;0,700;1,400&display=swap"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=Cedarville+Cursive&display=swap"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap"
rel="stylesheet"
/>
<link rel="icon" type="image/png" href="./images/favicon.svg" />
<link href="/src/css/styles.css" rel="stylesheet" />
</head>
+72 -2
View File
@@ -1,14 +1,21 @@
{
"name": "bento-pdf",
"version": "1.0.1",
"version": "1.1.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "bento-pdf",
"version": "1.0.1",
"version": "1.1.1",
"license": "Apache-2.0",
"dependencies": {
"@fontsource/cedarville-cursive": "^5.2.7",
"@fontsource/dancing-script": "^5.2.8",
"@fontsource/dm-sans": "^5.2.8",
"@fontsource/great-vibes": "^5.2.8",
"@fontsource/kalam": "^5.2.8",
"@fontsource/lato": "^5.2.7",
"@fontsource/merriweather": "^5.2.11",
"@neslinesli93/qpdf-wasm": "^0.3.0",
"@tailwindcss/vite": "^4.1.15",
"blob-stream": "^0.1.3",
@@ -2576,6 +2583,69 @@
"node": "^10.12.0 || >=12.0.0"
}
},
"node_modules/@fontsource/cedarville-cursive": {
"version": "5.2.7",
"resolved": "https://registry.npmjs.org/@fontsource/cedarville-cursive/-/cedarville-cursive-5.2.7.tgz",
"integrity": "sha512-G1Wcc8U9MsFV7t4vmxSaWEDVcJj86qbkuS/V27S5UngxkX6CoTpEdvDeGUIKBlF8FoHCDOQxSNZCFuCafRmvUg==",
"license": "OFL-1.1",
"funding": {
"url": "https://github.com/sponsors/ayuhito"
}
},
"node_modules/@fontsource/dancing-script": {
"version": "5.2.8",
"resolved": "https://registry.npmjs.org/@fontsource/dancing-script/-/dancing-script-5.2.8.tgz",
"integrity": "sha512-zHVVgIQ5/rAIM0VVp1QMsqvJm9INHO5/C82E9rHT6NlabjaPTFYn8wl9lT4vPWizfB0TublGQM1999kfdA+XFA==",
"license": "OFL-1.1",
"funding": {
"url": "https://github.com/sponsors/ayuhito"
}
},
"node_modules/@fontsource/dm-sans": {
"version": "5.2.8",
"resolved": "https://registry.npmjs.org/@fontsource/dm-sans/-/dm-sans-5.2.8.tgz",
"integrity": "sha512-tlovG42m9ESG28WiHpLq3F5umAlm64rv0RkqTbYowRn70e9OlRr5a3yTJhrhrY+k5lftR/OFJjPzOLQzk8EfCA==",
"license": "OFL-1.1",
"funding": {
"url": "https://github.com/sponsors/ayuhito"
}
},
"node_modules/@fontsource/great-vibes": {
"version": "5.2.8",
"resolved": "https://registry.npmjs.org/@fontsource/great-vibes/-/great-vibes-5.2.8.tgz",
"integrity": "sha512-/PATz436NGixjNaigierUpv50wfNv2UhAAijcCPkn4ynvl41x66TCLbXVSVfp4pth9gjWnGqgoj0lVIhHapAuw==",
"license": "OFL-1.1",
"funding": {
"url": "https://github.com/sponsors/ayuhito"
}
},
"node_modules/@fontsource/kalam": {
"version": "5.2.8",
"resolved": "https://registry.npmjs.org/@fontsource/kalam/-/kalam-5.2.8.tgz",
"integrity": "sha512-9WDYPX1llS28xRjrqAoz3IOLeaBhCtL3HCtNanYnF1fthFPmSD5aESL6s7C1SJxAlxq/qzTlpIpw4S1W9+q3OA==",
"license": "OFL-1.1",
"funding": {
"url": "https://github.com/sponsors/ayuhito"
}
},
"node_modules/@fontsource/lato": {
"version": "5.2.7",
"resolved": "https://registry.npmjs.org/@fontsource/lato/-/lato-5.2.7.tgz",
"integrity": "sha512-k5mum1ADbDW5cTw1Ett1eQVWeoZ6gq0ct6SFBibEhB4LRxhniChJZTBgd6ph5yBxLkN1fcnsnmicBNA4S/3nbw==",
"license": "OFL-1.1",
"funding": {
"url": "https://github.com/sponsors/ayuhito"
}
},
"node_modules/@fontsource/merriweather": {
"version": "5.2.11",
"resolved": "https://registry.npmjs.org/@fontsource/merriweather/-/merriweather-5.2.11.tgz",
"integrity": "sha512-ZiIMeUh5iT8d73o6xlSF8GKgjV5pgiFrufYc5jZTVAfExtWKqM2vQHnsqXSFMv4ELhAcjt6Vf+5T3oVGXhAizQ==",
"license": "OFL-1.1",
"funding": {
"url": "https://github.com/sponsors/ayuhito"
}
},
"node_modules/@humanwhocodes/config-array": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.5.0.tgz",
+8 -1
View File
@@ -1,7 +1,7 @@
{
"name": "bento-pdf",
"private": true,
"version": "1.1.0",
"version": "1.1.2",
"license": "Apache-2.0",
"type": "module",
"scripts": {
@@ -39,6 +39,13 @@
"vitest": "^3.2.4"
},
"dependencies": {
"@fontsource/cedarville-cursive": "^5.2.7",
"@fontsource/dancing-script": "^5.2.8",
"@fontsource/dm-sans": "^5.2.8",
"@fontsource/great-vibes": "^5.2.8",
"@fontsource/kalam": "^5.2.8",
"@fontsource/lato": "^5.2.7",
"@fontsource/merriweather": "^5.2.11",
"@neslinesli93/qpdf-wasm": "^0.3.0",
"@tailwindcss/vite": "^4.1.15",
"blob-stream": "^0.1.3",
+44
View File
@@ -1,5 +1,49 @@
@import '@fontsource/dm-sans/400.css';
@import '@fontsource/dm-sans/500.css';
@import '@fontsource/dm-sans/600.css';
@import '@fontsource/dm-sans/700.css';
@import '@fontsource/dancing-script/400.css';
@import '@fontsource/great-vibes/400.css';
@import '@fontsource/kalam/300.css';
@import '@fontsource/kalam/400.css';
@import '@fontsource/kalam/700.css';
@import '@fontsource/lato/400.css';
@import '@fontsource/lato/700.css';
@import '@fontsource/lato/400-italic.css';
@import '@fontsource/merriweather/400.css';
@import '@fontsource/merriweather/700.css';
@import '@fontsource/merriweather/400-italic.css';
@import '@fontsource/cedarville-cursive/400.css';
@import 'cropperjs/dist/cropper.css';
@import 'tailwindcss';
@theme {
--font-sans: 'DM Sans', ui-sans-serif, system-ui, sans-serif;
--font-dancing: 'Dancing Script', cursive;
--font-vibes: 'Great Vibes', cursive;
--font-kalam: 'Kalam', cursive;
--font-lato: 'Lato', sans-serif;
--font-merriweather: 'Merriweather', serif;
--font-cedarville: 'Cedarville Cursive', cursive;
}
@layer base {
body {
@apply antialiased;
font-family: var(--font-sans);
}
}
@theme {
--font-sans: 'DM Sans', ui-sans-serif, system-ui;
--font-dancing: 'Dancing Script', cursive;
--font-vibes: 'Great Vibes', cursive;
--font-kalam: 'Kalam', cursive;
--font-lato: 'Lato', sans-serif;
--font-merriweather: 'Merriweather', serif;
--font-cedarville: 'Cedarville Cursive', cursive;
}
html {
scroll-behavior: smooth;
}
+1
View File
@@ -39,6 +39,7 @@ export const singlePdfLoadTools = [
'remove-blank-pages',
'add-attachments',
'sanitize-pdf',
'remove-restrictions',
];
export const simpleTools = [
+9 -2
View File
@@ -401,6 +401,13 @@ export const categories = [
icon: 'ruler',
subtitle: 'Analyze page size, orientation, and units.',
},
{
id: 'remove-restrictions',
name: 'Remove Restrictions',
icon: 'unlink',
subtitle:
'Remove password protection and security restrictions associated with digitally signed PDF files.',
},
],
},
{
@@ -410,7 +417,7 @@ export const categories = [
id: 'encrypt',
name: 'Encrypt PDF',
icon: 'lock',
subtitle: 'Add a password to protect your PDF.',
subtitle: 'Lock your PDF by adding a password.',
},
{
id: 'sanitize-pdf',
@@ -422,7 +429,7 @@ export const categories = [
id: 'decrypt',
name: 'Decrypt PDF',
icon: 'unlock',
subtitle: 'Remove password protection from a PDF.',
subtitle: 'Unlock PDF by removing password protection.',
},
{
id: 'flatten',
+2 -1
View File
@@ -33,7 +33,8 @@ async function handleSinglePdfUpload(toolId, file) {
if (
state.pdfDoc.isEncrypted &&
toolId !== 'decrypt' &&
toolId !== 'change-permissions'
toolId !== 'change-permissions' &&
toolId !== 'remove-restrictions'
) {
showAlert(
'Protected PDF',
+149 -126
View File
@@ -1,146 +1,169 @@
import { showLoader, hideLoader, showAlert } from '../ui.js';
import { downloadFile, readFileAsArrayBuffer } from '../utils/helpers.js';
import {
downloadFile,
initializeQpdf,
readFileAsArrayBuffer,
} from '../utils/helpers.js';
import { state } from '../state.js';
import PDFDocument from 'pdfkit/js/pdfkit.standalone';
import blobStream from 'blob-stream';
import * as pdfjsLib from 'pdfjs-dist';
export async function changePermissions() {
const currentPassword = (
document.getElementById('current-password') as HTMLInputElement
).value;
const newUserPassword = (
document.getElementById('new-user-password') as HTMLInputElement
).value;
const newOwnerPassword = (
document.getElementById('new-owner-password') as HTMLInputElement
).value;
const file = state.files[0];
const currentPassword =
(document.getElementById('current-password') as HTMLInputElement)?.value ||
'';
const newUserPassword =
(document.getElementById('new-user-password') as HTMLInputElement)?.value ||
'';
const newOwnerPassword =
(document.getElementById('new-owner-password') as HTMLInputElement)
?.value || '';
// An owner password is required to enforce any permissions.
if (
!newOwnerPassword &&
(newUserPassword ||
document.querySelectorAll('input[type="checkbox"]:not(:checked)').length >
0)
) {
showAlert(
'Input Required',
'You must set a "New Owner Password" to enforce specific permissions or to set a user password.'
);
return;
}
showLoader('Preparing to process...');
const inputPath = '/input.pdf';
const outputPath = '/output.pdf';
let qpdf: any;
try {
const file = state.files[0];
const pdfData = await readFileAsArrayBuffer(file);
showLoader('Initializing...');
qpdf = await initializeQpdf();
let pdf;
try {
pdf = await pdfjsLib.getDocument({
data: pdfData as ArrayBuffer,
password: currentPassword,
}).promise;
} catch (e) {
// This catch is specific to password errors in pdf.js
if (e.name === 'PasswordException') {
hideLoader();
showAlert(
'Incorrect Password',
'The current password you entered is incorrect.'
);
return;
showLoader('Reading PDF...');
const fileBuffer = await readFileAsArrayBuffer(file);
const uint8Array = new Uint8Array(fileBuffer as ArrayBuffer);
qpdf.FS.writeFile(inputPath, uint8Array);
showLoader('Processing PDF permissions...');
const args = [inputPath];
// Add password if provided
if (currentPassword) {
args.push('--password=' + currentPassword);
}
const shouldEncrypt = newUserPassword || newOwnerPassword;
if (shouldEncrypt) {
const finalUserPassword = newUserPassword;
const finalOwnerPassword = newOwnerPassword;
args.push('--encrypt', finalUserPassword, finalOwnerPassword, '256');
const allowPrinting = (
document.getElementById('allow-printing') as HTMLInputElement
)?.checked;
const allowCopying = (
document.getElementById('allow-copying') as HTMLInputElement
)?.checked;
const allowModifying = (
document.getElementById('allow-modifying') as HTMLInputElement
)?.checked;
const allowAnnotating = (
document.getElementById('allow-annotating') as HTMLInputElement
)?.checked;
const allowFillingForms = (
document.getElementById('allow-filling-forms') as HTMLInputElement
)?.checked;
const allowDocumentAssembly = (
document.getElementById('allow-document-assembly') as HTMLInputElement
)?.checked;
const allowPageExtraction = (
document.getElementById('allow-page-extraction') as HTMLInputElement
)?.checked;
if (finalOwnerPassword) {
if (!allowModifying) args.push('--modify=none');
if (!allowCopying) args.push('--extract=n');
if (!allowPrinting) args.push('--print=none');
if (!allowAnnotating) args.push('--annotate=n');
if (!allowDocumentAssembly) args.push('--assemble=n');
if (!allowFillingForms) args.push('--form=n');
if (!allowPageExtraction) args.push('--extract=n');
// --modify-other is not directly mapped, apply if modifying is disabled
if (!allowModifying) args.push('--modify-other=n');
} else if (finalUserPassword) {
args.push('--allow-insecure');
}
throw e;
} else {
args.push('--decrypt');
}
const numPages = pdf.numPages;
const pageImages = [];
args.push('--', outputPath);
try {
qpdf.callMain(args);
} catch (qpdfError: any) {
console.error('qpdf execution error:', qpdfError);
for (let i = 1; i <= numPages; i++) {
document.getElementById('loader-text').textContent =
`Processing page ${i} of ${numPages}...`;
const page = await pdf.getPage(i);
const viewport = page.getViewport({ scale: 2.0 });
const canvas = document.createElement('canvas');
canvas.height = viewport.height;
canvas.width = viewport.width;
const context = canvas.getContext('2d');
await page.render({ canvasContext: context, viewport: viewport }).promise;
pageImages.push({
data: canvas.toDataURL('image/jpeg', 0.8),
width: viewport.width,
height: viewport.height,
});
const errorMsg = qpdfError.message || '';
if (
errorMsg.includes('invalid password') ||
errorMsg.includes('incorrect password') ||
errorMsg.includes('password')
) {
throw new Error('INVALID_PASSWORD');
}
if (
errorMsg.includes('encrypted') ||
errorMsg.includes('password required')
) {
throw new Error('PASSWORD_REQUIRED');
}
throw new Error('Processing failed: ' + errorMsg || 'Unknown error');
}
document.getElementById('loader-text').textContent =
'Applying new permissions...';
showLoader('Preparing download...');
const outputFile = qpdf.FS.readFile(outputPath, { encoding: 'binary' });
const allowPrinting = (
document.getElementById('allow-printing') as HTMLInputElement
).checked;
const allowCopying = (
document.getElementById('allow-copying') as HTMLInputElement
).checked;
const allowModifying = (
document.getElementById('allow-modifying') as HTMLInputElement
).checked;
const allowAnnotating = (
document.getElementById('allow-annotating') as HTMLInputElement
).checked;
const allowFillingForms = (
document.getElementById('allow-filling-forms') as HTMLInputElement
).checked;
const allowContentAccessibility = (
document.getElementById('allow-content-accessibility') as HTMLInputElement
).checked;
const allowDocumentAssembly = (
document.getElementById('allow-document-assembly') as HTMLInputElement
).checked;
const doc = new PDFDocument({
size: [pageImages[0].width, pageImages[0].height],
pdfVersion: '1.7ext3', // Uses 256-bit AES encryption
// Apply the new, separate user and owner passwords
userPassword: newUserPassword,
ownerPassword: newOwnerPassword,
// Apply all seven permissions from the checkboxes
permissions: {
printing: allowPrinting ? 'highResolution' : false,
modifying: allowModifying,
copying: allowCopying,
annotating: allowAnnotating,
fillingForms: allowFillingForms,
contentAccessibility: allowContentAccessibility,
documentAssembly: allowDocumentAssembly,
},
});
const stream = doc.pipe(blobStream());
for (let i = 0; i < pageImages.length; i++) {
if (i > 0)
doc.addPage({ size: [pageImages[i].width, pageImages[i].height] });
doc.image(pageImages[i].data, 0, 0, {
width: pageImages[i].width,
height: pageImages[i].height,
});
if (!outputFile || outputFile.length === 0) {
throw new Error('Processing resulted in an empty file.');
}
doc.end();
stream.on('finish', function () {
const blob = stream.toBlob('application/pdf');
downloadFile(blob, `permissions-changed-${file.name}`);
hideLoader();
showAlert('Success', 'Permissions changed successfully!');
});
} catch (e) {
console.error(e);
const blob = new Blob([outputFile], { type: 'application/pdf' });
downloadFile(blob, `permissions-changed-${file.name}`);
hideLoader();
showAlert('Error', `An unexpected error occurred: ${e.message}`);
let successMessage = 'PDF permissions changed successfully!';
if (!shouldEncrypt) {
successMessage =
'PDF decrypted successfully! All encryption and restrictions removed.';
}
showAlert('Success', successMessage);
} catch (error: any) {
console.error('Error during PDF permission change:', error);
hideLoader();
if (error.message === 'INVALID_PASSWORD') {
showAlert(
'Incorrect Password',
'The current password you entered is incorrect. Please try again.'
);
} else if (error.message === 'PASSWORD_REQUIRED') {
showAlert(
'Password Required',
'This PDF is password-protected. Please enter the current password to proceed.'
);
} else {
showAlert(
'Processing Failed',
`An error occurred: ${error.message || 'The PDF might be corrupted or password protected.'}`
);
}
} finally {
try {
if (qpdf?.FS) {
try {
qpdf.FS.unlink(inputPath);
} catch (e) {}
try {
qpdf.FS.unlink(outputPath);
} catch (e) {}
}
} catch (cleanupError) {
console.warn('Failed to cleanup WASM FS:', cleanupError);
}
}
}
+85 -59
View File
@@ -1,79 +1,105 @@
import { showLoader, hideLoader, showAlert } from '../ui.js';
import { downloadFile, readFileAsArrayBuffer } from '../utils/helpers.js';
import {
downloadFile,
initializeQpdf,
readFileAsArrayBuffer,
} from '../utils/helpers.js';
import { state } from '../state.js';
import PDFDocument from 'pdfkit/js/pdfkit.standalone';
import blobStream from 'blob-stream';
import * as pdfjsLib from 'pdfjs-dist';
export async function decrypt() {
const file = state.files[0];
// @ts-expect-error TS(2339) FIXME: Property 'value' does not exist on type 'HTMLEleme... Remove this comment to see the full error message
const password = document.getElementById('password-input').value;
if (!password.trim()) {
const password = (
document.getElementById('password-input') as HTMLInputElement
)?.value;
if (!password?.trim()) {
showAlert('Input Required', 'Please enter the PDF password.');
return;
}
const inputPath = '/input.pdf';
const outputPath = '/output.pdf';
let qpdf: any;
try {
showLoader('Preparing to process...');
const pdfData = (await readFileAsArrayBuffer(file)) as ArrayBuffer;
const pdf = await pdfjsLib.getDocument({
data: pdfData,
password: password,
}).promise;
const numPages = pdf.numPages;
const pageImages = [];
showLoader('Initializing decryption...');
qpdf = await initializeQpdf();
for (let i = 1; i <= numPages; i++) {
document.getElementById('loader-text').textContent =
`Processing page ${i} of ${numPages}...`;
const page = await pdf.getPage(i);
const viewport = page.getViewport({ scale: 2.0 });
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
await page.render({
canvasContext: context,
viewport: viewport,
canvas: canvas,
}).promise;
pageImages.push({
data: canvas.toDataURL('image/jpeg', 0.8),
width: viewport.width,
height: viewport.height,
});
showLoader('Reading encrypted PDF...');
const fileBuffer = await readFileAsArrayBuffer(file);
const uint8Array = new Uint8Array(fileBuffer as ArrayBuffer);
qpdf.FS.writeFile(inputPath, uint8Array);
showLoader('Decrypting PDF...');
const args = [inputPath, '--password=' + password, '--decrypt', outputPath];
try {
qpdf.callMain(args);
} catch (qpdfError: any) {
console.error('qpdf execution error:', qpdfError);
if (
qpdfError.message?.includes('invalid password') ||
qpdfError.message?.includes('password')
) {
throw new Error('INVALID_PASSWORD');
}
throw qpdfError;
}
document.getElementById('loader-text').textContent =
'Building unlocked PDF...';
const doc = new PDFDocument({
size: [pageImages[0].width, pageImages[0].height],
});
const stream = doc.pipe(blobStream());
for (let i = 0; i < pageImages.length; i++) {
if (i > 0)
doc.addPage({ size: [pageImages[i].width, pageImages[i].height] });
doc.image(pageImages[i].data, 0, 0, {
width: pageImages[i].width,
height: pageImages[i].height,
});
}
doc.end();
showLoader('Preparing download...');
const outputFile = qpdf.FS.readFile(outputPath, { encoding: 'binary' });
stream.on('finish', function () {
const blob = stream.toBlob('application/pdf');
downloadFile(blob, `unlocked-${file.name}`);
hideLoader();
showAlert('Success', 'Decryption complete! Your download has started.');
});
} catch (error) {
if (!outputFile || outputFile.length === 0) {
throw new Error('Decryption resulted in an empty file.');
}
const blob = new Blob([outputFile], { type: 'application/pdf' });
downloadFile(blob, `unlocked-${file.name}`);
hideLoader();
showAlert(
'Success',
'PDF decrypted successfully! Your download has started.'
);
} catch (error: any) {
console.error('Error during PDF decryption:', error);
hideLoader();
if (error.name === 'PasswordException') {
showAlert('Incorrect Password', 'The password you entered is incorrect.');
if (error.message === 'INVALID_PASSWORD') {
showAlert(
'Incorrect Password',
'The password you entered is incorrect. Please try again.'
);
} else if (error.message?.includes('password')) {
showAlert(
'Password Error',
'Unable to decrypt the PDF with the provided password.'
);
} else {
showAlert('Error', 'An error occurred. The PDF might be corrupted.');
showAlert(
'Decryption Failed',
`An error occurred: ${error.message || 'The password you entered is wrong or the file is corrupted.'}`
);
}
} finally {
try {
if (qpdf?.FS) {
try {
qpdf.FS.unlink(inputPath);
} catch (e) {
console.warn('Failed to unlink input file:', e);
}
try {
qpdf.FS.unlink(outputPath);
} catch (e) {
console.warn('Failed to unlink output file:', e);
}
}
} catch (cleanupError) {
console.warn('Failed to cleanup WASM FS:', cleanupError);
}
}
}
+96 -69
View File
@@ -1,86 +1,113 @@
import { showLoader, hideLoader, showAlert } from '../ui.js';
import { downloadFile, readFileAsArrayBuffer } from '../utils/helpers.js';
import {
downloadFile,
initializeQpdf,
readFileAsArrayBuffer,
} from '../utils/helpers.js';
import { state } from '../state.js';
import PDFDocument from 'pdfkit/js/pdfkit.standalone';
import blobStream from 'blob-stream';
import * as pdfjsLib from 'pdfjs-dist';
export async function encrypt() {
const file = state.files[0];
const password = (
document.getElementById('password-input') as HTMLInputElement
).value;
if (!password.trim()) {
showAlert('Input Required', 'Please enter a password.');
const userPassword =
(document.getElementById('user-password-input') as HTMLInputElement)
?.value || '';
const ownerPasswordInput =
(document.getElementById('owner-password-input') as HTMLInputElement)
?.value || '';
if (!userPassword) {
showAlert('Input Required', 'Please enter a user password.');
return;
}
const ownerPassword = ownerPasswordInput || userPassword;
const hasDistinctOwnerPassword = ownerPasswordInput !== '';
const inputPath = '/input.pdf';
const outputPath = '/output.pdf';
let qpdf: any;
try {
showLoader('Preparing to process...');
const pdfData = await readFileAsArrayBuffer(file);
const pdf = await pdfjsLib.getDocument({ data: pdfData as ArrayBuffer })
.promise;
const numPages = pdf.numPages;
const pageImages = [];
showLoader('Initializing encryption...');
qpdf = await initializeQpdf();
for (let i = 1; i <= numPages; i++) {
document.getElementById('loader-text').textContent =
`Processing page ${i} of ${numPages}...`;
const page = await pdf.getPage(i);
const viewport = page.getViewport({ scale: 2.0 });
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
await page.render({
canvasContext: context,
viewport: viewport,
canvas: canvas,
}).promise;
pageImages.push({
data: canvas.toDataURL('image/jpeg', 0.8),
width: viewport.width,
height: viewport.height,
});
showLoader('Reading PDF...');
const fileBuffer = await readFileAsArrayBuffer(file);
const uint8Array = new Uint8Array(fileBuffer as ArrayBuffer);
qpdf.FS.writeFile(inputPath, uint8Array);
showLoader('Encrypting PDF with 256-bit AES...');
const args = [inputPath, '--encrypt', userPassword, ownerPassword, '256'];
// Only add restrictions if a distinct owner password was provided
if (hasDistinctOwnerPassword) {
args.push(
'--modify=none',
'--extract=n',
'--print=none',
'--accessibility=n',
'--annotate=n',
'--assemble=n',
'--form=n',
'--modify-other=n'
);
}
document.getElementById('loader-text').textContent =
'Encrypting and building PDF...';
const doc = new PDFDocument({
size: [pageImages[0].width, pageImages[0].height],
pdfVersion: '1.7ext3', // Use 256-bit AES encryption
userPassword: password,
ownerPassword: password,
permissions: {
printing: 'highResolution',
modifying: false,
copying: false,
annotating: false,
fillingForms: false,
contentAccessibility: true,
documentAssembly: false,
},
});
const stream = doc.pipe(blobStream());
for (let i = 0; i < pageImages.length; i++) {
if (i > 0)
doc.addPage({ size: [pageImages[i].width, pageImages[i].height] });
doc.image(pageImages[i].data, 0, 0, {
width: pageImages[i].width,
height: pageImages[i].height,
});
}
doc.end();
args.push('--', outputPath);
stream.on('finish', function () {
const blob = stream.toBlob('application/pdf');
downloadFile(blob, `encrypted-${file.name}`);
hideLoader();
showAlert('Success', 'Encryption complete! Your download has started.');
});
} catch (error) {
try {
qpdf.callMain(args);
} catch (qpdfError: any) {
console.error('qpdf execution error:', qpdfError);
throw new Error(
'Encryption failed: ' + (qpdfError.message || 'Unknown error')
);
}
showLoader('Preparing download...');
const outputFile = qpdf.FS.readFile(outputPath, { encoding: 'binary' });
if (!outputFile || outputFile.length === 0) {
throw new Error('Encryption resulted in an empty file.');
}
const blob = new Blob([outputFile], { type: 'application/pdf' });
downloadFile(blob, `encrypted-${file.name}`);
hideLoader();
let successMessage = 'PDF encrypted successfully with 256-bit AES!';
if (!hasDistinctOwnerPassword) {
successMessage +=
' Note: Without a separate owner password, the PDF has no usage restrictions.';
}
showAlert('Success', successMessage);
} catch (error: any) {
console.error('Error during PDF encryption:', error);
hideLoader();
showAlert('Error', 'An error occurred. The PDF might be corrupted.');
showAlert(
'Encryption Failed',
`An error occurred: ${error.message || 'The PDF might be corrupted.'}`
);
} finally {
try {
if (qpdf?.FS) {
try {
qpdf.FS.unlink(inputPath);
} catch (e) {
console.warn('Failed to unlink input file:', e);
}
try {
qpdf.FS.unlink(outputPath);
} catch (e) {
console.warn('Failed to unlink output file:', e);
}
}
} catch (cleanupError) {
console.warn('Failed to cleanup WASM FS:', cleanupError);
}
}
}
+2
View File
@@ -64,12 +64,14 @@ import { alternateMerge, setupAlternateMergeTool } from './alternate-merge.js';
import { linearizePdf } from './linearize.js';
import { addAttachments, setupAddAttachmentsTool } from './add-attachments.js';
import { sanitizePdf } from './sanitize-pdf.js';
import { removeRestrictions } from './remove-restrictions.js';
export const toolLogic = {
merge: { process: merge, setup: setupMergeTool },
split: { process: split, setup: setupSplitTool },
encrypt,
decrypt,
'remove-restrictions': removeRestrictions,
organize,
rotate,
'add-page-numbers': addPageNumbers,
+99
View File
@@ -0,0 +1,99 @@
import { showLoader, hideLoader, showAlert } from '../ui.js';
import {
downloadFile,
initializeQpdf,
readFileAsArrayBuffer,
} from '../utils/helpers.js';
import { state } from '../state.js';
export async function removeRestrictions() {
const file = state.files[0];
const password =
(document.getElementById('owner-password-remove') as HTMLInputElement)
?.value || '';
const inputPath = '/input.pdf';
const outputPath = '/output.pdf';
let qpdf: any;
try {
showLoader('Initializing...');
qpdf = await initializeQpdf();
showLoader('Reading PDF...');
const fileBuffer = await readFileAsArrayBuffer(file);
const uint8Array = new Uint8Array(fileBuffer as ArrayBuffer);
qpdf.FS.writeFile(inputPath, uint8Array);
showLoader('Removing restrictions...');
const args = [inputPath];
if (password) {
args.push(`--password=${password}`);
}
args.push('--decrypt', '--remove-restrictions', '--', outputPath);
try {
qpdf.callMain(args);
} catch (qpdfError: any) {
console.error('qpdf execution error:', qpdfError);
if (
qpdfError.message?.includes('password') ||
qpdfError.message?.includes('encrypt')
) {
throw new Error(
'Failed to remove restrictions. The PDF may require the correct owner password.'
);
}
throw new Error(
'Failed to remove restrictions: ' +
(qpdfError.message || 'Unknown error')
);
}
showLoader('Preparing download...');
const outputFile = qpdf.FS.readFile(outputPath, { encoding: 'binary' });
if (!outputFile || outputFile.length === 0) {
throw new Error('Operation resulted in an empty file.');
}
const blob = new Blob([outputFile], { type: 'application/pdf' });
downloadFile(blob, `unrestricted-${file.name}`);
hideLoader();
showAlert(
'Success',
'PDF restrictions removed successfully! The file is now fully editable and printable.'
);
} catch (error: any) {
console.error('Error during restriction removal:', error);
hideLoader();
showAlert(
'Operation Failed',
`An error occurred: ${error.message || 'The PDF might be corrupted or password-protected.'}`
);
} finally {
try {
if (qpdf?.FS) {
try {
qpdf.FS.unlink(inputPath);
} catch (e) {
console.warn('Failed to unlink input file:', e);
}
try {
qpdf.FS.unlink(outputPath);
} catch (e) {
console.warn('Failed to unlink output file:', e);
}
}
} catch (cleanupError) {
console.warn('Failed to cleanup WASM FS:', cleanupError);
}
}
}
+151 -38
View File
@@ -379,23 +379,73 @@ export const toolTemplates = {
</div>
`,
encrypt: () => `
<h2 class="text-2xl font-bold text-white mb-4">Encrypt PDF</h2>
<p class="mb-6 text-gray-400">Upload a PDF to create a new, password-protected version.</p>
${createFileInputHTML()}
<div id="file-display-area" class="mt-4 space-y-2"></div>
<div id="encrypt-options" class="hidden space-y-4 mt-6">
<div>
<label for="password-input" class="block mb-2 text-sm font-medium text-gray-300">Set Encryption Password</label>
<input type="password" id="password-input" class="w-full bg-gray-700 border border-gray-600 text-white rounded-lg p-2.5" placeholder="Enter a strong password">
</div>
<div class="p-4 bg-gray-900 border border-yellow-500/30 text-yellow-200 rounded-lg">
<h3 class="font-semibold text-base mb-2">Important Note</h3>
<p class="text-sm text-gray-400">To create the secure file, each page is converted into an image. This means you won't be able to select text or click links in the final encrypted PDF.</p>
</div>
<button id="process-btn" class="btn-gradient w-full mt-6">Encrypt & Download</button>
<h2 class="text-2xl font-bold text-white mb-4">Encrypt PDF</h2>
<p class="mb-6 text-gray-400">Add 256-bit AES password protection to your PDF.</p>
${createFileInputHTML()}
<div id="file-display-area" class="mt-4 space-y-2"></div>
<div id="encrypt-options" class="hidden space-y-4 mt-6">
<div>
<label for="user-password-input" class="block mb-2 text-sm font-medium text-gray-300">User Password</label>
<input required type="password" id="user-password-input" class="w-full bg-gray-700 border border-gray-600 text-white rounded-lg p-2.5" placeholder="Password to open the PDF">
<p class="text-xs text-gray-500 mt-1">Required to open and view the PDF</p>
</div>
<div>
<label for="owner-password-input" class="block mb-2 text-sm font-medium text-gray-300">Owner Password (Optional)</label>
<input type="password" id="owner-password-input" class="w-full bg-gray-700 border border-gray-600 text-white rounded-lg p-2.5" placeholder="Password for full permissions (recommended)">
<p class="text-xs text-gray-500 mt-1">Allows changing permissions and removing encryption</p>
</div>
<!-- Restriction checkboxes (shown when owner password is entered) -->
<div id="restriction-options" class="hidden p-4 bg-gray-800 border border-gray-700 rounded-lg">
<h3 class="font-semibold text-base mb-2 text-white">🔒 Restrict PDF Permissions</h3>
<p class="text-sm text-gray-400 mb-3">Select which actions to disable:</p>
<div class="space-y-2">
<label class="flex items-center space-x-2">
<input type="checkbox" id="restrict-modify" checked>
<span>Disable all modifications (--modify=none)</span>
</label>
<label class="flex items-center space-x-2">
<input type="checkbox" id="restrict-extract" checked>
<span>Disable text and image extraction (--extract=n)</span>
</label>
<label class="flex items-center space-x-2">
<input type="checkbox" id="restrict-print" checked>
<span>Disable all printing (--print=none)</span>
</label>
<label class="flex items-center space-x-2">
<input type="checkbox" id="restrict-accessibility">
<span>Disable accessibility text copying (--accessibility=n)</span>
</label>
<label class="flex items-center space-x-2">
<input type="checkbox" id="restrict-annotate">
<span>Disable annotations (--annotate=n)</span>
</label>
<label class="flex items-center space-x-2">
<input type="checkbox" id="restrict-assemble">
<span>Disable page assembly (--assemble=n)</span>
</label>
<label class="flex items-center space-x-2">
<input type="checkbox" id="restrict-form">
<span>Disable form filling (--form=n)</span>
</label>
<label class="flex items-center space-x-2">
<input type="checkbox" id="restrict-modify-other">
<span>Disable other modifications (--modify-other=n)</span>
</label>
</div>
<canvas id="pdf-canvas" class="hidden"></canvas>
`,
</div>
<div class="p-4 bg-yellow-900/20 border border-yellow-500/30 text-yellow-200 rounded-lg">
<h3 class="font-semibold text-base mb-2">⚠️ Security Recommendation</h3>
<p class="text-sm text-gray-300">For strong security, set both passwords. Without an owner password, the security restrictions (printing, copying, etc.) can be easily bypassed.</p>
</div>
<div class="p-4 bg-green-900/20 border border-green-500/30 text-green-200 rounded-lg">
<h3 class="font-semibold text-base mb-2">✓ High-Quality Encryption</h3>
<p class="text-sm text-gray-300">256-bit AES encryption without quality loss. Text remains selectable and searchable.</p>
</div>
<button id="process-btn" class="btn-gradient w-full mt-6">Encrypt & Download</button>
</div>
`,
decrypt: () => `
<h2 class="text-2xl font-bold text-white mb-4">Decrypt PDF</h2>
<p class="mb-6 text-gray-400">Upload an encrypted PDF and provide its password to create an unlocked version.</p>
@@ -865,50 +915,71 @@ export const toolTemplates = {
'change-permissions': () => `
<h2 class="text-2xl font-bold text-white mb-4">Change PDF Permissions</h2>
<p class="mb-6 text-gray-400">Unlock a PDF and re-save it with new passwords and permissions.</p>
<p class="mb-6 text-gray-400">Modify passwords and permissions without losing quality.</p>
${createFileInputHTML()}
<div id="file-display-area" class="mt-4 space-y-2"></div>
<div id="permissions-options" class="hidden mt-6 space-y-4">
<div>
<label for="current-password" class="block mb-2 text-sm font-medium text-gray-300">Current Password (to unlock)</label>
<input type="password" id="current-password" class="w-full bg-gray-700 border border-gray-600 text-white rounded-lg p-2.5" placeholder="Enter current password to open file">
<label for="current-password" class="block mb-2 text-sm font-medium text-gray-300">Current Password (if encrypted)</label>
<input type="password" id="current-password" class="w-full bg-gray-700 border border-gray-600 text-white rounded-lg p-2.5" placeholder="Leave blank if PDF is not password-protected">
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label for="new-user-password" class="block mb-2 text-sm font-medium text-gray-300">New User Password (optional)</label>
<input type="password" id="new-user-password" class="w-full bg-gray-700 border border-gray-600 text-white rounded-lg p-2.5" placeholder="Password to open file">
<input type="password" id="new-user-password" class="w-full bg-gray-700 border border-gray-600 text-white rounded-lg p-2.5" placeholder="Password to open PDF">
</div>
<div>
<label for="new-owner-password" class="block mb-2 text-sm font-medium text-gray-300">New Owner Password (optional)</label>
<input type="password" id="new-owner-password" class="w-full bg-gray-700 border border-gray-600 text-white rounded-lg p-2.5" placeholder="Admin password for permissions">
<input type="password" id="new-owner-password" class="w-full bg-gray-700 border border-gray-600 text-white rounded-lg p-2.5" placeholder="Password for full permissions">
</div>
</div>
<div class="p-4 bg-gray-900 border border-blue-500/30 text-blue-200 rounded-lg">
<h3 class="font-semibold text-base mb-2">How Passwords Work</h3>
<ul class="list-disc list-inside text-sm text-gray-400 space-y-1">
<li>The <strong>User Password</strong> is required to open and decrypt the PDF.</li>
<li>The <strong>Owner Password</strong> is an admin key that bypasses all permissions.</li>
<li>Leave both blank to create an unprotected PDF.</li>
<li>Set an Owner Password to enforce the permissions you select below.</li>
<div class="p-4 bg-blue-900/20 border border-blue-500/30 text-blue-200 rounded-lg">
<h3 class="font-semibold text-base mb-2">How It Works</h3>
<ul class="list-disc list-inside text-sm text-gray-300 space-y-1">
<li><strong>User Password:</strong> Required to open the PDF</li>
<li><strong>Owner Password:</strong> Required to enforce the permissions below</li>
<li>Leave both blank to remove all encryption and restrictions</li>
<li>Check boxes below to ALLOW specific actions (unchecked = disabled)</li>
</ul>
</div>
<fieldset class="border border-gray-600 p-4 rounded-lg">
<legend class="px-2 text-sm font-medium text-gray-300">Allow User to:</legend>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mt-2">
<label class="flex items-center gap-2"><input type="checkbox" id="allow-printing" checked class="checkbox-style"> Print Document</label>
<label class="flex items-center gap-2"><input type="checkbox" id="allow-copying" checked class="checkbox-style"> Copy Content</label>
<label class="flex items-center gap-2"><input type="checkbox" id="allow-modifying" checked class="checkbox-style"> Modify Document</label>
<label class="flex items-center gap-2"><input type="checkbox" id="allow-annotating" checked class="checkbox-style"> Annotate & Comment</label>
<label class="flex items-center gap-2"><input type="checkbox" id="allow-filling-forms" checked class="checkbox-style"> Fill in Forms</label>
<label class="flex items-center gap-2"><input type="checkbox" id="allow-content-accessibility" checked class="checkbox-style"> Enable Content Accessibility</label>
<label class="flex items-center gap-2"><input type="checkbox" id="allow-document-assembly" checked class="checkbox-style"> Assemble Document</label>
<legend class="px-2 text-sm font-medium text-gray-300">Permissions (only enforced with Owner Password):</legend>
<div class="grid grid-cols-1 md:grid-cols-2 gap-3 mt-3">
<label class="flex items-center gap-2 text-gray-300 cursor-pointer hover:text-white">
<input type="checkbox" id="allow-printing" checked class="w-4 h-4 text-blue-600 bg-gray-700 border-gray-600 rounded">
Allow Printing
</label>
<label class="flex items-center gap-2 text-gray-300 cursor-pointer hover:text-white">
<input type="checkbox" id="allow-copying" checked class="w-4 h-4 text-blue-600 bg-gray-700 border-gray-600 rounded">
Allow Text/Image Extraction
</label>
<label class="flex items-center gap-2 text-gray-300 cursor-pointer hover:text-white">
<input type="checkbox" id="allow-modifying" checked class="w-4 h-4 text-blue-600 bg-gray-700 border-gray-600 rounded">
Allow Modifications
</label>
<label class="flex items-center gap-2 text-gray-300 cursor-pointer hover:text-white">
<input type="checkbox" id="allow-annotating" checked class="w-4 h-4 text-blue-600 bg-gray-700 border-gray-600 rounded">
Allow Annotations
</label>
<label class="flex items-center gap-2 text-gray-300 cursor-pointer hover:text-white">
<input type="checkbox" id="allow-filling-forms" checked class="w-4 h-4 text-blue-600 bg-gray-700 border-gray-600 rounded">
Allow Form Filling
</label>
<label class="flex items-center gap-2 text-gray-300 cursor-pointer hover:text-white">
<input type="checkbox" id="allow-document-assembly" checked class="w-4 h-4 text-blue-600 bg-gray-700 border-gray-600 rounded">
Allow Page Assembly
</label>
<label class="flex items-center gap-2 text-gray-300 cursor-pointer hover:text-white">
<input type="checkbox" id="allow-page-extraction" checked class="w-4 h-4 text-blue-600 bg-gray-700 border-gray-600 rounded">
Allow Page Extraction
</label>
</div>
</fieldset>
</div>
<button id="process-btn" class="hidden btn-gradient w-full mt-6">Save New Permissions</button>
<button id="process-btn" class="hidden btn-gradient w-full mt-6">Apply Changes</button>
`,
'pdf-to-markdown': () => `
@@ -1978,4 +2049,46 @@ export const toolTemplates = {
<button id="process-btn" class="btn-gradient w-full mt-6">Sanitize PDF & Download</button>
</div>
`,
'remove-restrictions': () => `
<h2 class="text-2xl font-bold text-white mb-4">Remove PDF Restrictions</h2>
<p class="mb-6 text-gray-400">Remove security restrictions and unlock PDF permissions for editing and printing.</p>
${createFileInputHTML()}
<div id="file-display-area" class="mt-4 space-y-2"></div>
<div id="remove-restrictions-options" class="hidden space-y-4 mt-6">
<div class="p-4 bg-blue-900/20 border border-blue-500/30 text-blue-200 rounded-lg">
<h3 class="font-semibold text-base mb-2"> How it Works </h3>
<p class="text-sm text-gray-300 mb-2">This operation will:</p>
<ul class="text-sm text-gray-300 list-disc list-inside space-y-1 ml-2">
<li>Remove all permission restrictions (printing, copying, editing)</li>
<li>Remove encryption even if the file is encrypted</li>
<li>Remove security restrictions associated with digitally signed PDF files (will make signature invalid)</li>
<li>Create a fully editable, unrestricted PDF</li>
</ul>
</div>
<div>
<label for="owner-password-remove" class="block mb-2 text-sm font-medium text-gray-300">Owner Password (if required)</label>
<input type="password" id="owner-password-remove" class="w-full bg-gray-700 border border-gray-600 text-white rounded-lg p-2.5" placeholder="Leave empty if PDF has no password">
<p class="text-xs text-gray-500 mt-1">Enter the owner password if the PDF is password-protected</p>
</div>
<div class="p-4 bg-red-900/20 border border-red-500/30 text-red-200 rounded-lg">
<h3 class="font-semibold text-base mb-2">Notice</h3>
<p class="text-sm text-gray-300 mb-2">This tool is intended for legitimate purposes only, such as:</p>
<ul class="text-sm text-gray-300 list-disc list-inside space-y-1 ml-2">
<li>Removing restrictions from PDFs you own or have permission to modify</li>
<li>Recovering access to a PDF when you legitimately forgot the password</li>
<li>Accessing content you legally purchased or created</li>
<li>Editing documents for authorized business purposes</li>
<li>Opening documents for legitimate archival, compliance, or recovery workflows</li>
<li class="font-semibold">Limitations: this tool can only remove restrictions from weakly protected PDFs or PDFs that do not have an owner password set. It cannot remove or bypass properly applied AES‑256 (256‑bit) encryption.</li>
</ul>
<p class="text-sm text-gray-300 mt-3 font-semibold">
Using this tool to bypass copyright protections, violate intellectual property rights, or access documents without authorization may be illegal in your jurisdiction. We are not liable for any misuse of this tool — if you're unsure, consult legal counsel or the document owner before proceeding.
</p>
</div>
<button id="process-btn" class="btn-gradient w-full mt-6">Remove Restrictions & Download</button>
</div>
`,
};
+31
View File
@@ -1,3 +1,6 @@
import createModule from '@neslinesli93/qpdf-wasm';
import { showLoader, hideLoader, showAlert } from '../ui';
const STANDARD_SIZES = {
A4: { width: 595.28, height: 841.89 },
Letter: { width: 612, height: 792 },
@@ -146,3 +149,31 @@ export function formatIsoDate(isoDateString) {
return isoDateString; // Return original string on any error
}
}
let qpdfInstance: any = null;
/**
* Initialize qpdf-wasm singleton.
* Subsequent calls return the same instance.
*/
export async function initializeQpdf() {
if (qpdfInstance) return qpdfInstance;
showLoader('Initializing PDF engine...');
try {
qpdfInstance = await createModule({
locateFile: () => '/qpdf.wasm',
});
} catch (error) {
console.error('Failed to initialize qpdf-wasm:', error);
showAlert(
'Initialization Error',
'Could not load the PDF engine. Please refresh the page and try again.'
);
throw error;
} finally {
hideLoader();
}
return qpdfInstance;
}