From f24e611c4e00f8effdf7b83febd9860ac0915c1c Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Fri, 18 Oct 2024 12:05:31 +0800 Subject: [PATCH] Lazy loading of PDF documents (#37) (#38) --- pdf.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pdf.js b/pdf.js index fc224f9..dbde8d9 100644 --- a/pdf.js +++ b/pdf.js @@ -105,9 +105,14 @@ const makeTOCItem = item => ({ }) export const makePDF = async file => { - const data = new Uint8Array(await file.arrayBuffer()) + const transport = new pdfjsLib.PDFDataRangeTransport(file.size, []) + transport.requestDataRange = (begin, end) => { + file.slice(begin, end).arrayBuffer().then(chunk => { + transport.onDataRange(begin, chunk) + }) + } const pdf = await pdfjsLib.getDocument({ - data, + range: transport, cMapUrl: pdfjsPath('cmaps/'), standardFontDataUrl: pdfjsPath('standard_fonts/'), isEvalSupported: false,