unpdf 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/index.node.cjs +2 -2
- package/dist/index.node.d.cts +2 -2
- package/dist/index.node.d.mts +2 -2
- package/dist/index.node.d.ts +2 -2
- package/dist/index.node.mjs +3 -3
- package/dist/index.web.cjs +2 -2
- package/dist/index.web.d.cts +2 -2
- package/dist/index.web.d.mts +2 -2
- package/dist/index.web.d.ts +2 -2
- package/dist/index.web.mjs +3 -3
- package/dist/index.worker.cjs +1 -1
- package/dist/index.worker.d.cts +2 -2
- package/dist/index.worker.d.mts +2 -2
- package/dist/index.worker.d.ts +2 -2
- package/dist/index.worker.mjs +1 -1
- package/dist/shared/{unpdf.3a0402b0.d.cts → unpdf.0c92a4fe.d.cts} +13 -5
- package/dist/shared/{unpdf.3a0402b0.d.mts → unpdf.0c92a4fe.d.mts} +13 -5
- package/dist/shared/{unpdf.3a0402b0.d.ts → unpdf.0c92a4fe.d.ts} +13 -5
- package/dist/shared/{unpdf.3a651ae7.cjs → unpdf.6502e2c8.cjs} +4 -4
- package/dist/shared/{unpdf.15eec1ee.cjs → unpdf.9b5cc790.cjs} +15 -4
- package/dist/shared/{unpdf.d5a4740d.mjs → unpdf.e3e60ef4.mjs} +4 -4
- package/dist/shared/{unpdf.9db6f9f8.mjs → unpdf.f801f444.mjs} +15 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ This library is also intended as a modern alternative to the unmaintained but st
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
11
|
- 🏗️ Conditional exports for Browser, Node and worker environments
|
|
12
|
-
- 💬 Extract text from PDFs
|
|
12
|
+
- 💬 Extract text and images from PDFs
|
|
13
13
|
- 🧱 Opt-in to legacy PDF.js build
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
@@ -86,7 +86,7 @@ interface UnPDFConfiguration {
|
|
|
86
86
|
Define a custom PDF.js module, like the legacy build.
|
|
87
87
|
|
|
88
88
|
```ts
|
|
89
|
-
function defineUnPDFConfig(
|
|
89
|
+
function defineUnPDFConfig(config: UnPDFConfiguration): Promise<void>
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
### `getResolvedPDFJS`
|
|
@@ -100,7 +100,9 @@ function getResolvedPDFJS(): Promise<typeof import('pdfjs-dist')>
|
|
|
100
100
|
### `getPDFMeta`
|
|
101
101
|
|
|
102
102
|
```ts
|
|
103
|
-
function getPDFMeta(
|
|
103
|
+
function getPDFMeta(
|
|
104
|
+
data: BinaryData | PDFDocumentProxy
|
|
105
|
+
): Promise<{
|
|
104
106
|
info: Record<string, any>
|
|
105
107
|
metadata: Record<string, any>
|
|
106
108
|
}>
|
|
@@ -110,7 +112,7 @@ function getPDFMeta(data: ArrayBuffer): Promise<{
|
|
|
110
112
|
|
|
111
113
|
```ts
|
|
112
114
|
function extractPDFText(
|
|
113
|
-
data:
|
|
115
|
+
data: BinaryData | PDFDocumentProxy,
|
|
114
116
|
{ mergePages }?: { mergePages?: boolean }
|
|
115
117
|
): Promise<{
|
|
116
118
|
totalPages: number
|
|
@@ -122,7 +124,7 @@ function extractPDFText(
|
|
|
122
124
|
|
|
123
125
|
```ts
|
|
124
126
|
function getImagesFromPage(
|
|
125
|
-
data:
|
|
127
|
+
data: BinaryData | PDFDocumentProxy,
|
|
126
128
|
pageNumber: number
|
|
127
129
|
): Promise<ArrayBuffer[]>
|
|
128
130
|
```
|
package/dist/index.node.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const image = require('./shared/unpdf.
|
|
4
|
-
const utils = require('./shared/unpdf.
|
|
3
|
+
const image = require('./shared/unpdf.6502e2c8.cjs');
|
|
4
|
+
const utils = require('./shared/unpdf.9b5cc790.cjs');
|
|
5
5
|
|
|
6
6
|
const getPDFMeta = async (...args) => {
|
|
7
7
|
await utils.resolvePDFJSImports();
|
package/dist/index.node.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.
|
|
2
|
-
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.0c92a4fe.cjs';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.0c92a4fe.cjs';
|
|
3
3
|
import 'pdfjs-dist/types/src/display/api';
|
|
4
4
|
import 'pdfjs-dist';
|
|
5
5
|
|
package/dist/index.node.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.
|
|
2
|
-
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.0c92a4fe.mjs';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.0c92a4fe.mjs';
|
|
3
3
|
import 'pdfjs-dist/types/src/display/api';
|
|
4
4
|
import 'pdfjs-dist';
|
|
5
5
|
|
package/dist/index.node.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.
|
|
2
|
-
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.0c92a4fe.js';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.0c92a4fe.js';
|
|
3
3
|
import 'pdfjs-dist/types/src/display/api';
|
|
4
4
|
import 'pdfjs-dist';
|
|
5
5
|
|
package/dist/index.node.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.
|
|
2
|
-
import { r as resolvePDFJSImports } from './shared/unpdf.
|
|
3
|
-
export { d as defineUnPDFConfig, g as getDocumentProxy, a as getResolvedPDFJS } from './shared/unpdf.
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.e3e60ef4.mjs';
|
|
2
|
+
import { r as resolvePDFJSImports } from './shared/unpdf.f801f444.mjs';
|
|
3
|
+
export { d as defineUnPDFConfig, g as getDocumentProxy, a as getResolvedPDFJS } from './shared/unpdf.f801f444.mjs';
|
|
4
4
|
|
|
5
5
|
const getPDFMeta = async (...args) => {
|
|
6
6
|
await resolvePDFJSImports();
|
package/dist/index.web.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const image = require('./shared/unpdf.
|
|
4
|
-
const utils = require('./shared/unpdf.
|
|
3
|
+
const image = require('./shared/unpdf.6502e2c8.cjs');
|
|
4
|
+
const utils = require('./shared/unpdf.9b5cc790.cjs');
|
|
5
5
|
|
|
6
6
|
const getPDFMeta = async (...args) => {
|
|
7
7
|
await utils.resolvePDFJSImports();
|
package/dist/index.web.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.
|
|
2
|
-
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.0c92a4fe.cjs';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.0c92a4fe.cjs';
|
|
3
3
|
import 'pdfjs-dist/types/src/display/api';
|
|
4
4
|
import 'pdfjs-dist';
|
|
5
5
|
|
package/dist/index.web.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.
|
|
2
|
-
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.0c92a4fe.mjs';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.0c92a4fe.mjs';
|
|
3
3
|
import 'pdfjs-dist/types/src/display/api';
|
|
4
4
|
import 'pdfjs-dist';
|
|
5
5
|
|
package/dist/index.web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.
|
|
2
|
-
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.0c92a4fe.js';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.0c92a4fe.js';
|
|
3
3
|
import 'pdfjs-dist/types/src/display/api';
|
|
4
4
|
import 'pdfjs-dist';
|
|
5
5
|
|
package/dist/index.web.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.
|
|
2
|
-
import { r as resolvePDFJSImports } from './shared/unpdf.
|
|
3
|
-
export { d as defineUnPDFConfig, g as getDocumentProxy, a as getResolvedPDFJS } from './shared/unpdf.
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.e3e60ef4.mjs';
|
|
2
|
+
import { r as resolvePDFJSImports } from './shared/unpdf.f801f444.mjs';
|
|
3
|
+
export { d as defineUnPDFConfig, g as getDocumentProxy, a as getResolvedPDFJS } from './shared/unpdf.f801f444.mjs';
|
|
4
4
|
|
|
5
5
|
const getPDFMeta = async (...args) => {
|
|
6
6
|
await resolvePDFJSImports();
|
package/dist/index.worker.cjs
CHANGED
package/dist/index.worker.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.
|
|
2
|
-
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.0c92a4fe.cjs';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.0c92a4fe.cjs';
|
|
3
3
|
import 'pdfjs-dist/types/src/display/api';
|
|
4
4
|
import 'pdfjs-dist';
|
|
5
5
|
|
package/dist/index.worker.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.
|
|
2
|
-
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.0c92a4fe.mjs';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.0c92a4fe.mjs';
|
|
3
3
|
import 'pdfjs-dist/types/src/display/api';
|
|
4
4
|
import 'pdfjs-dist';
|
|
5
5
|
|
package/dist/index.worker.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.
|
|
2
|
-
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.0c92a4fe.js';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.0c92a4fe.js';
|
|
3
3
|
import 'pdfjs-dist/types/src/display/api';
|
|
4
4
|
import 'pdfjs-dist';
|
|
5
5
|
|
package/dist/index.worker.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as defineUnPDFConfig, g as getDocumentProxy, a as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.
|
|
1
|
+
export { d as defineUnPDFConfig, g as getDocumentProxy, a as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.f801f444.mjs';
|
|
2
2
|
|
|
3
3
|
const getPDFMeta = async () => {
|
|
4
4
|
throw new Error("Not implemented in worker context yet");
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BinaryData, PDFDocumentProxy, DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
|
|
2
2
|
import PDFJS from 'pdfjs-dist';
|
|
3
3
|
|
|
4
|
-
declare function getPDFMeta(data:
|
|
4
|
+
declare function getPDFMeta(data: BinaryData | PDFDocumentProxy): Promise<{
|
|
5
5
|
info: Record<string, any>;
|
|
6
6
|
metadata: Record<string, any>;
|
|
7
7
|
}>;
|
|
8
8
|
|
|
9
|
-
declare function extractPDFText(data:
|
|
9
|
+
declare function extractPDFText(data: BinaryData | PDFDocumentProxy, { mergePages }?: {
|
|
10
10
|
mergePages?: boolean;
|
|
11
11
|
}): Promise<{
|
|
12
12
|
totalPages: number;
|
|
13
13
|
text: string | string[];
|
|
14
14
|
}>;
|
|
15
15
|
|
|
16
|
-
declare function getImagesFromPage(data:
|
|
16
|
+
declare function getImagesFromPage(data: BinaryData | PDFDocumentProxy, pageNumber: number): Promise<ArrayBuffer[]>;
|
|
17
17
|
|
|
18
18
|
interface UnPDFConfiguration {
|
|
19
19
|
/**
|
|
@@ -27,7 +27,15 @@ interface UnPDFConfiguration {
|
|
|
27
27
|
pdfjs?: () => Promise<typeof PDFJS>;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Returns a PDFDocumentProxy instance from a given binary data.
|
|
32
|
+
*
|
|
33
|
+
* Applies the following defaults:
|
|
34
|
+
* - `useWorkerFetch: false`
|
|
35
|
+
* - `isEvalSupported: false`
|
|
36
|
+
* - `useSystemFonts: true`
|
|
37
|
+
*/
|
|
38
|
+
declare function getDocumentProxy(data: BinaryData, options?: DocumentInitParameters): Promise<PDFDocumentProxy>;
|
|
31
39
|
declare function defineUnPDFConfig({ pdfjs }: UnPDFConfiguration): Promise<void>;
|
|
32
40
|
declare function getResolvedPDFJS(): Promise<typeof PDFJS>;
|
|
33
41
|
declare function resolvePDFJSImports(): Promise<void>;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BinaryData, PDFDocumentProxy, DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
|
|
2
2
|
import PDFJS from 'pdfjs-dist';
|
|
3
3
|
|
|
4
|
-
declare function getPDFMeta(data:
|
|
4
|
+
declare function getPDFMeta(data: BinaryData | PDFDocumentProxy): Promise<{
|
|
5
5
|
info: Record<string, any>;
|
|
6
6
|
metadata: Record<string, any>;
|
|
7
7
|
}>;
|
|
8
8
|
|
|
9
|
-
declare function extractPDFText(data:
|
|
9
|
+
declare function extractPDFText(data: BinaryData | PDFDocumentProxy, { mergePages }?: {
|
|
10
10
|
mergePages?: boolean;
|
|
11
11
|
}): Promise<{
|
|
12
12
|
totalPages: number;
|
|
13
13
|
text: string | string[];
|
|
14
14
|
}>;
|
|
15
15
|
|
|
16
|
-
declare function getImagesFromPage(data:
|
|
16
|
+
declare function getImagesFromPage(data: BinaryData | PDFDocumentProxy, pageNumber: number): Promise<ArrayBuffer[]>;
|
|
17
17
|
|
|
18
18
|
interface UnPDFConfiguration {
|
|
19
19
|
/**
|
|
@@ -27,7 +27,15 @@ interface UnPDFConfiguration {
|
|
|
27
27
|
pdfjs?: () => Promise<typeof PDFJS>;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Returns a PDFDocumentProxy instance from a given binary data.
|
|
32
|
+
*
|
|
33
|
+
* Applies the following defaults:
|
|
34
|
+
* - `useWorkerFetch: false`
|
|
35
|
+
* - `isEvalSupported: false`
|
|
36
|
+
* - `useSystemFonts: true`
|
|
37
|
+
*/
|
|
38
|
+
declare function getDocumentProxy(data: BinaryData, options?: DocumentInitParameters): Promise<PDFDocumentProxy>;
|
|
31
39
|
declare function defineUnPDFConfig({ pdfjs }: UnPDFConfiguration): Promise<void>;
|
|
32
40
|
declare function getResolvedPDFJS(): Promise<typeof PDFJS>;
|
|
33
41
|
declare function resolvePDFJSImports(): Promise<void>;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BinaryData, PDFDocumentProxy, DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
|
|
2
2
|
import PDFJS from 'pdfjs-dist';
|
|
3
3
|
|
|
4
|
-
declare function getPDFMeta(data:
|
|
4
|
+
declare function getPDFMeta(data: BinaryData | PDFDocumentProxy): Promise<{
|
|
5
5
|
info: Record<string, any>;
|
|
6
6
|
metadata: Record<string, any>;
|
|
7
7
|
}>;
|
|
8
8
|
|
|
9
|
-
declare function extractPDFText(data:
|
|
9
|
+
declare function extractPDFText(data: BinaryData | PDFDocumentProxy, { mergePages }?: {
|
|
10
10
|
mergePages?: boolean;
|
|
11
11
|
}): Promise<{
|
|
12
12
|
totalPages: number;
|
|
13
13
|
text: string | string[];
|
|
14
14
|
}>;
|
|
15
15
|
|
|
16
|
-
declare function getImagesFromPage(data:
|
|
16
|
+
declare function getImagesFromPage(data: BinaryData | PDFDocumentProxy, pageNumber: number): Promise<ArrayBuffer[]>;
|
|
17
17
|
|
|
18
18
|
interface UnPDFConfiguration {
|
|
19
19
|
/**
|
|
@@ -27,7 +27,15 @@ interface UnPDFConfiguration {
|
|
|
27
27
|
pdfjs?: () => Promise<typeof PDFJS>;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Returns a PDFDocumentProxy instance from a given binary data.
|
|
32
|
+
*
|
|
33
|
+
* Applies the following defaults:
|
|
34
|
+
* - `useWorkerFetch: false`
|
|
35
|
+
* - `isEvalSupported: false`
|
|
36
|
+
* - `useSystemFonts: true`
|
|
37
|
+
*/
|
|
38
|
+
declare function getDocumentProxy(data: BinaryData, options?: DocumentInitParameters): Promise<PDFDocumentProxy>;
|
|
31
39
|
declare function defineUnPDFConfig({ pdfjs }: UnPDFConfiguration): Promise<void>;
|
|
32
40
|
declare function getResolvedPDFJS(): Promise<typeof PDFJS>;
|
|
33
41
|
declare function resolvePDFJSImports(): Promise<void>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const utils = require('./unpdf.
|
|
3
|
+
const utils = require('./unpdf.9b5cc790.cjs');
|
|
4
4
|
|
|
5
5
|
async function getPDFMeta(data) {
|
|
6
|
-
const pdf = await utils.getDocumentProxy(data);
|
|
6
|
+
const pdf = utils.isPDFDocumentProxy(data) ? data : await utils.getDocumentProxy(data);
|
|
7
7
|
const meta = await pdf.getMetadata().catch(() => null);
|
|
8
8
|
return {
|
|
9
9
|
info: meta?.info ?? {},
|
|
@@ -12,7 +12,7 @@ async function getPDFMeta(data) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
async function extractPDFText(data, { mergePages = false } = {}) {
|
|
15
|
-
const pdf = await utils.getDocumentProxy(data);
|
|
15
|
+
const pdf = utils.isPDFDocumentProxy(data) ? data : await utils.getDocumentProxy(data);
|
|
16
16
|
const texts = await Promise.all(
|
|
17
17
|
Array.from({ length: pdf.numPages }, (_, i) => getPageText(pdf, i + 1))
|
|
18
18
|
);
|
|
@@ -32,7 +32,7 @@ async function getPageText(pdf, pageNumber) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
async function getImagesFromPage(data, pageNumber) {
|
|
35
|
-
const pdf = await utils.getDocumentProxy(data);
|
|
35
|
+
const pdf = utils.isPDFDocumentProxy(data) ? data : await utils.getDocumentProxy(data);
|
|
36
36
|
const page = await pdf.getPage(pageNumber);
|
|
37
37
|
const operatorList = await page.getOperatorList();
|
|
38
38
|
const { OPS } = await utils.getResolvedPDFJS();
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
let resolvedModule;
|
|
4
|
-
async function getDocumentProxy(data) {
|
|
4
|
+
async function getDocumentProxy(data, options = {}) {
|
|
5
|
+
const {
|
|
6
|
+
useWorkerFetch = false,
|
|
7
|
+
isEvalSupported = false,
|
|
8
|
+
useSystemFonts = true,
|
|
9
|
+
...rest
|
|
10
|
+
} = options;
|
|
5
11
|
const { getDocument } = await getResolvedPDFJS();
|
|
6
12
|
const pdf = await getDocument({
|
|
7
13
|
data,
|
|
8
|
-
useWorkerFetch
|
|
9
|
-
useSystemFonts
|
|
10
|
-
isEvalSupported
|
|
14
|
+
useWorkerFetch,
|
|
15
|
+
useSystemFonts,
|
|
16
|
+
isEvalSupported,
|
|
17
|
+
...rest
|
|
11
18
|
}).promise;
|
|
12
19
|
return pdf;
|
|
13
20
|
}
|
|
@@ -36,8 +43,12 @@ async function resolvePDFJSImports() {
|
|
|
36
43
|
throw new Error("PDF.js is not available. Please add the package as a dependency.");
|
|
37
44
|
}
|
|
38
45
|
}
|
|
46
|
+
function isPDFDocumentProxy(data) {
|
|
47
|
+
return typeof data === "object" && data !== null && "_pdfInfo" in data;
|
|
48
|
+
}
|
|
39
49
|
|
|
40
50
|
exports.defineUnPDFConfig = defineUnPDFConfig;
|
|
41
51
|
exports.getDocumentProxy = getDocumentProxy;
|
|
42
52
|
exports.getResolvedPDFJS = getResolvedPDFJS;
|
|
53
|
+
exports.isPDFDocumentProxy = isPDFDocumentProxy;
|
|
43
54
|
exports.resolvePDFJSImports = resolvePDFJSImports;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { g as getDocumentProxy, a as getResolvedPDFJS } from './unpdf.
|
|
1
|
+
import { i as isPDFDocumentProxy, g as getDocumentProxy, a as getResolvedPDFJS } from './unpdf.f801f444.mjs';
|
|
2
2
|
|
|
3
3
|
async function getPDFMeta(data) {
|
|
4
|
-
const pdf = await getDocumentProxy(data);
|
|
4
|
+
const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
|
|
5
5
|
const meta = await pdf.getMetadata().catch(() => null);
|
|
6
6
|
return {
|
|
7
7
|
info: meta?.info ?? {},
|
|
@@ -10,7 +10,7 @@ async function getPDFMeta(data) {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async function extractPDFText(data, { mergePages = false } = {}) {
|
|
13
|
-
const pdf = await getDocumentProxy(data);
|
|
13
|
+
const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
|
|
14
14
|
const texts = await Promise.all(
|
|
15
15
|
Array.from({ length: pdf.numPages }, (_, i) => getPageText(pdf, i + 1))
|
|
16
16
|
);
|
|
@@ -30,7 +30,7 @@ async function getPageText(pdf, pageNumber) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
async function getImagesFromPage(data, pageNumber) {
|
|
33
|
-
const pdf = await getDocumentProxy(data);
|
|
33
|
+
const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
|
|
34
34
|
const page = await pdf.getPage(pageNumber);
|
|
35
35
|
const operatorList = await page.getOperatorList();
|
|
36
36
|
const { OPS } = await getResolvedPDFJS();
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
let resolvedModule;
|
|
2
|
-
async function getDocumentProxy(data) {
|
|
2
|
+
async function getDocumentProxy(data, options = {}) {
|
|
3
|
+
const {
|
|
4
|
+
useWorkerFetch = false,
|
|
5
|
+
isEvalSupported = false,
|
|
6
|
+
useSystemFonts = true,
|
|
7
|
+
...rest
|
|
8
|
+
} = options;
|
|
3
9
|
const { getDocument } = await getResolvedPDFJS();
|
|
4
10
|
const pdf = await getDocument({
|
|
5
11
|
data,
|
|
6
|
-
useWorkerFetch
|
|
7
|
-
useSystemFonts
|
|
8
|
-
isEvalSupported
|
|
12
|
+
useWorkerFetch,
|
|
13
|
+
useSystemFonts,
|
|
14
|
+
isEvalSupported,
|
|
15
|
+
...rest
|
|
9
16
|
}).promise;
|
|
10
17
|
return pdf;
|
|
11
18
|
}
|
|
@@ -34,5 +41,8 @@ async function resolvePDFJSImports() {
|
|
|
34
41
|
throw new Error("PDF.js is not available. Please add the package as a dependency.");
|
|
35
42
|
}
|
|
36
43
|
}
|
|
44
|
+
function isPDFDocumentProxy(data) {
|
|
45
|
+
return typeof data === "object" && data !== null && "_pdfInfo" in data;
|
|
46
|
+
}
|
|
37
47
|
|
|
38
|
-
export { getResolvedPDFJS as a, defineUnPDFConfig as d, getDocumentProxy as g, resolvePDFJSImports as r };
|
|
48
|
+
export { getResolvedPDFJS as a, defineUnPDFConfig as d, getDocumentProxy as g, isPDFDocumentProxy as i, resolvePDFJSImports as r };
|
package/package.json
CHANGED