unpdf 0.6.1 → 0.7.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 +69 -17
- package/dist/index.cjs +108 -22
- package/dist/index.d.cts +22 -10
- package/dist/index.d.mts +22 -10
- package/dist/index.d.ts +22 -10
- package/dist/index.mjs +105 -21
- package/dist/pdfjs.mjs +1 -1
- package/package.json +24 -4
package/README.md
CHANGED
|
@@ -34,25 +34,25 @@ yarn add unpdf
|
|
|
34
34
|
### Extract Text From PDF
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
|
-
import {
|
|
37
|
+
import { extractText, getDocumentProxy } from "unpdf";
|
|
38
38
|
|
|
39
39
|
// Fetch a PDF file from the web
|
|
40
|
-
const
|
|
40
|
+
const buffer = await fetch(
|
|
41
41
|
"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
|
|
42
42
|
).then((res) => res.arrayBuffer());
|
|
43
43
|
|
|
44
44
|
// Or load it from the filesystem
|
|
45
|
-
const
|
|
45
|
+
const buffer = await readFile("./dummy.pdf");
|
|
46
46
|
|
|
47
|
-
//
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
});
|
|
47
|
+
// Load PDF from buffer
|
|
48
|
+
const pdf = await getDocumentProxy(new Uint8Array(pdf));
|
|
49
|
+
// Extract text from PDF
|
|
50
|
+
const { totalPages, text } = await extractText(pdf, { mergePages: true });
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
### Use Legacy Or Custom PDF.js Build
|
|
54
54
|
|
|
55
|
-
Generally, you don't need to worry about the PDF.js build. `unpdf` ships with a serverless build of the latest PDF.js version. However, if you want to use
|
|
55
|
+
Generally, you don't need to worry about the PDF.js build. `unpdf` ships with a serverless build of the latest PDF.js version. However, if you want to use the official PDF.js version or the legacy build, you can define a custom PDF.js module.
|
|
56
56
|
|
|
57
57
|
```ts
|
|
58
58
|
// Before using any other methods, define the PDF.js module
|
|
@@ -132,19 +132,21 @@ Returns the resolved PDF.js module. If no build is defined, the latest version w
|
|
|
132
132
|
function getResolvedPDFJS(): Promise<PDFJS>;
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
### `
|
|
135
|
+
### `getMeta`
|
|
136
136
|
|
|
137
137
|
```ts
|
|
138
|
-
function
|
|
138
|
+
function getMeta(data: BinaryData | PDFDocumentProxy): Promise<{
|
|
139
139
|
info: Record<string, any>;
|
|
140
140
|
metadata: Record<string, any>;
|
|
141
141
|
}>;
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
-
### `
|
|
144
|
+
### `extractText`
|
|
145
|
+
|
|
146
|
+
Extracts all text from a PDF. If `mergePages` is set to `true`, the text of all pages will be merged into a single string. Otherwise, an array of strings for each page will be returned.
|
|
145
147
|
|
|
146
148
|
```ts
|
|
147
|
-
function
|
|
149
|
+
function extractText(
|
|
148
150
|
data: BinaryData | PDFDocumentProxy,
|
|
149
151
|
{ mergePages }?: { mergePages?: boolean },
|
|
150
152
|
): Promise<{
|
|
@@ -153,20 +155,70 @@ function extractPDFText(
|
|
|
153
155
|
}>;
|
|
154
156
|
```
|
|
155
157
|
|
|
156
|
-
### `
|
|
158
|
+
### `renderPageAsImage`
|
|
159
|
+
|
|
160
|
+
> [!NOTE]
|
|
161
|
+
> This method will only work in Node.js and browser environments.
|
|
162
|
+
|
|
163
|
+
To render a PDF page as an image, you can use the `renderPageAsImage` method. This method will return an `ArrayBuffer` of the rendered image.
|
|
164
|
+
|
|
165
|
+
In order to use this method, you have to meet the following requirements:
|
|
166
|
+
|
|
167
|
+
- Use the official PDF.js build
|
|
168
|
+
- Install the [`canvas`](https://www.npmjs.com/package/canvas) package in Node.js environments
|
|
169
|
+
|
|
170
|
+
**Example**
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
import { defineUnPDFConfig, renderPageAsImage } from "unpdf";
|
|
174
|
+
|
|
175
|
+
defineUnPDFConfig({
|
|
176
|
+
// Use the official PDF.js build
|
|
177
|
+
pdfjs: () => import("pdfjs-dist"),
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const pdf = await readFile("./dummy.pdf");
|
|
181
|
+
const buffer = new Uint8Array(pdf);
|
|
182
|
+
const pageNumber = 1;
|
|
183
|
+
|
|
184
|
+
const result = await renderPageAsImage(buffer, pageNumber, {
|
|
185
|
+
canvas: () => import("canvas"),
|
|
186
|
+
});
|
|
187
|
+
await writeFile("dummy-page-1.png", Buffer.from(result));
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**Type Declaration**
|
|
157
191
|
|
|
158
192
|
```ts
|
|
159
|
-
function
|
|
193
|
+
declare function renderPageAsImage(
|
|
160
194
|
data: BinaryData | PDFDocumentProxy,
|
|
161
195
|
pageNumber: number,
|
|
162
|
-
|
|
196
|
+
options?: {
|
|
197
|
+
canvas?: () => Promise<typeof "canvas">;
|
|
198
|
+
/** @default 1 */
|
|
199
|
+
scale?: number
|
|
200
|
+
width?: number;
|
|
201
|
+
height?: number;
|
|
202
|
+
},
|
|
203
|
+
): Promise<ArrayBuffer>;
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### `extractImages`
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
function extractImages(
|
|
210
|
+
data: BinaryData | PDFDocumentProxy,
|
|
211
|
+
pageNumber: number,
|
|
212
|
+
): Promise<Uint8ClampedArray[]>;
|
|
163
213
|
```
|
|
164
214
|
|
|
165
215
|
## FAQ
|
|
166
216
|
|
|
167
|
-
###
|
|
217
|
+
### Why Is `canvas` A Peer Dependency?
|
|
218
|
+
|
|
219
|
+
The official PDF.js library depends on the `canvas` module for Node.js environments, which [doesn't work inside worker threads](https://github.com/Automattic/node-canvas/issues/1394). That's why `unpdf` ships with a serverless build of PDF.js that mocks the `canvas` module.
|
|
168
220
|
|
|
169
|
-
|
|
221
|
+
However, to render PDF pages as images, you need to install the `canvas` module in Node.js environments. That's why `canvas` is a peer dependency.
|
|
170
222
|
|
|
171
223
|
## License
|
|
172
224
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
let resolvedModule;
|
|
4
|
+
const isNode = globalThis.process?.release?.name === "node";
|
|
5
|
+
const isBrowser = typeof window !== "undefined";
|
|
4
6
|
async function getDocumentProxy(data, options = {}) {
|
|
5
7
|
const { getDocument } = await getResolvedPDFJS();
|
|
6
8
|
const pdf = await getDocument({
|
|
@@ -10,12 +12,6 @@ async function getDocumentProxy(data, options = {}) {
|
|
|
10
12
|
}).promise;
|
|
11
13
|
return pdf;
|
|
12
14
|
}
|
|
13
|
-
async function defineUnPDFConfig(options) {
|
|
14
|
-
const { pdfjs } = { ...options };
|
|
15
|
-
if (pdfjs) {
|
|
16
|
-
await resolvePDFJSImports(pdfjs, { force: true });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
15
|
async function getResolvedPDFJS() {
|
|
20
16
|
if (!resolvedModule) {
|
|
21
17
|
await resolvePDFJSImports();
|
|
@@ -49,7 +45,7 @@ function isPDFDocumentProxy(data) {
|
|
|
49
45
|
return typeof data === "object" && data !== null && "_pdfInfo" in data;
|
|
50
46
|
}
|
|
51
47
|
|
|
52
|
-
async function
|
|
48
|
+
async function getMeta$1(data) {
|
|
53
49
|
const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
|
|
54
50
|
const meta = await pdf.getMetadata();
|
|
55
51
|
return {
|
|
@@ -58,7 +54,7 @@ async function getPDFMeta$1(data) {
|
|
|
58
54
|
};
|
|
59
55
|
}
|
|
60
56
|
|
|
61
|
-
async function
|
|
57
|
+
async function extractText$1(data, options = {}) {
|
|
62
58
|
const { mergePages = false } = { ...options };
|
|
63
59
|
const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
|
|
64
60
|
const texts = await Promise.all(
|
|
@@ -80,41 +76,131 @@ async function getPageText(pdf, pageNumber) {
|
|
|
80
76
|
return items.map(({ str }) => str).join("\n");
|
|
81
77
|
}
|
|
82
78
|
|
|
83
|
-
async function
|
|
79
|
+
async function extractImages$1(data, pageNumber) {
|
|
84
80
|
const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
|
|
85
81
|
const page = await pdf.getPage(pageNumber);
|
|
82
|
+
if (pageNumber < 1 || pageNumber > pdf.numPages) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Invalid page number. Must be between 1 and ${pdf.numPages}.`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
86
87
|
const operatorList = await page.getOperatorList();
|
|
87
88
|
const { OPS } = await getResolvedPDFJS();
|
|
88
89
|
const images = [];
|
|
89
|
-
for (
|
|
90
|
+
for (let i = 0; i < operatorList.fnArray.length; i++) {
|
|
91
|
+
const op = operatorList.fnArray[i];
|
|
90
92
|
if (op !== OPS.paintImageXObject) {
|
|
91
93
|
continue;
|
|
92
94
|
}
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
95
|
+
const imageKey = operatorList.argsArray[i][0];
|
|
96
|
+
const image = await page.objs.get(imageKey);
|
|
97
|
+
images.push(image.data);
|
|
97
98
|
}
|
|
98
99
|
return images;
|
|
99
100
|
}
|
|
101
|
+
async function renderPageAsImage$1(data, pageNumber, options = {}) {
|
|
102
|
+
const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
|
|
103
|
+
const page = await pdf.getPage(pageNumber);
|
|
104
|
+
if (pageNumber < 1 || pageNumber > pdf.numPages) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`Invalid page number. Must be between 1 and ${pdf.numPages}.`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
let outputScale = options.scale || 1;
|
|
110
|
+
let viewport = page.getViewport({ scale: outputScale });
|
|
111
|
+
if (options.width) {
|
|
112
|
+
outputScale = options.width / viewport.width;
|
|
113
|
+
} else if (options.height) {
|
|
114
|
+
outputScale = options.height / viewport.height;
|
|
115
|
+
}
|
|
116
|
+
if (outputScale !== 1 && outputScale > 0) {
|
|
117
|
+
viewport = page.getViewport({ scale: outputScale });
|
|
118
|
+
}
|
|
119
|
+
const canvasFactory = await createIsomorphicCanvasFactory(options.canvas);
|
|
120
|
+
const ctx = canvasFactory.create(viewport.width, viewport.height);
|
|
121
|
+
await page.render({
|
|
122
|
+
canvasContext: ctx.context,
|
|
123
|
+
viewport
|
|
124
|
+
}).promise;
|
|
125
|
+
const dataUrl = isBrowser ? ctx.canvas.toDataURL() : ctx.canvas.toDataURL();
|
|
126
|
+
const response = await fetch(dataUrl);
|
|
127
|
+
return await response.arrayBuffer();
|
|
128
|
+
}
|
|
129
|
+
async function createIsomorphicCanvasFactory(canvas) {
|
|
130
|
+
const _canvas = await canvas?.();
|
|
131
|
+
return {
|
|
132
|
+
_createCanvas(width, height) {
|
|
133
|
+
if (isBrowser) {
|
|
134
|
+
const canvas2 = document.createElement("canvas");
|
|
135
|
+
canvas2.width = width;
|
|
136
|
+
canvas2.height = height;
|
|
137
|
+
return canvas2;
|
|
138
|
+
} else if (isNode) {
|
|
139
|
+
if (!_canvas) {
|
|
140
|
+
throw new Error('Failed to resolve "canvas" package.');
|
|
141
|
+
}
|
|
142
|
+
return _canvas.createCanvas(width, height);
|
|
143
|
+
}
|
|
144
|
+
throw new Error("Unsupported environment for canvas creation.");
|
|
145
|
+
},
|
|
146
|
+
create(width, height) {
|
|
147
|
+
const _canvas2 = this._createCanvas(width, height);
|
|
148
|
+
const context = _canvas2.getContext(
|
|
149
|
+
"2d"
|
|
150
|
+
);
|
|
151
|
+
return {
|
|
152
|
+
canvas: _canvas2,
|
|
153
|
+
context
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
reset(ctx, width, height) {
|
|
157
|
+
if (ctx.canvas) {
|
|
158
|
+
ctx.canvas.width = width;
|
|
159
|
+
ctx.canvas.height = height;
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
destroy(ctx) {
|
|
163
|
+
if (ctx.canvas) {
|
|
164
|
+
ctx.canvas.width = 0;
|
|
165
|
+
ctx.canvas.height = 0;
|
|
166
|
+
}
|
|
167
|
+
ctx.canvas = void 0;
|
|
168
|
+
ctx.context = void 0;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function defineUnPDFConfig(options) {
|
|
174
|
+
const { pdfjs } = { ...options };
|
|
175
|
+
if (pdfjs) {
|
|
176
|
+
await resolvePDFJSImports(pdfjs, { force: true });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
100
179
|
|
|
101
|
-
const
|
|
180
|
+
const getMeta = async (...args) => {
|
|
181
|
+
await resolvePDFJSImports();
|
|
182
|
+
return await getMeta$1(...args);
|
|
183
|
+
};
|
|
184
|
+
const extractText = async (...args) => {
|
|
102
185
|
await resolvePDFJSImports();
|
|
103
|
-
return await
|
|
186
|
+
return await extractText$1(...args);
|
|
104
187
|
};
|
|
105
|
-
const extractPDFText =
|
|
188
|
+
const extractPDFText = extractText;
|
|
189
|
+
const extractImages = async (...args) => {
|
|
106
190
|
await resolvePDFJSImports();
|
|
107
|
-
return await
|
|
191
|
+
return await extractImages$1(...args);
|
|
108
192
|
};
|
|
109
|
-
const
|
|
193
|
+
const renderPageAsImage = async (...args) => {
|
|
110
194
|
await resolvePDFJSImports();
|
|
111
|
-
return await
|
|
195
|
+
return await renderPageAsImage$1(...args);
|
|
112
196
|
};
|
|
113
197
|
|
|
114
198
|
exports.defineUnPDFConfig = defineUnPDFConfig;
|
|
199
|
+
exports.extractImages = extractImages;
|
|
115
200
|
exports.extractPDFText = extractPDFText;
|
|
201
|
+
exports.extractText = extractText;
|
|
116
202
|
exports.getDocumentProxy = getDocumentProxy;
|
|
117
|
-
exports.
|
|
118
|
-
exports.getPDFMeta = getPDFMeta;
|
|
203
|
+
exports.getMeta = getMeta;
|
|
119
204
|
exports.getResolvedPDFJS = getResolvedPDFJS;
|
|
205
|
+
exports.renderPageAsImage = renderPageAsImage;
|
|
120
206
|
exports.resolvePDFJSImports = resolvePDFJSImports;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { BinaryData, PDFDocumentProxy, DocumentInitParameters } from './types/src/display/api';
|
|
2
|
+
import * as canvas from 'canvas';
|
|
2
3
|
import * as _PDFJS from './types/src/pdf';
|
|
3
4
|
|
|
4
|
-
declare function
|
|
5
|
+
declare function getMeta$1(data: BinaryData | PDFDocumentProxy): Promise<{
|
|
5
6
|
info: Record<string, any>;
|
|
6
7
|
metadata: Record<string, any>;
|
|
7
8
|
}>;
|
|
8
9
|
|
|
9
|
-
declare function
|
|
10
|
+
declare function extractText$1(data: BinaryData | PDFDocumentProxy, options?: {
|
|
10
11
|
mergePages?: boolean;
|
|
11
12
|
}): Promise<{
|
|
12
13
|
totalPages: number;
|
|
13
14
|
text: string | string[];
|
|
14
15
|
}>;
|
|
15
16
|
|
|
16
|
-
declare function
|
|
17
|
+
declare function extractImages$1(data: BinaryData | PDFDocumentProxy, pageNumber: number): Promise<Uint8ClampedArray[]>;
|
|
18
|
+
declare function renderPageAsImage$1(data: BinaryData | PDFDocumentProxy, pageNumber: number, options?: {
|
|
19
|
+
canvas?: () => Promise<typeof canvas>;
|
|
20
|
+
/** @default 1 */
|
|
21
|
+
scale?: number;
|
|
22
|
+
width?: number;
|
|
23
|
+
height?: number;
|
|
24
|
+
}): Promise<ArrayBuffer>;
|
|
17
25
|
|
|
18
26
|
type PDFJS = typeof _PDFJS;
|
|
19
27
|
interface UnPDFConfiguration {
|
|
@@ -26,9 +34,11 @@ interface UnPDFConfiguration {
|
|
|
26
34
|
* // Use the legacy build
|
|
27
35
|
* () => import('pdfjs-dist/legacy/build/pdf.js')
|
|
28
36
|
*/
|
|
29
|
-
pdfjs?: () => Promise<
|
|
37
|
+
pdfjs?: () => Promise<any>;
|
|
30
38
|
}
|
|
31
39
|
|
|
40
|
+
declare function defineUnPDFConfig(options: UnPDFConfiguration): Promise<void>;
|
|
41
|
+
|
|
32
42
|
/**
|
|
33
43
|
* Returns a PDFDocumentProxy instance from a given binary data.
|
|
34
44
|
*
|
|
@@ -36,14 +46,16 @@ interface UnPDFConfiguration {
|
|
|
36
46
|
* - `isEvalSupported: false`
|
|
37
47
|
*/
|
|
38
48
|
declare function getDocumentProxy(data: BinaryData, options?: DocumentInitParameters): Promise<PDFDocumentProxy>;
|
|
39
|
-
declare function defineUnPDFConfig(options: UnPDFConfiguration): Promise<void>;
|
|
40
49
|
declare function getResolvedPDFJS(): Promise<PDFJS>;
|
|
41
|
-
declare function resolvePDFJSImports(pdfjsResolver?: () => Promise<
|
|
50
|
+
declare function resolvePDFJSImports(pdfjsResolver?: () => Promise<any>, { force }?: {
|
|
42
51
|
force?: boolean | undefined;
|
|
43
52
|
}): Promise<void>;
|
|
44
53
|
|
|
45
|
-
declare const
|
|
46
|
-
declare const
|
|
47
|
-
|
|
54
|
+
declare const getMeta: typeof getMeta$1;
|
|
55
|
+
declare const extractText: typeof extractText$1;
|
|
56
|
+
/** @deprecated Use `extractText` instead. */
|
|
57
|
+
declare const extractPDFText: typeof extractText$1;
|
|
58
|
+
declare const extractImages: typeof extractImages$1;
|
|
59
|
+
declare const renderPageAsImage: typeof renderPageAsImage$1;
|
|
48
60
|
|
|
49
|
-
export { defineUnPDFConfig, extractPDFText,
|
|
61
|
+
export { defineUnPDFConfig, extractImages, extractPDFText, extractText, getDocumentProxy, getMeta, getResolvedPDFJS, renderPageAsImage, resolvePDFJSImports };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { BinaryData, PDFDocumentProxy, DocumentInitParameters } from './types/src/display/api';
|
|
2
|
+
import * as canvas from 'canvas';
|
|
2
3
|
import * as _PDFJS from './types/src/pdf';
|
|
3
4
|
|
|
4
|
-
declare function
|
|
5
|
+
declare function getMeta$1(data: BinaryData | PDFDocumentProxy): Promise<{
|
|
5
6
|
info: Record<string, any>;
|
|
6
7
|
metadata: Record<string, any>;
|
|
7
8
|
}>;
|
|
8
9
|
|
|
9
|
-
declare function
|
|
10
|
+
declare function extractText$1(data: BinaryData | PDFDocumentProxy, options?: {
|
|
10
11
|
mergePages?: boolean;
|
|
11
12
|
}): Promise<{
|
|
12
13
|
totalPages: number;
|
|
13
14
|
text: string | string[];
|
|
14
15
|
}>;
|
|
15
16
|
|
|
16
|
-
declare function
|
|
17
|
+
declare function extractImages$1(data: BinaryData | PDFDocumentProxy, pageNumber: number): Promise<Uint8ClampedArray[]>;
|
|
18
|
+
declare function renderPageAsImage$1(data: BinaryData | PDFDocumentProxy, pageNumber: number, options?: {
|
|
19
|
+
canvas?: () => Promise<typeof canvas>;
|
|
20
|
+
/** @default 1 */
|
|
21
|
+
scale?: number;
|
|
22
|
+
width?: number;
|
|
23
|
+
height?: number;
|
|
24
|
+
}): Promise<ArrayBuffer>;
|
|
17
25
|
|
|
18
26
|
type PDFJS = typeof _PDFJS;
|
|
19
27
|
interface UnPDFConfiguration {
|
|
@@ -26,9 +34,11 @@ interface UnPDFConfiguration {
|
|
|
26
34
|
* // Use the legacy build
|
|
27
35
|
* () => import('pdfjs-dist/legacy/build/pdf.js')
|
|
28
36
|
*/
|
|
29
|
-
pdfjs?: () => Promise<
|
|
37
|
+
pdfjs?: () => Promise<any>;
|
|
30
38
|
}
|
|
31
39
|
|
|
40
|
+
declare function defineUnPDFConfig(options: UnPDFConfiguration): Promise<void>;
|
|
41
|
+
|
|
32
42
|
/**
|
|
33
43
|
* Returns a PDFDocumentProxy instance from a given binary data.
|
|
34
44
|
*
|
|
@@ -36,14 +46,16 @@ interface UnPDFConfiguration {
|
|
|
36
46
|
* - `isEvalSupported: false`
|
|
37
47
|
*/
|
|
38
48
|
declare function getDocumentProxy(data: BinaryData, options?: DocumentInitParameters): Promise<PDFDocumentProxy>;
|
|
39
|
-
declare function defineUnPDFConfig(options: UnPDFConfiguration): Promise<void>;
|
|
40
49
|
declare function getResolvedPDFJS(): Promise<PDFJS>;
|
|
41
|
-
declare function resolvePDFJSImports(pdfjsResolver?: () => Promise<
|
|
50
|
+
declare function resolvePDFJSImports(pdfjsResolver?: () => Promise<any>, { force }?: {
|
|
42
51
|
force?: boolean | undefined;
|
|
43
52
|
}): Promise<void>;
|
|
44
53
|
|
|
45
|
-
declare const
|
|
46
|
-
declare const
|
|
47
|
-
|
|
54
|
+
declare const getMeta: typeof getMeta$1;
|
|
55
|
+
declare const extractText: typeof extractText$1;
|
|
56
|
+
/** @deprecated Use `extractText` instead. */
|
|
57
|
+
declare const extractPDFText: typeof extractText$1;
|
|
58
|
+
declare const extractImages: typeof extractImages$1;
|
|
59
|
+
declare const renderPageAsImage: typeof renderPageAsImage$1;
|
|
48
60
|
|
|
49
|
-
export { defineUnPDFConfig, extractPDFText,
|
|
61
|
+
export { defineUnPDFConfig, extractImages, extractPDFText, extractText, getDocumentProxy, getMeta, getResolvedPDFJS, renderPageAsImage, resolvePDFJSImports };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { BinaryData, PDFDocumentProxy, DocumentInitParameters } from './types/src/display/api';
|
|
2
|
+
import * as canvas from 'canvas';
|
|
2
3
|
import * as _PDFJS from './types/src/pdf';
|
|
3
4
|
|
|
4
|
-
declare function
|
|
5
|
+
declare function getMeta$1(data: BinaryData | PDFDocumentProxy): Promise<{
|
|
5
6
|
info: Record<string, any>;
|
|
6
7
|
metadata: Record<string, any>;
|
|
7
8
|
}>;
|
|
8
9
|
|
|
9
|
-
declare function
|
|
10
|
+
declare function extractText$1(data: BinaryData | PDFDocumentProxy, options?: {
|
|
10
11
|
mergePages?: boolean;
|
|
11
12
|
}): Promise<{
|
|
12
13
|
totalPages: number;
|
|
13
14
|
text: string | string[];
|
|
14
15
|
}>;
|
|
15
16
|
|
|
16
|
-
declare function
|
|
17
|
+
declare function extractImages$1(data: BinaryData | PDFDocumentProxy, pageNumber: number): Promise<Uint8ClampedArray[]>;
|
|
18
|
+
declare function renderPageAsImage$1(data: BinaryData | PDFDocumentProxy, pageNumber: number, options?: {
|
|
19
|
+
canvas?: () => Promise<typeof canvas>;
|
|
20
|
+
/** @default 1 */
|
|
21
|
+
scale?: number;
|
|
22
|
+
width?: number;
|
|
23
|
+
height?: number;
|
|
24
|
+
}): Promise<ArrayBuffer>;
|
|
17
25
|
|
|
18
26
|
type PDFJS = typeof _PDFJS;
|
|
19
27
|
interface UnPDFConfiguration {
|
|
@@ -26,9 +34,11 @@ interface UnPDFConfiguration {
|
|
|
26
34
|
* // Use the legacy build
|
|
27
35
|
* () => import('pdfjs-dist/legacy/build/pdf.js')
|
|
28
36
|
*/
|
|
29
|
-
pdfjs?: () => Promise<
|
|
37
|
+
pdfjs?: () => Promise<any>;
|
|
30
38
|
}
|
|
31
39
|
|
|
40
|
+
declare function defineUnPDFConfig(options: UnPDFConfiguration): Promise<void>;
|
|
41
|
+
|
|
32
42
|
/**
|
|
33
43
|
* Returns a PDFDocumentProxy instance from a given binary data.
|
|
34
44
|
*
|
|
@@ -36,14 +46,16 @@ interface UnPDFConfiguration {
|
|
|
36
46
|
* - `isEvalSupported: false`
|
|
37
47
|
*/
|
|
38
48
|
declare function getDocumentProxy(data: BinaryData, options?: DocumentInitParameters): Promise<PDFDocumentProxy>;
|
|
39
|
-
declare function defineUnPDFConfig(options: UnPDFConfiguration): Promise<void>;
|
|
40
49
|
declare function getResolvedPDFJS(): Promise<PDFJS>;
|
|
41
|
-
declare function resolvePDFJSImports(pdfjsResolver?: () => Promise<
|
|
50
|
+
declare function resolvePDFJSImports(pdfjsResolver?: () => Promise<any>, { force }?: {
|
|
42
51
|
force?: boolean | undefined;
|
|
43
52
|
}): Promise<void>;
|
|
44
53
|
|
|
45
|
-
declare const
|
|
46
|
-
declare const
|
|
47
|
-
|
|
54
|
+
declare const getMeta: typeof getMeta$1;
|
|
55
|
+
declare const extractText: typeof extractText$1;
|
|
56
|
+
/** @deprecated Use `extractText` instead. */
|
|
57
|
+
declare const extractPDFText: typeof extractText$1;
|
|
58
|
+
declare const extractImages: typeof extractImages$1;
|
|
59
|
+
declare const renderPageAsImage: typeof renderPageAsImage$1;
|
|
48
60
|
|
|
49
|
-
export { defineUnPDFConfig, extractPDFText,
|
|
61
|
+
export { defineUnPDFConfig, extractImages, extractPDFText, extractText, getDocumentProxy, getMeta, getResolvedPDFJS, renderPageAsImage, resolvePDFJSImports };
|