refactor(pdf): simplify standard font path resolution for pdfjs-dist
Replace dynamic require.resolve lookup with direct path construction to standard_fonts directory under node_modules. Removes use of createRequire and streamlines runtime font path resolution logic for PDF parsing.
This commit is contained in:
parent
1074a60462
commit
bb61d0f502
1 changed files with 1 additions and 6 deletions
|
|
@ -1,17 +1,12 @@
|
|||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { createRequire } from 'node:module';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
let cachedStandardFontDataUrl: string | null = null;
|
||||
|
||||
export function resolvePdfjsStandardFontDataUrl(): string {
|
||||
if (cachedStandardFontDataUrl) return cachedStandardFontDataUrl;
|
||||
|
||||
const pdfjsEntry = require.resolve('pdfjs-dist/legacy/build/pdf.mjs');
|
||||
const pdfjsPackageRoot = path.resolve(path.dirname(pdfjsEntry), '..', '..');
|
||||
const standardFontDir = path.join(pdfjsPackageRoot, 'standard_fonts');
|
||||
const standardFontDir = path.join(process.cwd(), 'node_modules', 'pdfjs-dist', 'standard_fonts');
|
||||
|
||||
if (!fs.existsSync(standardFontDir)) {
|
||||
throw new Error(`pdfjs-dist standard_fonts directory not found at ${standardFontDir}`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue