unpdf 0.4.1 → 0.5.1
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 +58 -19
- package/dist/index.node.cjs +13 -5
- package/dist/index.node.d.cts +6 -4
- package/dist/index.node.d.mts +6 -4
- package/dist/index.node.d.ts +6 -4
- package/dist/index.node.mjs +10 -6
- package/dist/index.web.cjs +13 -5
- package/dist/index.web.d.cts +6 -4
- package/dist/index.web.d.mts +6 -4
- package/dist/index.web.d.ts +6 -4
- package/dist/index.web.mjs +10 -6
- package/dist/index.worker.cjs +10 -3
- package/dist/index.worker.d.cts +6 -4
- package/dist/index.worker.d.mts +6 -4
- package/dist/index.worker.d.ts +6 -4
- package/dist/index.worker.mjs +6 -3
- package/dist/shared/{unpdf.54007d6f.cjs → unpdf.15eec1ee.cjs} +4 -2
- package/dist/shared/unpdf.3a0402b0.d.cts +35 -0
- package/dist/shared/unpdf.3a0402b0.d.mts +35 -0
- package/dist/shared/unpdf.3a0402b0.d.ts +35 -0
- package/dist/shared/{unpdf.ff73f2a9.cjs → unpdf.3a651ae7.cjs} +13 -6
- package/dist/shared/{unpdf.5b4a24ed.mjs → unpdf.9db6f9f8.mjs} +4 -2
- package/dist/shared/{unpdf.0f3aa1eb.mjs → unpdf.d5a4740d.mjs} +12 -6
- package/package.json +1 -1
- package/dist/shared/unpdf.72be7352.d.cts +0 -29
- package/dist/shared/unpdf.72be7352.d.mts +0 -29
- package/dist/shared/unpdf.72be7352.d.ts +0 -29
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# unpdf
|
|
2
2
|
|
|
3
|
-
A collection of utilities to work with PDFs. Uses Mozilla's [PDF.js](https://github.com/mozilla/pdf.js) under the hood.
|
|
3
|
+
A collection of utilities to work with PDFs. Uses Mozilla's [PDF.js](https://github.com/mozilla/pdf.js) under the hood and lazily initializes the library.
|
|
4
4
|
|
|
5
|
-
`unpdf` takes advantage of [export conditions](https://nodejs.org/api/packages.html#packages_conditional_exports) to circumvent build issues in serverless environments. PDF.js depends on the optional `canvas` module, which [doesn't work inside worker threads](https://github.com/Automattic/node-canvas/issues/1394).
|
|
5
|
+
`unpdf` takes advantage of [export conditions](https://nodejs.org/api/packages.html#packages_conditional_exports) to circumvent build issues in serverless environments. For example, PDF.js depends on the optional `canvas` module, which [doesn't work inside worker threads](https://github.com/Automattic/node-canvas/issues/1394).
|
|
6
6
|
|
|
7
|
-
This library is also intended as a modern alternative to the unmaintained [`pdf-parse`](https://www.npmjs.com/package/pdf-parse).
|
|
7
|
+
This library is also intended as a modern alternative to the unmaintained but still popular [`pdf-parse`](https://www.npmjs.com/package/pdf-parse).
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
11
|
- 🏗️ Conditional exports for Browser, Node and worker environments
|
|
12
12
|
- 💬 Extract text from PDFs
|
|
13
|
-
- 🧱
|
|
13
|
+
- 🧱 Opt-in to legacy PDF.js build
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -18,27 +18,51 @@ Run the following command to add `unpdf` to your project.
|
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
20
|
# pnpm
|
|
21
|
-
pnpm add
|
|
21
|
+
pnpm add unpdf
|
|
22
22
|
|
|
23
23
|
# npm
|
|
24
|
-
npm install
|
|
24
|
+
npm install unpdf
|
|
25
25
|
|
|
26
26
|
# yarn
|
|
27
|
-
yarn add
|
|
27
|
+
yarn add unpdf
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
## Usage
|
|
31
31
|
|
|
32
32
|
```ts
|
|
33
|
-
import {
|
|
33
|
+
import { extractPDFText } from 'unpdf'
|
|
34
34
|
|
|
35
|
-
const pdfBuffer = await fetch('https://
|
|
35
|
+
const pdfBuffer = await fetch('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf')
|
|
36
|
+
.then(res => res.arrayBuffer())
|
|
36
37
|
|
|
37
|
-
const { totalPages,
|
|
38
|
+
const { totalPages, text } = await extractPDFText(
|
|
38
39
|
new Uint8Array(pdfBuffer), { mergePages: true }
|
|
39
40
|
)
|
|
40
41
|
```
|
|
41
42
|
|
|
43
|
+
### Use Legacy Or Custom PDF.js Build
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// Before using any other methods, define the PDF.js module
|
|
47
|
+
import { defineUnPDFConfig } from 'unpdf'
|
|
48
|
+
|
|
49
|
+
// Use the legacy build
|
|
50
|
+
defineUnPDFConfig({
|
|
51
|
+
pdfjs: () => import('pdfjs-dist/legacy/build/pdf.js')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
// Now, you can use the other methods
|
|
55
|
+
// …
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Access the PDF.js Module
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { getResolvedPDFJS } from 'unpdf'
|
|
62
|
+
|
|
63
|
+
const { version } = await getResolvedPDFJS()
|
|
64
|
+
```
|
|
65
|
+
|
|
42
66
|
## Config
|
|
43
67
|
|
|
44
68
|
```ts
|
|
@@ -59,24 +83,39 @@ interface UnPDFConfiguration {
|
|
|
59
83
|
|
|
60
84
|
### `defineUnPDFConfig`
|
|
61
85
|
|
|
86
|
+
Define a custom PDF.js module, like the legacy build.
|
|
87
|
+
|
|
62
88
|
```ts
|
|
63
89
|
function defineUnPDFConfig({ pdfjs }: UnPDFConfiguration): Promise<void>
|
|
64
90
|
```
|
|
65
91
|
|
|
66
|
-
### `
|
|
92
|
+
### `getResolvedPDFJS`
|
|
93
|
+
|
|
94
|
+
Returns the resolved PDF.js module.
|
|
67
95
|
|
|
68
96
|
```ts
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
97
|
+
function getResolvedPDFJS(): Promise<typeof import('pdfjs-dist')>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### `getPDFMeta`
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
function getPDFMeta(data: ArrayBuffer): Promise<{
|
|
104
|
+
info: Record<string, any>
|
|
105
|
+
metadata: Record<string, any>
|
|
106
|
+
}>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### `extractPDFText`
|
|
75
110
|
|
|
76
|
-
|
|
111
|
+
```ts
|
|
112
|
+
function extractPDFText(
|
|
77
113
|
data: ArrayBuffer,
|
|
78
114
|
{ mergePages }?: { mergePages?: boolean }
|
|
79
|
-
): Promise<
|
|
115
|
+
): Promise<{
|
|
116
|
+
totalPages: number
|
|
117
|
+
text: string | string[]
|
|
118
|
+
}>
|
|
80
119
|
```
|
|
81
120
|
|
|
82
121
|
### `getImagesFromPage`
|
package/dist/index.node.cjs
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const image = require('./shared/unpdf.
|
|
4
|
-
const utils = require('./shared/unpdf.
|
|
3
|
+
const image = require('./shared/unpdf.3a651ae7.cjs');
|
|
4
|
+
const utils = require('./shared/unpdf.15eec1ee.cjs');
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const getPDFMeta = async (...args) => {
|
|
7
7
|
await utils.resolvePDFJSImports();
|
|
8
|
-
return await image.
|
|
8
|
+
return await image.getPDFMeta(...args);
|
|
9
|
+
};
|
|
10
|
+
const extractPDFText = async (...args) => {
|
|
11
|
+
await utils.resolvePDFJSImports();
|
|
12
|
+
return await image.extractPDFText(...args);
|
|
9
13
|
};
|
|
10
14
|
const getImagesFromPage = async (...args) => {
|
|
11
15
|
await utils.resolvePDFJSImports();
|
|
@@ -13,5 +17,9 @@ const getImagesFromPage = async (...args) => {
|
|
|
13
17
|
};
|
|
14
18
|
|
|
15
19
|
exports.defineUnPDFConfig = utils.defineUnPDFConfig;
|
|
16
|
-
exports.
|
|
20
|
+
exports.getDocumentProxy = utils.getDocumentProxy;
|
|
21
|
+
exports.getResolvedPDFJS = utils.getResolvedPDFJS;
|
|
22
|
+
exports.resolvePDFJSImports = utils.resolvePDFJSImports;
|
|
23
|
+
exports.extractPDFText = extractPDFText;
|
|
17
24
|
exports.getImagesFromPage = getImagesFromPage;
|
|
25
|
+
exports.getPDFMeta = getPDFMeta;
|
package/dist/index.node.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.3a0402b0.cjs';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.3a0402b0.cjs';
|
|
3
|
+
import 'pdfjs-dist/types/src/display/api';
|
|
3
4
|
import 'pdfjs-dist';
|
|
4
5
|
|
|
5
|
-
declare const
|
|
6
|
+
declare const getPDFMeta: typeof getPDFMeta$1;
|
|
7
|
+
declare const extractPDFText: typeof extractPDFText$1;
|
|
6
8
|
declare const getImagesFromPage: typeof getImagesFromPage$1;
|
|
7
9
|
|
|
8
|
-
export {
|
|
10
|
+
export { extractPDFText, getImagesFromPage, getPDFMeta };
|
package/dist/index.node.d.mts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.3a0402b0.mjs';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.3a0402b0.mjs';
|
|
3
|
+
import 'pdfjs-dist/types/src/display/api';
|
|
3
4
|
import 'pdfjs-dist';
|
|
4
5
|
|
|
5
|
-
declare const
|
|
6
|
+
declare const getPDFMeta: typeof getPDFMeta$1;
|
|
7
|
+
declare const extractPDFText: typeof extractPDFText$1;
|
|
6
8
|
declare const getImagesFromPage: typeof getImagesFromPage$1;
|
|
7
9
|
|
|
8
|
-
export {
|
|
10
|
+
export { extractPDFText, getImagesFromPage, getPDFMeta };
|
package/dist/index.node.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.3a0402b0.js';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.3a0402b0.js';
|
|
3
|
+
import 'pdfjs-dist/types/src/display/api';
|
|
3
4
|
import 'pdfjs-dist';
|
|
4
5
|
|
|
5
|
-
declare const
|
|
6
|
+
declare const getPDFMeta: typeof getPDFMeta$1;
|
|
7
|
+
declare const extractPDFText: typeof extractPDFText$1;
|
|
6
8
|
declare const getImagesFromPage: typeof getImagesFromPage$1;
|
|
7
9
|
|
|
8
|
-
export {
|
|
10
|
+
export { extractPDFText, getImagesFromPage, getPDFMeta };
|
package/dist/index.node.mjs
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as resolvePDFJSImports } from './shared/unpdf.
|
|
3
|
-
export { d as defineUnPDFConfig } from './shared/unpdf.
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.d5a4740d.mjs';
|
|
2
|
+
import { r as resolvePDFJSImports } from './shared/unpdf.9db6f9f8.mjs';
|
|
3
|
+
export { d as defineUnPDFConfig, g as getDocumentProxy, a as getResolvedPDFJS } from './shared/unpdf.9db6f9f8.mjs';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const getPDFMeta = async (...args) => {
|
|
6
6
|
await resolvePDFJSImports();
|
|
7
|
-
return await
|
|
7
|
+
return await getPDFMeta$1(...args);
|
|
8
|
+
};
|
|
9
|
+
const extractPDFText = async (...args) => {
|
|
10
|
+
await resolvePDFJSImports();
|
|
11
|
+
return await extractPDFText$1(...args);
|
|
8
12
|
};
|
|
9
13
|
const getImagesFromPage = async (...args) => {
|
|
10
14
|
await resolvePDFJSImports();
|
|
11
15
|
return await getImagesFromPage$1(...args);
|
|
12
16
|
};
|
|
13
17
|
|
|
14
|
-
export {
|
|
18
|
+
export { extractPDFText, getImagesFromPage, getPDFMeta, resolvePDFJSImports };
|
package/dist/index.web.cjs
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const image = require('./shared/unpdf.
|
|
4
|
-
const utils = require('./shared/unpdf.
|
|
3
|
+
const image = require('./shared/unpdf.3a651ae7.cjs');
|
|
4
|
+
const utils = require('./shared/unpdf.15eec1ee.cjs');
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const getPDFMeta = async (...args) => {
|
|
7
7
|
await utils.resolvePDFJSImports();
|
|
8
|
-
return await image.
|
|
8
|
+
return await image.getPDFMeta(...args);
|
|
9
|
+
};
|
|
10
|
+
const extractPDFText = async (...args) => {
|
|
11
|
+
await utils.resolvePDFJSImports();
|
|
12
|
+
return await image.extractPDFText(...args);
|
|
9
13
|
};
|
|
10
14
|
const getImagesFromPage = async (...args) => {
|
|
11
15
|
await utils.resolvePDFJSImports();
|
|
@@ -13,5 +17,9 @@ const getImagesFromPage = async (...args) => {
|
|
|
13
17
|
};
|
|
14
18
|
|
|
15
19
|
exports.defineUnPDFConfig = utils.defineUnPDFConfig;
|
|
16
|
-
exports.
|
|
20
|
+
exports.getDocumentProxy = utils.getDocumentProxy;
|
|
21
|
+
exports.getResolvedPDFJS = utils.getResolvedPDFJS;
|
|
22
|
+
exports.resolvePDFJSImports = utils.resolvePDFJSImports;
|
|
23
|
+
exports.extractPDFText = extractPDFText;
|
|
17
24
|
exports.getImagesFromPage = getImagesFromPage;
|
|
25
|
+
exports.getPDFMeta = getPDFMeta;
|
package/dist/index.web.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.3a0402b0.cjs';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.3a0402b0.cjs';
|
|
3
|
+
import 'pdfjs-dist/types/src/display/api';
|
|
3
4
|
import 'pdfjs-dist';
|
|
4
5
|
|
|
5
|
-
declare const
|
|
6
|
+
declare const getPDFMeta: typeof getPDFMeta$1;
|
|
7
|
+
declare const extractPDFText: typeof extractPDFText$1;
|
|
6
8
|
declare const getImagesFromPage: typeof getImagesFromPage$1;
|
|
7
9
|
|
|
8
|
-
export {
|
|
10
|
+
export { extractPDFText, getImagesFromPage, getPDFMeta };
|
package/dist/index.web.d.mts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.3a0402b0.mjs';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.3a0402b0.mjs';
|
|
3
|
+
import 'pdfjs-dist/types/src/display/api';
|
|
3
4
|
import 'pdfjs-dist';
|
|
4
5
|
|
|
5
|
-
declare const
|
|
6
|
+
declare const getPDFMeta: typeof getPDFMeta$1;
|
|
7
|
+
declare const extractPDFText: typeof extractPDFText$1;
|
|
6
8
|
declare const getImagesFromPage: typeof getImagesFromPage$1;
|
|
7
9
|
|
|
8
|
-
export {
|
|
10
|
+
export { extractPDFText, getImagesFromPage, getPDFMeta };
|
package/dist/index.web.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.3a0402b0.js';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.3a0402b0.js';
|
|
3
|
+
import 'pdfjs-dist/types/src/display/api';
|
|
3
4
|
import 'pdfjs-dist';
|
|
4
5
|
|
|
5
|
-
declare const
|
|
6
|
+
declare const getPDFMeta: typeof getPDFMeta$1;
|
|
7
|
+
declare const extractPDFText: typeof extractPDFText$1;
|
|
6
8
|
declare const getImagesFromPage: typeof getImagesFromPage$1;
|
|
7
9
|
|
|
8
|
-
export {
|
|
10
|
+
export { extractPDFText, getImagesFromPage, getPDFMeta };
|
package/dist/index.web.mjs
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as resolvePDFJSImports } from './shared/unpdf.
|
|
3
|
-
export { d as defineUnPDFConfig } from './shared/unpdf.
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.d5a4740d.mjs';
|
|
2
|
+
import { r as resolvePDFJSImports } from './shared/unpdf.9db6f9f8.mjs';
|
|
3
|
+
export { d as defineUnPDFConfig, g as getDocumentProxy, a as getResolvedPDFJS } from './shared/unpdf.9db6f9f8.mjs';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const getPDFMeta = async (...args) => {
|
|
6
6
|
await resolvePDFJSImports();
|
|
7
|
-
return await
|
|
7
|
+
return await getPDFMeta$1(...args);
|
|
8
|
+
};
|
|
9
|
+
const extractPDFText = async (...args) => {
|
|
10
|
+
await resolvePDFJSImports();
|
|
11
|
+
return await extractPDFText$1(...args);
|
|
8
12
|
};
|
|
9
13
|
const getImagesFromPage = async (...args) => {
|
|
10
14
|
await resolvePDFJSImports();
|
|
11
15
|
return await getImagesFromPage$1(...args);
|
|
12
16
|
};
|
|
13
17
|
|
|
14
|
-
export {
|
|
18
|
+
export { extractPDFText, getImagesFromPage, getPDFMeta, resolvePDFJSImports };
|
package/dist/index.worker.cjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const utils = require('./shared/unpdf.
|
|
3
|
+
const utils = require('./shared/unpdf.15eec1ee.cjs');
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const getPDFMeta = async () => {
|
|
6
|
+
throw new Error("Not implemented in worker context yet");
|
|
7
|
+
};
|
|
8
|
+
const extractPDFText = async () => {
|
|
6
9
|
throw new Error("Not implemented in worker context yet");
|
|
7
10
|
};
|
|
8
11
|
const getImagesFromPage = async () => {
|
|
@@ -10,5 +13,9 @@ const getImagesFromPage = async () => {
|
|
|
10
13
|
};
|
|
11
14
|
|
|
12
15
|
exports.defineUnPDFConfig = utils.defineUnPDFConfig;
|
|
13
|
-
exports.
|
|
16
|
+
exports.getDocumentProxy = utils.getDocumentProxy;
|
|
17
|
+
exports.getResolvedPDFJS = utils.getResolvedPDFJS;
|
|
18
|
+
exports.resolvePDFJSImports = utils.resolvePDFJSImports;
|
|
19
|
+
exports.extractPDFText = extractPDFText;
|
|
14
20
|
exports.getImagesFromPage = getImagesFromPage;
|
|
21
|
+
exports.getPDFMeta = getPDFMeta;
|
package/dist/index.worker.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.3a0402b0.cjs';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.3a0402b0.cjs';
|
|
3
|
+
import 'pdfjs-dist/types/src/display/api';
|
|
3
4
|
import 'pdfjs-dist';
|
|
4
5
|
|
|
5
|
-
declare const
|
|
6
|
+
declare const getPDFMeta: typeof getPDFMeta$1;
|
|
7
|
+
declare const extractPDFText: typeof extractPDFText$1;
|
|
6
8
|
declare const getImagesFromPage: typeof getImagesFromPage$1;
|
|
7
9
|
|
|
8
|
-
export {
|
|
10
|
+
export { extractPDFText, getImagesFromPage, getPDFMeta };
|
package/dist/index.worker.d.mts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.3a0402b0.mjs';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.3a0402b0.mjs';
|
|
3
|
+
import 'pdfjs-dist/types/src/display/api';
|
|
3
4
|
import 'pdfjs-dist';
|
|
4
5
|
|
|
5
|
-
declare const
|
|
6
|
+
declare const getPDFMeta: typeof getPDFMeta$1;
|
|
7
|
+
declare const extractPDFText: typeof extractPDFText$1;
|
|
6
8
|
declare const getImagesFromPage: typeof getImagesFromPage$1;
|
|
7
9
|
|
|
8
|
-
export {
|
|
10
|
+
export { extractPDFText, getImagesFromPage, getPDFMeta };
|
package/dist/index.worker.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.3a0402b0.js';
|
|
2
|
+
export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.3a0402b0.js';
|
|
3
|
+
import 'pdfjs-dist/types/src/display/api';
|
|
3
4
|
import 'pdfjs-dist';
|
|
4
5
|
|
|
5
|
-
declare const
|
|
6
|
+
declare const getPDFMeta: typeof getPDFMeta$1;
|
|
7
|
+
declare const extractPDFText: typeof extractPDFText$1;
|
|
6
8
|
declare const getImagesFromPage: typeof getImagesFromPage$1;
|
|
7
9
|
|
|
8
|
-
export {
|
|
10
|
+
export { extractPDFText, getImagesFromPage, getPDFMeta };
|
package/dist/index.worker.mjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export { d as defineUnPDFConfig } from './shared/unpdf.
|
|
1
|
+
export { d as defineUnPDFConfig, g as getDocumentProxy, a as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.9db6f9f8.mjs';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const getPDFMeta = async () => {
|
|
4
|
+
throw new Error("Not implemented in worker context yet");
|
|
5
|
+
};
|
|
6
|
+
const extractPDFText = async () => {
|
|
4
7
|
throw new Error("Not implemented in worker context yet");
|
|
5
8
|
};
|
|
6
9
|
const getImagesFromPage = async () => {
|
|
7
10
|
throw new Error("Not implemented in worker context yet");
|
|
8
11
|
};
|
|
9
12
|
|
|
10
|
-
export {
|
|
13
|
+
export { extractPDFText, getImagesFromPage, getPDFMeta };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
let resolvedModule;
|
|
4
4
|
async function getDocumentProxy(data) {
|
|
5
|
-
const { getDocument } = getResolvedPDFJS();
|
|
5
|
+
const { getDocument } = await getResolvedPDFJS();
|
|
6
6
|
const pdf = await getDocument({
|
|
7
7
|
data,
|
|
8
8
|
useWorkerFetch: false,
|
|
@@ -21,7 +21,9 @@ async function defineUnPDFConfig({ pdfjs }) {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
function getResolvedPDFJS() {
|
|
24
|
+
async function getResolvedPDFJS() {
|
|
25
|
+
if (!resolvedModule)
|
|
26
|
+
await resolvePDFJSImports();
|
|
25
27
|
return resolvedModule;
|
|
26
28
|
}
|
|
27
29
|
async function resolvePDFJSImports() {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as pdfjs_dist_types_src_display_api from 'pdfjs-dist/types/src/display/api';
|
|
2
|
+
import PDFJS from 'pdfjs-dist';
|
|
3
|
+
|
|
4
|
+
declare function getPDFMeta(data: ArrayBuffer): Promise<{
|
|
5
|
+
info: Record<string, any>;
|
|
6
|
+
metadata: Record<string, any>;
|
|
7
|
+
}>;
|
|
8
|
+
|
|
9
|
+
declare function extractPDFText(data: ArrayBuffer, { mergePages }?: {
|
|
10
|
+
mergePages?: boolean;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
totalPages: number;
|
|
13
|
+
text: string | string[];
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
declare function getImagesFromPage(data: ArrayBuffer, pageNumber: number): Promise<ArrayBuffer[]>;
|
|
17
|
+
|
|
18
|
+
interface UnPDFConfiguration {
|
|
19
|
+
/**
|
|
20
|
+
* By default, UnPDF will use the latest version of PDF.js. If you want to
|
|
21
|
+
* use an older version or the legacy build, set a promise that resolves to
|
|
22
|
+
* the PDF.js module.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* () => import('pdfjs-dist/legacy/build/pdf.js')
|
|
26
|
+
*/
|
|
27
|
+
pdfjs?: () => Promise<typeof PDFJS>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare function getDocumentProxy(data: ArrayBuffer): Promise<pdfjs_dist_types_src_display_api.PDFDocumentProxy>;
|
|
31
|
+
declare function defineUnPDFConfig({ pdfjs }: UnPDFConfiguration): Promise<void>;
|
|
32
|
+
declare function getResolvedPDFJS(): Promise<typeof PDFJS>;
|
|
33
|
+
declare function resolvePDFJSImports(): Promise<void>;
|
|
34
|
+
|
|
35
|
+
export { getImagesFromPage as a, getDocumentProxy as b, getResolvedPDFJS as c, defineUnPDFConfig as d, extractPDFText as e, getPDFMeta as g, resolvePDFJSImports as r };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as pdfjs_dist_types_src_display_api from 'pdfjs-dist/types/src/display/api';
|
|
2
|
+
import PDFJS from 'pdfjs-dist';
|
|
3
|
+
|
|
4
|
+
declare function getPDFMeta(data: ArrayBuffer): Promise<{
|
|
5
|
+
info: Record<string, any>;
|
|
6
|
+
metadata: Record<string, any>;
|
|
7
|
+
}>;
|
|
8
|
+
|
|
9
|
+
declare function extractPDFText(data: ArrayBuffer, { mergePages }?: {
|
|
10
|
+
mergePages?: boolean;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
totalPages: number;
|
|
13
|
+
text: string | string[];
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
declare function getImagesFromPage(data: ArrayBuffer, pageNumber: number): Promise<ArrayBuffer[]>;
|
|
17
|
+
|
|
18
|
+
interface UnPDFConfiguration {
|
|
19
|
+
/**
|
|
20
|
+
* By default, UnPDF will use the latest version of PDF.js. If you want to
|
|
21
|
+
* use an older version or the legacy build, set a promise that resolves to
|
|
22
|
+
* the PDF.js module.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* () => import('pdfjs-dist/legacy/build/pdf.js')
|
|
26
|
+
*/
|
|
27
|
+
pdfjs?: () => Promise<typeof PDFJS>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare function getDocumentProxy(data: ArrayBuffer): Promise<pdfjs_dist_types_src_display_api.PDFDocumentProxy>;
|
|
31
|
+
declare function defineUnPDFConfig({ pdfjs }: UnPDFConfiguration): Promise<void>;
|
|
32
|
+
declare function getResolvedPDFJS(): Promise<typeof PDFJS>;
|
|
33
|
+
declare function resolvePDFJSImports(): Promise<void>;
|
|
34
|
+
|
|
35
|
+
export { getImagesFromPage as a, getDocumentProxy as b, getResolvedPDFJS as c, defineUnPDFConfig as d, extractPDFText as e, getPDFMeta as g, resolvePDFJSImports as r };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as pdfjs_dist_types_src_display_api from 'pdfjs-dist/types/src/display/api';
|
|
2
|
+
import PDFJS from 'pdfjs-dist';
|
|
3
|
+
|
|
4
|
+
declare function getPDFMeta(data: ArrayBuffer): Promise<{
|
|
5
|
+
info: Record<string, any>;
|
|
6
|
+
metadata: Record<string, any>;
|
|
7
|
+
}>;
|
|
8
|
+
|
|
9
|
+
declare function extractPDFText(data: ArrayBuffer, { mergePages }?: {
|
|
10
|
+
mergePages?: boolean;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
totalPages: number;
|
|
13
|
+
text: string | string[];
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
declare function getImagesFromPage(data: ArrayBuffer, pageNumber: number): Promise<ArrayBuffer[]>;
|
|
17
|
+
|
|
18
|
+
interface UnPDFConfiguration {
|
|
19
|
+
/**
|
|
20
|
+
* By default, UnPDF will use the latest version of PDF.js. If you want to
|
|
21
|
+
* use an older version or the legacy build, set a promise that resolves to
|
|
22
|
+
* the PDF.js module.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* () => import('pdfjs-dist/legacy/build/pdf.js')
|
|
26
|
+
*/
|
|
27
|
+
pdfjs?: () => Promise<typeof PDFJS>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare function getDocumentProxy(data: ArrayBuffer): Promise<pdfjs_dist_types_src_display_api.PDFDocumentProxy>;
|
|
31
|
+
declare function defineUnPDFConfig({ pdfjs }: UnPDFConfiguration): Promise<void>;
|
|
32
|
+
declare function getResolvedPDFJS(): Promise<typeof PDFJS>;
|
|
33
|
+
declare function resolvePDFJSImports(): Promise<void>;
|
|
34
|
+
|
|
35
|
+
export { getImagesFromPage as a, getDocumentProxy as b, getResolvedPDFJS as c, defineUnPDFConfig as d, extractPDFText as e, getPDFMeta as g, resolvePDFJSImports as r };
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const utils = require('./unpdf.
|
|
3
|
+
const utils = require('./unpdf.15eec1ee.cjs');
|
|
4
4
|
|
|
5
|
-
async function
|
|
5
|
+
async function getPDFMeta(data) {
|
|
6
6
|
const pdf = await utils.getDocumentProxy(data);
|
|
7
7
|
const meta = await pdf.getMetadata().catch(() => null);
|
|
8
|
+
return {
|
|
9
|
+
info: meta?.info ?? {},
|
|
10
|
+
metadata: meta?.metadata?.getAll() ?? {}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function extractPDFText(data, { mergePages = false } = {}) {
|
|
15
|
+
const pdf = await utils.getDocumentProxy(data);
|
|
8
16
|
const texts = await Promise.all(
|
|
9
17
|
Array.from({ length: pdf.numPages }, (_, i) => getPageText(pdf, i + 1))
|
|
10
18
|
);
|
|
11
19
|
const filteredTexts = texts.filter(Boolean);
|
|
12
20
|
return {
|
|
13
21
|
totalPages: pdf.numPages,
|
|
14
|
-
info: meta?.info,
|
|
15
|
-
metadata: meta?.metadata?.getAll(),
|
|
16
22
|
text: mergePages ? filteredTexts.join("\n\n") : filteredTexts
|
|
17
23
|
};
|
|
18
24
|
}
|
|
@@ -29,7 +35,7 @@ async function getImagesFromPage(data, pageNumber) {
|
|
|
29
35
|
const pdf = await utils.getDocumentProxy(data);
|
|
30
36
|
const page = await pdf.getPage(pageNumber);
|
|
31
37
|
const operatorList = await page.getOperatorList();
|
|
32
|
-
const { OPS } = utils.getResolvedPDFJS();
|
|
38
|
+
const { OPS } = await utils.getResolvedPDFJS();
|
|
33
39
|
const images = [];
|
|
34
40
|
for (const op of operatorList.fnArray) {
|
|
35
41
|
if (op !== OPS.paintImageXObject)
|
|
@@ -41,5 +47,6 @@ async function getImagesFromPage(data, pageNumber) {
|
|
|
41
47
|
return images;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
exports.
|
|
50
|
+
exports.extractPDFText = extractPDFText;
|
|
45
51
|
exports.getImagesFromPage = getImagesFromPage;
|
|
52
|
+
exports.getPDFMeta = getPDFMeta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
let resolvedModule;
|
|
2
2
|
async function getDocumentProxy(data) {
|
|
3
|
-
const { getDocument } = getResolvedPDFJS();
|
|
3
|
+
const { getDocument } = await getResolvedPDFJS();
|
|
4
4
|
const pdf = await getDocument({
|
|
5
5
|
data,
|
|
6
6
|
useWorkerFetch: false,
|
|
@@ -19,7 +19,9 @@ async function defineUnPDFConfig({ pdfjs }) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
function getResolvedPDFJS() {
|
|
22
|
+
async function getResolvedPDFJS() {
|
|
23
|
+
if (!resolvedModule)
|
|
24
|
+
await resolvePDFJSImports();
|
|
23
25
|
return resolvedModule;
|
|
24
26
|
}
|
|
25
27
|
async function resolvePDFJSImports() {
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import { g as getDocumentProxy, a as getResolvedPDFJS } from './unpdf.
|
|
1
|
+
import { g as getDocumentProxy, a as getResolvedPDFJS } from './unpdf.9db6f9f8.mjs';
|
|
2
2
|
|
|
3
|
-
async function
|
|
3
|
+
async function getPDFMeta(data) {
|
|
4
4
|
const pdf = await getDocumentProxy(data);
|
|
5
5
|
const meta = await pdf.getMetadata().catch(() => null);
|
|
6
|
+
return {
|
|
7
|
+
info: meta?.info ?? {},
|
|
8
|
+
metadata: meta?.metadata?.getAll() ?? {}
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function extractPDFText(data, { mergePages = false } = {}) {
|
|
13
|
+
const pdf = await getDocumentProxy(data);
|
|
6
14
|
const texts = await Promise.all(
|
|
7
15
|
Array.from({ length: pdf.numPages }, (_, i) => getPageText(pdf, i + 1))
|
|
8
16
|
);
|
|
9
17
|
const filteredTexts = texts.filter(Boolean);
|
|
10
18
|
return {
|
|
11
19
|
totalPages: pdf.numPages,
|
|
12
|
-
info: meta?.info,
|
|
13
|
-
metadata: meta?.metadata?.getAll(),
|
|
14
20
|
text: mergePages ? filteredTexts.join("\n\n") : filteredTexts
|
|
15
21
|
};
|
|
16
22
|
}
|
|
@@ -27,7 +33,7 @@ async function getImagesFromPage(data, pageNumber) {
|
|
|
27
33
|
const pdf = await getDocumentProxy(data);
|
|
28
34
|
const page = await pdf.getPage(pageNumber);
|
|
29
35
|
const operatorList = await page.getOperatorList();
|
|
30
|
-
const { OPS } = getResolvedPDFJS();
|
|
36
|
+
const { OPS } = await getResolvedPDFJS();
|
|
31
37
|
const images = [];
|
|
32
38
|
for (const op of operatorList.fnArray) {
|
|
33
39
|
if (op !== OPS.paintImageXObject)
|
|
@@ -39,4 +45,4 @@ async function getImagesFromPage(data, pageNumber) {
|
|
|
39
45
|
return images;
|
|
40
46
|
}
|
|
41
47
|
|
|
42
|
-
export {
|
|
48
|
+
export { getImagesFromPage as a, extractPDFText as e, getPDFMeta as g };
|
package/package.json
CHANGED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import PDFJS from 'pdfjs-dist';
|
|
2
|
-
|
|
3
|
-
interface PDFContent {
|
|
4
|
-
totalPages: number;
|
|
5
|
-
info?: Record<string, any>;
|
|
6
|
-
metadata?: any;
|
|
7
|
-
text: string | string[];
|
|
8
|
-
}
|
|
9
|
-
interface UnPDFConfiguration {
|
|
10
|
-
/**
|
|
11
|
-
* By default, UnPDF will use the latest version of PDF.js. If you want to
|
|
12
|
-
* use an older version or the legacy build, set a promise that resolves to
|
|
13
|
-
* the PDF.js module.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* () => import('pdfjs-dist/legacy/build/pdf.js')
|
|
17
|
-
*/
|
|
18
|
-
pdfjs?: () => Promise<typeof PDFJS>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare function decodePDFText(data: ArrayBuffer, { mergePages }?: {
|
|
22
|
-
mergePages?: boolean;
|
|
23
|
-
}): Promise<PDFContent>;
|
|
24
|
-
|
|
25
|
-
declare function getImagesFromPage(data: ArrayBuffer, pageNumber: number): Promise<ArrayBuffer[]>;
|
|
26
|
-
|
|
27
|
-
declare function defineUnPDFConfig({ pdfjs }: UnPDFConfiguration): Promise<void>;
|
|
28
|
-
|
|
29
|
-
export { defineUnPDFConfig as a, decodePDFText as d, getImagesFromPage as g };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import PDFJS from 'pdfjs-dist';
|
|
2
|
-
|
|
3
|
-
interface PDFContent {
|
|
4
|
-
totalPages: number;
|
|
5
|
-
info?: Record<string, any>;
|
|
6
|
-
metadata?: any;
|
|
7
|
-
text: string | string[];
|
|
8
|
-
}
|
|
9
|
-
interface UnPDFConfiguration {
|
|
10
|
-
/**
|
|
11
|
-
* By default, UnPDF will use the latest version of PDF.js. If you want to
|
|
12
|
-
* use an older version or the legacy build, set a promise that resolves to
|
|
13
|
-
* the PDF.js module.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* () => import('pdfjs-dist/legacy/build/pdf.js')
|
|
17
|
-
*/
|
|
18
|
-
pdfjs?: () => Promise<typeof PDFJS>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare function decodePDFText(data: ArrayBuffer, { mergePages }?: {
|
|
22
|
-
mergePages?: boolean;
|
|
23
|
-
}): Promise<PDFContent>;
|
|
24
|
-
|
|
25
|
-
declare function getImagesFromPage(data: ArrayBuffer, pageNumber: number): Promise<ArrayBuffer[]>;
|
|
26
|
-
|
|
27
|
-
declare function defineUnPDFConfig({ pdfjs }: UnPDFConfiguration): Promise<void>;
|
|
28
|
-
|
|
29
|
-
export { defineUnPDFConfig as a, decodePDFText as d, getImagesFromPage as g };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import PDFJS from 'pdfjs-dist';
|
|
2
|
-
|
|
3
|
-
interface PDFContent {
|
|
4
|
-
totalPages: number;
|
|
5
|
-
info?: Record<string, any>;
|
|
6
|
-
metadata?: any;
|
|
7
|
-
text: string | string[];
|
|
8
|
-
}
|
|
9
|
-
interface UnPDFConfiguration {
|
|
10
|
-
/**
|
|
11
|
-
* By default, UnPDF will use the latest version of PDF.js. If you want to
|
|
12
|
-
* use an older version or the legacy build, set a promise that resolves to
|
|
13
|
-
* the PDF.js module.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* () => import('pdfjs-dist/legacy/build/pdf.js')
|
|
17
|
-
*/
|
|
18
|
-
pdfjs?: () => Promise<typeof PDFJS>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare function decodePDFText(data: ArrayBuffer, { mergePages }?: {
|
|
22
|
-
mergePages?: boolean;
|
|
23
|
-
}): Promise<PDFContent>;
|
|
24
|
-
|
|
25
|
-
declare function getImagesFromPage(data: ArrayBuffer, pageNumber: number): Promise<ArrayBuffer[]>;
|
|
26
|
-
|
|
27
|
-
declare function defineUnPDFConfig({ pdfjs }: UnPDFConfiguration): Promise<void>;
|
|
28
|
-
|
|
29
|
-
export { defineUnPDFConfig as a, decodePDFText as d, getImagesFromPage as g };
|