diff --git a/frontend/src/utils/thumbnailUtils.ts b/frontend/src/utils/thumbnailUtils.ts index a960b5858..72e1bc392 100644 --- a/frontend/src/utils/thumbnailUtils.ts +++ b/frontend/src/utils/thumbnailUtils.ts @@ -273,6 +273,29 @@ function formatFileSize(bytes: number): string { return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]; } +async function generatePDFThumbnail(arrayBuffer: ArrayBuffer, file: File, scale: number): Promise { + try { + const pdf = await getDocument({ + data: arrayBuffer, + disableAutoFetch: true, + disableStream: true + }).promise; + + const thumbnail = await generateStandardPDFThumbnail(pdf, scale); + + // Immediately clean up memory after thumbnail generation + pdf.destroy(); + return thumbnail; + } catch (error) { + if (error instanceof Error) { + // Check if PDF is encrypted + if (error.name === "PasswordException") { + return generateEncryptedPDFThumbnail(file); + } + } + throw error; // Not an encryption issue, re-throw + } +} /** * Generate thumbnail for any file type @@ -306,51 +329,15 @@ export async function generateThumbnailForFile(file: File): Promise