Add password prompt functionality and tests while uploading encrypted PDF
This commit is contained in:
@@ -4,6 +4,7 @@ import * as pdfjsLib from 'pdfjs-dist';
|
||||
import JSZip from 'jszip';
|
||||
import Sortable from 'sortablejs';
|
||||
import { downloadFile, getPDFDocument } from '../utils/helpers';
|
||||
import { loadPdfWithPasswordPrompt } from '../utils/password-prompt.js';
|
||||
import {
|
||||
renderPagesProgressively,
|
||||
cleanupLazyRendering,
|
||||
@@ -428,6 +429,12 @@ async function loadPdfs(files: File[]) {
|
||||
arrayBuffer = await file.arrayBuffer();
|
||||
}
|
||||
|
||||
hideLoading();
|
||||
const pwResult = await loadPdfWithPasswordPrompt(file);
|
||||
if (!pwResult) continue;
|
||||
pwResult.pdf.destroy();
|
||||
arrayBuffer = pwResult.bytes as ArrayBuffer;
|
||||
|
||||
const pdfDoc = await PDFLibDocument.load(arrayBuffer, {
|
||||
ignoreEncryption: true,
|
||||
throwOnInvalidObject: false,
|
||||
@@ -848,15 +855,17 @@ async function handleInsertPdf(e: Event) {
|
||||
if (insertAfterIndex === undefined) return;
|
||||
|
||||
try {
|
||||
const arrayBuffer = await file.arrayBuffer();
|
||||
const pdfDoc = await PDFLibDocument.load(arrayBuffer, {
|
||||
const pwResult = await loadPdfWithPasswordPrompt(file);
|
||||
if (!pwResult) return;
|
||||
pwResult.pdf.destroy();
|
||||
|
||||
const pdfDoc = await PDFLibDocument.load(pwResult.bytes, {
|
||||
ignoreEncryption: true,
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
currentPdfDocs.push(pdfDoc);
|
||||
const pdfIndex = currentPdfDocs.length - 1;
|
||||
|
||||
// Load PDF.js document for rendering
|
||||
const pdfBytes = await pdfDoc.save();
|
||||
const pdfjsDoc = await getPDFDocument({ data: new Uint8Array(pdfBytes) })
|
||||
.promise;
|
||||
|
||||
Reference in New Issue
Block a user