Add password prompt functionality and tests while uploading encrypted PDF

This commit is contained in:
alam00000
2026-03-26 12:11:12 +05:30
parent f88f872162
commit 1dbf907eeb
79 changed files with 7869 additions and 4419 deletions

View File

@@ -29,6 +29,7 @@ type PdfViewerWindow = Window & {
import { initializeGlobalShortcuts } from '../utils/shortcuts-init.js';
import { downloadFile, hexToRgb, getPDFDocument } from '../utils/helpers.js';
import { loadPdfWithPasswordPrompt } from '../utils/password-prompt.js';
import { createIcons, icons } from 'lucide';
import * as pdfjsLib from 'pdfjs-dist';
import type { PDFDocumentProxy } from 'pdfjs-dist';
@@ -3135,7 +3136,10 @@ function extractExistingFields(pdfDoc: PDFDocument): void {
async function handlePdfUpload(file: File) {
try {
const arrayBuffer = await file.arrayBuffer();
const result = await loadPdfWithPasswordPrompt(file);
if (!result) return;
const arrayBuffer = result.bytes;
uploadedPdfjsDoc = result.pdf;
uploadedPdfDoc = await PDFDocument.load(arrayBuffer);
// Check for existing fields and update counter
@@ -3173,8 +3177,6 @@ async function handlePdfUpload(file: File) {
console.log('No form fields found or error reading fields:', e);
}
uploadedPdfjsDoc = await getPDFDocument({ data: arrayBuffer }).promise;
const pageCount = uploadedPdfDoc.getPageCount();
pages = [];