@@ -30,31 +30,32 @@ yarn add unpdf
3030## Usage
3131
3232``` ts
33- import { extractPDFText } from ' unpdf'
33+ import { extractPDFText } from " unpdf" ;
3434
3535// Fetch a PDF file from the web
36- const pdf = await fetch (' https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf' )
37- .then (res => res .arrayBuffer ())
36+ const pdf = await fetch (
37+ " https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" ,
38+ ).then ((res ) => res .arrayBuffer ());
3839
3940// Or load it from the filesystem
40- const pdf = await readFile (' ./dummy.pdf' )
41+ const pdf = await readFile (" ./dummy.pdf" );
4142
4243// Pass the PDF buffer to the relevant method
43- const { totalPages, text } = await extractPDFText (
44- new Uint8Array ( pdf ), { mergePages: true }
45- )
44+ const { totalPages, text } = await extractPDFText (new Uint8Array ( pdf ), {
45+ mergePages: true ,
46+ });
4647```
4748
4849### Use Legacy Or Custom PDF.js Build
4950
5051``` ts
5152// Before using any other methods, define the PDF.js module
52- import { defineUnPDFConfig } from ' unpdf'
53+ import { defineUnPDFConfig } from " unpdf" ;
5354
5455// Use the legacy build
5556defineUnPDFConfig ({
56- pdfjs : () => import (' pdfjs-dist/legacy/build/pdf.js' )
57- })
57+ pdfjs : () => import (" pdfjs-dist/legacy/build/pdf.js" ),
58+ });
5859
5960// Now, you can use the other methods
6061// …
@@ -63,9 +64,9 @@ defineUnPDFConfig({
6364### Access the PDF.js Module
6465
6566``` ts
66- import { getResolvedPDFJS } from ' unpdf'
67+ import { getResolvedPDFJS } from " unpdf" ;
6768
68- const { version } = await getResolvedPDFJS ()
69+ const { version } = await getResolvedPDFJS ();
6970```
7071
7172## Config
@@ -80,7 +81,7 @@ interface UnPDFConfiguration {
8081 * @example
8182 * () => import('pdfjs-dist/legacy/build/pdf.js')
8283 */
83- pdfjs? : () => Promise <typeof PDFJS >
84+ pdfjs? : () => Promise <typeof PDFJS >;
8485}
8586```
8687
@@ -91,47 +92,45 @@ interface UnPDFConfiguration {
9192Define a custom PDF.js module, like the legacy build. Make sure to call this method before using any other methods.
9293
9394``` ts
94- function defineUnPDFConfig(config : UnPDFConfiguration ): Promise <void >
95+ function defineUnPDFConfig(config : UnPDFConfiguration ): Promise <void >;
9596```
9697
9798### ` getResolvedPDFJS `
9899
99100Returns the resolved PDF.js module. If no build is defined, the latest version will be initialized.
100101
101102``` ts
102- function getResolvedPDFJS(): Promise<typeof import(' pdfjs-dist')>
103+ function getResolvedPDFJS(): Promise <typeof import (" pdfjs-dist" )>;
103104```
104105
105106### ` getPDFMeta `
106107
107108``` ts
108- function getPDFMeta(
109- data: BinaryData | PDFDocumentProxy
110- ): Promise<{
111- info: Record<string, any>
112- metadata: Record<string, any>
113- }>
109+ function getPDFMeta(data : BinaryData | PDFDocumentProxy ): Promise <{
110+ info: Record <string , any >;
111+ metadata: Record <string , any >;
112+ }>;
114113```
115114
116115### ` extractPDFText `
117116
118117``` ts
119118function extractPDFText(
120119 data : BinaryData | PDFDocumentProxy ,
121- { mergePages }?: { mergePages?: boolean }
120+ { mergePages }?: { mergePages? : boolean },
122121): Promise <{
123- totalPages: number
124- text: string | string[]
125- }>
122+ totalPages: number ;
123+ text: string | string [];
124+ }>;
126125```
127126
128127### ` getImagesFromPage `
129128
130129``` ts
131130function getImagesFromPage(
132131 data : BinaryData | PDFDocumentProxy ,
133- pageNumber: number
134- ): Promise<ArrayBuffer[]>
132+ pageNumber : number ,
133+ ): Promise <ArrayBuffer []>;
135134```
136135
137136## License
0 commit comments