feat: enable loading of encrypted PDFs by adding ignoreEncryption option
This commit is contained in:
@@ -139,7 +139,9 @@ async function updateUI() {
|
||||
pageState.file = result.file;
|
||||
showLoader('Loading PDF...');
|
||||
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes);
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
|
||||
const pageCount = pageState.pdfDoc.getPageCount();
|
||||
metaSpan.textContent = `${formatBytes(pageState.file.size)} • ${pageCount} pages`;
|
||||
|
||||
@@ -85,6 +85,7 @@ async function updateUI() {
|
||||
showLoader('Loading PDF...');
|
||||
pageState.file = result.file;
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
result.pdf.destroy();
|
||||
|
||||
@@ -63,7 +63,9 @@ async function handleFiles(files: FileList) {
|
||||
if (!result) return;
|
||||
showLoader('Loading PDF...');
|
||||
result.pdf.destroy();
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes);
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
pageState.file = result.file;
|
||||
updateFileDisplay();
|
||||
document.getElementById('options-panel')?.classList.remove('hidden');
|
||||
|
||||
@@ -184,7 +184,9 @@ async function handleFiles(fileList: FileList) {
|
||||
if (!result) continue;
|
||||
showLoader('Loading PDFs...');
|
||||
result.pdf.destroy();
|
||||
const pdfDoc = await PDFDocument.load(result.bytes);
|
||||
const pdfDoc = await PDFDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
files.push({ file: result.file, pageCount: pdfDoc.getPageCount() });
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ async function updateUI() {
|
||||
result.pdf.destroy();
|
||||
pageState.file = result.file;
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
hideLoader();
|
||||
|
||||
@@ -95,6 +95,7 @@ async function handleFile(file: File) {
|
||||
showLoader('Loading PDF...');
|
||||
deleteState.file = result.file;
|
||||
deleteState.pdfDoc = await PDFDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
deleteState.pdfJsDoc = result.pdf;
|
||||
|
||||
@@ -87,7 +87,9 @@ async function updateUI() {
|
||||
pageState.file = result.file;
|
||||
showLoader('Loading PDF...');
|
||||
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes);
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
pageState.totalPages = pageState.pdfDoc.getPageCount();
|
||||
hideLoader();
|
||||
|
||||
|
||||
@@ -229,6 +229,7 @@ async function updateUI() {
|
||||
result.pdf.destroy();
|
||||
pageState.file = result.file;
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
hideLoader();
|
||||
|
||||
@@ -100,6 +100,7 @@ async function handleFile(file: File) {
|
||||
extractState.file = result.file;
|
||||
result.pdf.destroy();
|
||||
extractState.pdfDoc = await PDFDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
extractState.totalPages = extractState.pdfDoc.getPageCount();
|
||||
|
||||
@@ -3140,7 +3140,9 @@ async function handlePdfUpload(file: File) {
|
||||
if (!result) return;
|
||||
const arrayBuffer = result.bytes;
|
||||
uploadedPdfjsDoc = result.pdf;
|
||||
uploadedPdfDoc = await PDFDocument.load(arrayBuffer);
|
||||
uploadedPdfDoc = await PDFDocument.load(arrayBuffer, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
|
||||
// Check for existing fields and update counter
|
||||
existingFieldNames.clear();
|
||||
|
||||
@@ -68,7 +68,9 @@ async function handleFiles(files: FileList) {
|
||||
if (!result) return;
|
||||
showLoader('Loading PDF...');
|
||||
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes);
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
pageState.file = result.file;
|
||||
result.pdf.destroy();
|
||||
|
||||
|
||||
@@ -70,7 +70,9 @@ async function handleFiles(files: FileList) {
|
||||
if (!result) return;
|
||||
showLoader('Loading PDF...');
|
||||
result.pdf.destroy();
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes);
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
pageState.file = result.file;
|
||||
updateFileDisplay();
|
||||
document.getElementById('options-panel')?.classList.remove('hidden');
|
||||
|
||||
@@ -75,6 +75,7 @@ async function updateUI() {
|
||||
result.pdf.destroy();
|
||||
pageState.file = result.file;
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
hideLoader();
|
||||
|
||||
@@ -177,6 +177,7 @@ async function handleFile(file: File) {
|
||||
showLoader('Loading PDF...');
|
||||
|
||||
organizeState.pdfDoc = await PDFDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
organizeState.pdfJsDoc = result.pdf;
|
||||
|
||||
@@ -341,7 +341,9 @@ async function handleFileSelect(files: FileList | null) {
|
||||
result.pdf.destroy();
|
||||
|
||||
pageState.file = result.file;
|
||||
pageState.pdfDoc = await PDFDocument.load(result.bytes);
|
||||
pageState.pdfDoc = await PDFDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
updateUI();
|
||||
analyzeAndDisplayDimensions();
|
||||
} catch (e) {
|
||||
|
||||
@@ -89,7 +89,9 @@ async function handleFiles(files: FileList) {
|
||||
if (!result) return;
|
||||
showLoader('Loading PDF...');
|
||||
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes);
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
pageState.file = result.file;
|
||||
result.pdf.destroy();
|
||||
|
||||
|
||||
@@ -108,7 +108,9 @@ async function handleFileUpload(file: File) {
|
||||
if (!result) return;
|
||||
showLoader('Loading PDF...');
|
||||
result.pdf.destroy();
|
||||
pageState.pdfDoc = await PDFDocument.load(result.bytes);
|
||||
pageState.pdfDoc = await PDFDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
pageState.file = result.file;
|
||||
updateFileDisplay();
|
||||
document.getElementById('options-panel')?.classList.remove('hidden');
|
||||
|
||||
@@ -122,7 +122,9 @@ async function handleFileUpload(file: File) {
|
||||
if (!result) return;
|
||||
showLoader('Loading PDF...');
|
||||
result.pdf.destroy();
|
||||
pageState.pdfDoc = await PDFDocument.load(result.bytes);
|
||||
pageState.pdfDoc = await PDFDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
pageState.file = result.file;
|
||||
pageState.detectedBlankPages = [];
|
||||
updateFileDisplay();
|
||||
|
||||
@@ -150,7 +150,9 @@ async function removeMetadata() {
|
||||
if (loaderModal) loaderModal.classList.remove('hidden');
|
||||
if (loaderText) loaderText.textContent = 'Removing all metadata...';
|
||||
result.pdf.destroy();
|
||||
const pdfDoc = await PDFDocument.load(result.bytes);
|
||||
const pdfDoc = await PDFDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
|
||||
removeMetadataFromDoc(pdfDoc);
|
||||
|
||||
|
||||
@@ -236,6 +236,7 @@ async function updateUI() {
|
||||
showLoader('Loading PDF...');
|
||||
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
|
||||
|
||||
@@ -208,6 +208,7 @@ async function updateUI() {
|
||||
showLoader('Loading PDF...');
|
||||
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
|
||||
|
||||
@@ -98,7 +98,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
result.pdf.destroy();
|
||||
state.files[0] = result.file;
|
||||
state.pdfDoc = await PDFLibDocument.load(result.bytes);
|
||||
state.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
}
|
||||
// Update page count
|
||||
metaSpan.textContent = `${formatBytes(file.size)} • ${state.pdfDoc.getPageCount()} pages`;
|
||||
@@ -146,7 +148,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
result.pdf.destroy();
|
||||
state.files[0] = result.file;
|
||||
state.pdfDoc = await PDFLibDocument.load(result.bytes);
|
||||
state.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
showLoader('Rendering page previews...');
|
||||
} else {
|
||||
throw new Error('No PDF document loaded');
|
||||
|
||||
@@ -75,7 +75,9 @@ async function handleFiles(files: FileList) {
|
||||
if (!result) return;
|
||||
showLoader('Loading PDF...');
|
||||
result.pdf.destroy();
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes);
|
||||
pageState.pdfDoc = await PDFLibDocument.load(result.bytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
pageState.file = result.file;
|
||||
updateFileDisplay();
|
||||
document.getElementById('options-panel')?.classList.remove('hidden');
|
||||
|
||||
Reference in New Issue
Block a user