Fix pdfjs lib no-loading in static build. Using classic Service Worker
This commit is contained in:
@ -1,14 +1,5 @@
|
||||
// lib/common/services/pdf.service.js
|
||||
|
||||
let pdfjsLib = null;
|
||||
|
||||
async function getPdfJs() {
|
||||
if (!pdfjsLib) {
|
||||
pdfjsLib = await import('https://mozilla.github.io/pdf.js/build/pdf.mjs');
|
||||
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://mozilla.github.io/pdf.js/build/pdf.worker.mjs';
|
||||
}
|
||||
return pdfjsLib;
|
||||
}
|
||||
import * as pdfjsLib from 'pdfjs-dist';
|
||||
import PdfWorkerCtor from 'pdfjs-dist/build/pdf.worker.min.mjs?worker';
|
||||
|
||||
/**
|
||||
* Загрузка PDF документа
|
||||
@ -16,9 +7,9 @@ async function getPdfJs() {
|
||||
*/
|
||||
export async function loadPdfDocument(file) {
|
||||
try {
|
||||
const lib = await getPdfJs();
|
||||
const arrayBuffer = await file.arrayBuffer();
|
||||
const loadingTask = lib.getDocument({ data: arrayBuffer });
|
||||
const worker = new pdfjsLib.PDFWorker({ port: new PdfWorkerCtor() });
|
||||
const loadingTask = pdfjsLib.getDocument({ data: arrayBuffer, worker });
|
||||
return await loadingTask.promise;
|
||||
} catch (err) {
|
||||
console.error('PDF load error:', err);
|
||||
|
||||
Reference in New Issue
Block a user