1
1
import { useState , useEffect , useRef } from 'react' ;
2
- import * as pdfjs from 'pdfjs-dist' ;
2
+ import { GlobalWorkerOptions , getDocument , version } from 'pdfjs-dist' ;
3
3
import type { PDFDocumentProxy , PDFPageProxy } from 'pdfjs-dist' ;
4
4
import type { DocumentInitParameters } from 'pdfjs-dist/types/src/display/api' ;
5
5
@@ -46,7 +46,7 @@ export const usePdf = ({
46
46
page = 1 ,
47
47
cMapUrl,
48
48
cMapPacked,
49
- workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${ pdfjs . version } /pdf.worker.mjs` ,
49
+ workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${ version } /pdf.worker.mjs` ,
50
50
withCredentials = false ,
51
51
} : HookProps ) : HookReturnValues => {
52
52
const [ pdfDocument , setPdfDocument ] = useState < PDFDocumentProxy > ( ) ;
@@ -86,7 +86,7 @@ export const usePdf = ({
86
86
} , [ onPageRenderFail ] ) ;
87
87
88
88
useEffect ( ( ) => {
89
- pdfjs . GlobalWorkerOptions . workerSrc = workerSrc ;
89
+ GlobalWorkerOptions . workerSrc = workerSrc ;
90
90
} , [ workerSrc ] ) ;
91
91
92
92
useEffect ( ( ) => {
@@ -96,7 +96,7 @@ export const usePdf = ({
96
96
config . cMapPacked = cMapPacked ;
97
97
}
98
98
99
- pdfjs . getDocument ( config ) . promise . then (
99
+ getDocument ( config ) . promise . then (
100
100
( loadedPdfDocument ) => {
101
101
setPdfDocument ( loadedPdfDocument ) ;
102
102
@@ -128,7 +128,7 @@ export const usePdf = ({
128
128
if ( ! canvasContext ) {
129
129
return ;
130
130
}
131
-
131
+
132
132
canvasEl . height = viewport . height * window . devicePixelRatio ;
133
133
canvasEl . width = viewport . width * window . devicePixelRatio ;
134
134
0 commit comments