Skip to content

Commit e31eac7

Browse files
committed
Refactor PDF.js import to use dynamic import.
Switched from static to dynamic import for PDF.js to improve compatibility and possibly reduce initial load time. This change ensures the module is imported only when needed during runtime.
1 parent 04eb54b commit e31eac7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/pdf-to-png.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
*/
44
import { readFileSync } from 'node:fs'
55
import { dirname, join } from 'node:path'
6-
import { getDocument } from 'pdfjs-dist/legacy/build/pdf.mjs'
76

87
const PDFJS_DIR = join(dirname(require.resolve('pdfjs-dist')), '..')
98

109
export async function pdfToPng(
1110
pdf: string | Buffer
1211
): Promise<Buffer[]> {
12+
const { getDocument } = await import('pdfjs-dist/legacy/build/pdf.mjs')
1313

1414
// Load PDF
1515
const data = new Uint8Array(Buffer.isBuffer(pdf) ? pdf : readFileSync(pdf))

0 commit comments

Comments
 (0)