2024-09-15 18:01:29 -04:00
|
|
|
import * as PDFJS from 'pdfjs-dist'
|
2024-09-14 11:01:15 -04:00
|
|
|
import type { DocumentInitParameters } from 'pdfjs-dist/types/src/display/api'
|
|
|
|
|
|
|
|
export { PDFJS }
|
|
|
|
|
2024-10-09 04:20:06 -04:00
|
|
|
PDFJS.GlobalWorkerOptions.workerPort = new Worker(
|
|
|
|
/* webpackChunkName: "pdf-worker" */
|
|
|
|
new URL('pdfjs-dist/build/pdf.worker.mjs', import.meta.url) // NOTE: .mjs extension
|
|
|
|
)
|
2024-09-14 11:01:15 -04:00
|
|
|
|
|
|
|
export const imageResourcesPath = '/images/pdfjs-dist/'
|
|
|
|
const cMapUrl = '/js/pdfjs-dist/cmaps/'
|
|
|
|
const standardFontDataUrl = '/fonts/pdfjs-dist/'
|
|
|
|
|
|
|
|
const params = new URLSearchParams(window.location.search)
|
|
|
|
const disableFontFace = params.get('disable-font-face') === 'true'
|
|
|
|
const disableStream = process.env.NODE_ENV !== 'test'
|
|
|
|
|
|
|
|
export const loadPdfDocumentFromUrl = (
|
|
|
|
url: string,
|
|
|
|
options: Partial<DocumentInitParameters> = {}
|
|
|
|
) =>
|
|
|
|
PDFJS.getDocument({
|
|
|
|
url,
|
|
|
|
cMapUrl,
|
|
|
|
standardFontDataUrl,
|
|
|
|
disableFontFace,
|
|
|
|
disableAutoFetch: true, // only fetch the data needed for the displayed pages
|
|
|
|
disableStream,
|
|
|
|
isEvalSupported: false,
|
|
|
|
enableXfa: false, // default is false (2021-10-12), but set explicitly to be sure
|
|
|
|
...options,
|
|
|
|
})
|