Update PDF worker paths and remove setup script

This commit is contained in:
Richard Roberson 2025-03-04 17:10:57 -07:00
parent 4e857a75f0
commit d10d4410e2
4 changed files with 5 additions and 118778 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,17 +0,0 @@
import path from 'node:path';
import fs from 'node:fs';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const pdfjsDistPath = path.dirname(require.resolve('pdfjs-dist/package.json'));
const pdfWorkerPath = path.join(pdfjsDistPath, 'build', 'pdf.worker.mjs');
const pdfLegacyWorkerPath = path.join(pdfjsDistPath, 'legacy', 'build', 'pdf.worker.mjs');
// Create public directory if it doesn't exist
if (!fs.existsSync('./public')) {
fs.mkdirSync('./public', { recursive: true });
}
// Copy both modern and legacy workers
fs.cpSync(pdfWorkerPath, './public/pdf.worker.mjs', { recursive: true });
fs.cpSync(pdfLegacyWorkerPath, './public/pdf.legacy.worker.mjs', { recursive: true });

View file

@ -28,12 +28,15 @@ function shouldUseLegacyBuild() {
}
}
// Initialize PDF.js worker
// Function to initialize PDF worker
function initPDFWorker() {
try {
if (typeof window !== 'undefined') {
const useLegacy = shouldUseLegacyBuild();
const workerSrc = useLegacy ? '/pdf.legacy.worker.mjs' : '/pdf.worker.mjs';
// Use local worker file instead of unpkg
const workerSrc = useLegacy
? new URL('pdfjs-dist/legacy/build/pdf.worker.min.mjs', import.meta.url).href
: new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url).href;
console.log('Setting PDF worker to:', workerSrc);
pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;
pdfjs.GlobalWorkerOptions.workerPort = null;