From bf61324c1d74d881f2080982f244d8b214b74737 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 4 Sep 2024 11:26:08 +0200 Subject: [PATCH] Signature: multi page viewer - WIP --- .../public/vuejs/DocumentSignature/App.vue | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/DocumentSignature/App.vue b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/DocumentSignature/App.vue index 114c08704..88043673a 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/DocumentSignature/App.vue +++ b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/DocumentSignature/App.vue @@ -75,12 +75,19 @@ -
- +
+ +
+
+
-
@@ -171,6 +178,7 @@ import { pdfjsLib.GlobalWorkerOptions.workerSrc = "pdfjs-dist/build/pdf.worker.mjs"; +const multiPage: Ref = ref(true); const modalOpen: Ref = ref(false); const loading: Ref = ref(false); const adding: Ref = ref(false); @@ -198,13 +206,24 @@ const mountPdf = async (url: string) => { const loadingTask = pdfjsLib.getDocument(url); pdf = await loadingTask.promise; pageCount.value = pdf.numPages; - await setPage(1); + if (multiPage.value) { + await setAllPages(); + } else { + await setPage(1); + } }; const getRenderContext = (pdfPage: PDFPageProxy) => { const scale = 1; const viewport = pdfPage.getViewport({ scale }); - const canvas = document.querySelectorAll("canvas")[0] as HTMLCanvasElement; + let canvas; + if (multiPage.value) { + canvas = document.getElementById( + `canvas-${pdfPage.pageNumber}` + ) as HTMLCanvasElement; + } else { + canvas = document.querySelectorAll("canvas")[0] as HTMLCanvasElement; + } const context = canvas.getContext("2d") as CanvasRenderingContext2D; canvas.height = viewport.height; canvas.width = viewport.width; @@ -215,6 +234,9 @@ const getRenderContext = (pdfPage: PDFPageProxy) => { }; }; +const setAllPages = async () => + Array.from(Array(pageCount.value).keys()).map((p) => setPage(p + 1)); + const setPage = async (page: number) => { const pdfPage = await pdf.getPage(page); const renderContext = getRenderContext(pdfPage); @@ -515,7 +537,7 @@ downloadAndOpen();