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.
This commit is contained in:
abdullahalam123
2025-10-24 13:42:09 +05:30
parent e3468e3aaa
commit ba20536436
10 changed files with 234 additions and 68 deletions

View File

@@ -1,5 +1,9 @@
import { showLoader, hideLoader, showAlert } from '../ui.js';
import { downloadFile, initializeQpdf, readFileAsArrayBuffer } from '../utils/helpers.js';
import {
downloadFile,
initializeQpdf,
readFileAsArrayBuffer,
} from '../utils/helpers.js';
import { state } from '../state.js';
export async function encrypt() {
@@ -35,32 +39,24 @@ export async function encrypt() {
showLoader('Encrypting PDF with 256-bit AES...');
const args = [
inputPath,
'--encrypt',
userPassword,
ownerPassword,
'256',
];
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',
'--extract=n',
'--print=none',
'--accessibility=n',
'--annotate=n',
'--assemble=n',
'--form=n',
'--modify-other=n'
);
}
args.push('--', outputPath);
console.log(args);
try {
qpdf.callMain(args);
} catch (qpdfError: any) {
@@ -114,4 +110,4 @@ export async function encrypt() {
console.warn('Failed to cleanup WASM FS:', cleanupError);
}
}
}
}