Skip to content

Commit

Permalink
feat: init params for getDocumentProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Aug 13, 2023
1 parent 40981ff commit 9ab22bc
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import type PDFJS from 'pdfjs-dist'
import type { BinaryData, DocumentInitParameters, PDFDocumentProxy } from 'pdfjs-dist/types/src/display/api'
import type { UnPDFConfiguration } from './types'

let resolvedModule: typeof PDFJS | undefined

export async function getDocumentProxy(data: ArrayBuffer) {
/**
* Returns a PDFDocumentProxy instance from a given binary data.
*
* Applies the following defaults:
* - `useWorkerFetch: false`
* - `isEvalSupported: false`
* - `useSystemFonts: true`
*/
export async function getDocumentProxy(data: BinaryData, options: DocumentInitParameters = {}) {
const {
useWorkerFetch = false,
isEvalSupported = false,
useSystemFonts = true,
...rest
} = options

const { getDocument } = await getResolvedPDFJS()
const pdf = await getDocument({
data,
useWorkerFetch: false,
useSystemFonts: true,
isEvalSupported: false,
useWorkerFetch,
useSystemFonts,
isEvalSupported,
...rest,
}).promise

return pdf
Expand Down Expand Up @@ -47,3 +64,7 @@ export async function resolvePDFJSImports() {
throw new Error('PDF.js is not available. Please add the package as a dependency.')
}
}

export function isPDFDocumentProxy(data: unknown): data is PDFDocumentProxy {
return typeof data === 'object' && data !== null && '_pdfInfo' in data
}

0 comments on commit 9ab22bc

Please # to comment.