From 0eee52dedfd161b907ed3fb3dcabfb2d07059d02 Mon Sep 17 00:00:00 2001 From: James Brunton Date: Fri, 15 Aug 2025 17:19:09 +0100 Subject: [PATCH] Refactor thumbnail generation code --- frontend/src/utils/thumbnailUtils.ts | 112 ++++++++++++--------------- 1 file changed, 49 insertions(+), 63 deletions(-) diff --git a/frontend/src/utils/thumbnailUtils.ts b/frontend/src/utils/thumbnailUtils.ts index 8eee201df..a960b5858 100644 --- a/frontend/src/utils/thumbnailUtils.ts +++ b/frontend/src/utils/thumbnailUtils.ts @@ -224,6 +224,25 @@ function drawLargeLockIcon(ctx: CanvasRenderingContext2D, centerX: number, cente ctx.fillRect(keyholeX - 2, keyholeY, 4, 8); } +/** + * Generate standard PDF thumbnail by rendering first page + */ +async function generateStandardPDFThumbnail(pdf: any, scale: number): Promise { + const page = await pdf.getPage(1); + const viewport = page.getViewport({ scale }); + const canvas = document.createElement("canvas"); + canvas.width = viewport.width; + canvas.height = viewport.height; + const context = canvas.getContext("2d"); + + if (!context) { + throw new Error('Could not get canvas context'); + } + + await page.render({ canvasContext: context, viewport }).promise; + return canvas.toDataURL(); +} + /** * Draw extension badge */ @@ -281,98 +300,65 @@ export async function generateThumbnailForFile(file: File): Promise