From e223ec8749975655d1a1e20ce4864edef6229e74 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 21 Jan 2026 08:18:40 -0300 Subject: [PATCH 1/2] fix: prevent load multiple pdf worker when use multiple pdf files Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- src/utils/asyncReader.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/utils/asyncReader.js b/src/utils/asyncReader.js index 26035ee..81b81a7 100644 --- a/src/utils/asyncReader.js +++ b/src/utils/asyncReader.js @@ -1,11 +1,20 @@ // SPDX-FileCopyrightText: 2026 LibreCode coop and contributors // SPDX-License-Identifier: AGPL-3.0-or-later -import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist' +import { getDocument, GlobalWorkerOptions, PDFWorker } from 'pdfjs-dist' import pdfWorkerCode from 'pdfjs-dist/build/pdf.worker.min.mjs' GlobalWorkerOptions.workerSrc = pdfWorkerCode +let sharedWorker = null + +function getSharedWorker() { + if (!sharedWorker) { + sharedWorker = new PDFWorker({ name: 'libresign-pdf-worker' }) + } + return sharedWorker +} + export function setWorkerPath(path) { GlobalWorkerOptions.workerSrc = path } @@ -20,5 +29,16 @@ export function readAsArrayBuffer(file) { } export function readAsPDF(file) { - return getDocument(file).promise + const worker = getSharedWorker() + const isArrayBuffer = file instanceof ArrayBuffer + const isView = ArrayBuffer.isView(file) + const isBlob = typeof Blob !== 'undefined' && file instanceof Blob + + if (file && typeof file === 'object' && !isArrayBuffer && !isView && !isBlob) { + return getDocument({ ...file, worker }).promise + } + if (typeof file === 'string') { + return getDocument({ url: file, worker }).promise + } + return getDocument({ data: file, worker }).promise } From 5a8d88ab32c6919f1a7ae12ef3cc0836a9bd1e1f Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 21 Jan 2026 08:19:12 -0300 Subject: [PATCH 2/2] chore: bump version Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e4fa84b..fce8460 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@libresign/pdf-elements", "description": "PDF viewer with draggable and resizable element overlays for Vue 2", - "version": "0.3.0", + "version": "0.3.1", "author": "LibreCode ", "private": false, "main": "dist/pdf-elements.umd.js",