Add password prompt functionality and tests while uploading encrypted PDF
This commit is contained in:
@@ -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 = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user