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