@d0paminedriven/pdfdown-ocr 0.9.8 → 0.10.0
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 +79 -78
- package/index.d.ts +168 -152
- package/index.js +371 -93
- package/package.json +12 -14
package/README.md
CHANGED
|
@@ -62,50 +62,47 @@ This package exports everything from `@d0paminedriven/pdfdown` (text, images, an
|
|
|
62
62
|
export declare function extractTextWithOcrPerPage(
|
|
63
63
|
buffer: Buffer,
|
|
64
64
|
opts?: OcrOptions,
|
|
65
|
-
): Array<OcrPageText
|
|
65
|
+
): Array<OcrPageText>;
|
|
66
66
|
|
|
67
67
|
export declare function extractTextWithOcrPerPageAsync(
|
|
68
68
|
buffer: Buffer,
|
|
69
69
|
opts?: OcrOptions,
|
|
70
|
-
): Promise<Array<OcrPageText
|
|
70
|
+
): Promise<Array<OcrPageText>>;
|
|
71
71
|
|
|
72
72
|
// Full document extraction with OCR text fallback
|
|
73
|
-
export declare function pdfDocumentOcr(
|
|
74
|
-
buffer: Buffer,
|
|
75
|
-
opts?: OcrOptions,
|
|
76
|
-
): PdfDocumentOcr
|
|
73
|
+
export declare function pdfDocumentOcr(buffer: Buffer, opts?: OcrOptions): PdfDocumentOcr;
|
|
77
74
|
|
|
78
75
|
export declare function pdfDocumentOcrAsync(
|
|
79
76
|
buffer: Buffer,
|
|
80
77
|
opts?: OcrOptions,
|
|
81
|
-
): Promise<PdfDocumentOcr
|
|
78
|
+
): Promise<PdfDocumentOcr>;
|
|
82
79
|
```
|
|
83
80
|
|
|
84
81
|
### `PdfDown` class (includes OCR methods)
|
|
85
82
|
|
|
86
83
|
```typescript
|
|
87
84
|
export declare class PdfDown {
|
|
88
|
-
constructor(buffer: Buffer)
|
|
85
|
+
constructor(buffer: Buffer);
|
|
89
86
|
|
|
90
87
|
// ── Base methods ──
|
|
91
|
-
textPerPage(): Array<PageText
|
|
92
|
-
textPerPageAsync(): Promise<Array<PageText
|
|
93
|
-
imagesPerPage(): Array<PageImage
|
|
94
|
-
imagesPerPageAsync(): Promise<Array<PageImage
|
|
95
|
-
annotationsPerPage(): Array<PageAnnotation
|
|
96
|
-
annotationsPerPageAsync(): Promise<Array<PageAnnotation
|
|
97
|
-
structuredText(): Array<StructuredPageText
|
|
98
|
-
structuredTextAsync(): Promise<Array<StructuredPageText
|
|
99
|
-
metadata(): PdfMeta
|
|
100
|
-
metadataAsync(): Promise<PdfMeta
|
|
101
|
-
document(): PdfDocument
|
|
102
|
-
documentAsync(): Promise<PdfDocument
|
|
88
|
+
textPerPage(): Array<PageText>;
|
|
89
|
+
textPerPageAsync(): Promise<Array<PageText>>;
|
|
90
|
+
imagesPerPage(): Array<PageImage>;
|
|
91
|
+
imagesPerPageAsync(): Promise<Array<PageImage>>;
|
|
92
|
+
annotationsPerPage(): Array<PageAnnotation>;
|
|
93
|
+
annotationsPerPageAsync(): Promise<Array<PageAnnotation>>;
|
|
94
|
+
structuredText(): Array<StructuredPageText>;
|
|
95
|
+
structuredTextAsync(): Promise<Array<StructuredPageText>>;
|
|
96
|
+
metadata(): PdfMeta;
|
|
97
|
+
metadataAsync(): Promise<PdfMeta>;
|
|
98
|
+
document(): PdfDocument;
|
|
99
|
+
documentAsync(): Promise<PdfDocument>;
|
|
103
100
|
|
|
104
101
|
// ── OCR methods ──
|
|
105
|
-
textWithOcrPerPage(opts?: OcrOptions): Array<OcrPageText
|
|
106
|
-
textWithOcrPerPageAsync(opts?: OcrOptions): Promise<Array<OcrPageText
|
|
107
|
-
documentOcr(opts?: OcrOptions): PdfDocumentOcr
|
|
108
|
-
documentOcrAsync(opts?: OcrOptions): Promise<PdfDocumentOcr
|
|
102
|
+
textWithOcrPerPage(opts?: OcrOptions): Array<OcrPageText>;
|
|
103
|
+
textWithOcrPerPageAsync(opts?: OcrOptions): Promise<Array<OcrPageText>>;
|
|
104
|
+
documentOcr(opts?: OcrOptions): PdfDocumentOcr;
|
|
105
|
+
documentOcrAsync(opts?: OcrOptions): Promise<PdfDocumentOcr>;
|
|
109
106
|
}
|
|
110
107
|
```
|
|
111
108
|
|
|
@@ -113,46 +110,46 @@ export declare class PdfDown {
|
|
|
113
110
|
|
|
114
111
|
```typescript
|
|
115
112
|
export const enum TextSource {
|
|
116
|
-
Native =
|
|
117
|
-
Ocr =
|
|
113
|
+
Native = "Native",
|
|
114
|
+
Ocr = "Ocr",
|
|
118
115
|
}
|
|
119
116
|
|
|
120
117
|
export interface OcrPageText {
|
|
121
|
-
page: number
|
|
122
|
-
text: string
|
|
123
|
-
source: TextSource
|
|
118
|
+
page: number;
|
|
119
|
+
text: string;
|
|
120
|
+
source: TextSource;
|
|
124
121
|
}
|
|
125
122
|
|
|
126
123
|
export interface OcrStructuredPageText {
|
|
127
|
-
page: number
|
|
128
|
-
header: string
|
|
129
|
-
body: string
|
|
130
|
-
footer: string
|
|
131
|
-
source: TextSource
|
|
124
|
+
page: number;
|
|
125
|
+
header: string;
|
|
126
|
+
body: string;
|
|
127
|
+
footer: string;
|
|
128
|
+
source: TextSource;
|
|
132
129
|
}
|
|
133
130
|
|
|
134
131
|
export interface OcrOptions {
|
|
135
|
-
lang?: string
|
|
136
|
-
minTextLength?: number // non-whitespace char threshold before OCR fallback, default 1
|
|
137
|
-
maxThreads?: number
|
|
132
|
+
lang?: string; // Tesseract language code, default "eng"
|
|
133
|
+
minTextLength?: number; // non-whitespace char threshold before OCR fallback, default 1
|
|
134
|
+
maxThreads?: number; // cap on Rayon threads for OCR parallelism, default 4, clamped to [1, available CPUs]
|
|
138
135
|
}
|
|
139
136
|
|
|
140
137
|
export interface PdfDocumentOcr {
|
|
141
|
-
version: string
|
|
142
|
-
isLinearized: boolean
|
|
143
|
-
pageCount: number
|
|
144
|
-
creator?: string
|
|
145
|
-
producer?: string
|
|
146
|
-
creationDate?: string
|
|
147
|
-
modificationDate?: string
|
|
148
|
-
totalImages: number
|
|
149
|
-
totalAnnotations: number
|
|
150
|
-
imagePages: Array<number
|
|
151
|
-
annotationPages: Array<number
|
|
152
|
-
text: Array<OcrPageText
|
|
153
|
-
structuredText: Array<OcrStructuredPageText
|
|
154
|
-
images: Array<PageImage
|
|
155
|
-
annotations: Array<PageAnnotation
|
|
138
|
+
version: string;
|
|
139
|
+
isLinearized: boolean;
|
|
140
|
+
pageCount: number;
|
|
141
|
+
creator?: string;
|
|
142
|
+
producer?: string;
|
|
143
|
+
creationDate?: string;
|
|
144
|
+
modificationDate?: string;
|
|
145
|
+
totalImages: number;
|
|
146
|
+
totalAnnotations: number;
|
|
147
|
+
imagePages: Array<number>;
|
|
148
|
+
annotationPages: Array<number>;
|
|
149
|
+
text: Array<OcrPageText>;
|
|
150
|
+
structuredText: Array<OcrStructuredPageText>;
|
|
151
|
+
images: Array<PageImage>;
|
|
152
|
+
annotations: Array<PageAnnotation>;
|
|
156
153
|
}
|
|
157
154
|
```
|
|
158
155
|
|
|
@@ -163,41 +160,41 @@ export interface PdfDocumentOcr {
|
|
|
163
160
|
### Standalone
|
|
164
161
|
|
|
165
162
|
```typescript
|
|
166
|
-
import { readFile } from
|
|
167
|
-
import { extractTextWithOcrPerPageAsync } from
|
|
163
|
+
import { readFile } from "fs/promises";
|
|
164
|
+
import { extractTextWithOcrPerPageAsync } from "@d0paminedriven/pdfdown-ocr";
|
|
168
165
|
|
|
169
|
-
const pdf = await readFile(
|
|
170
|
-
const pages = await extractTextWithOcrPerPageAsync(pdf, { lang:
|
|
166
|
+
const pdf = await readFile("scanned-document.pdf");
|
|
167
|
+
const pages = await extractTextWithOcrPerPageAsync(pdf, { lang: "eng", minTextLength: 10 });
|
|
171
168
|
|
|
172
169
|
for (const { page, text, source } of pages) {
|
|
173
|
-
console.log(`Page ${page} [${source}]: ${text.slice(0, 100)}...`)
|
|
170
|
+
console.log(`Page ${page} [${source}]: ${text.slice(0, 100)}...`);
|
|
174
171
|
}
|
|
175
172
|
```
|
|
176
173
|
|
|
177
174
|
### Class-based (parse once, extract many)
|
|
178
175
|
|
|
179
176
|
```typescript
|
|
180
|
-
import { readFile } from
|
|
181
|
-
import { PdfDown } from
|
|
177
|
+
import { readFile } from "fs/promises";
|
|
178
|
+
import { PdfDown } from "@d0paminedriven/pdfdown-ocr";
|
|
182
179
|
|
|
183
|
-
const pdf = new PdfDown(await readFile(
|
|
180
|
+
const pdf = new PdfDown(await readFile("scanned-document.pdf"));
|
|
184
181
|
|
|
185
182
|
// OCR text extraction
|
|
186
|
-
const pages = await pdf.textWithOcrPerPageAsync({ lang:
|
|
183
|
+
const pages = await pdf.textWithOcrPerPageAsync({ lang: "eng", minTextLength: 10 });
|
|
187
184
|
|
|
188
185
|
// All base methods work too
|
|
189
|
-
const images = await pdf.imagesPerPageAsync()
|
|
190
|
-
const meta = pdf.metadata()
|
|
186
|
+
const images = await pdf.imagesPerPageAsync();
|
|
187
|
+
const meta = pdf.metadata();
|
|
191
188
|
```
|
|
192
189
|
|
|
193
190
|
### Extract everything with OCR in one call
|
|
194
191
|
|
|
195
192
|
```typescript
|
|
196
|
-
import { readFile } from
|
|
197
|
-
import { PdfDown } from
|
|
193
|
+
import { readFile } from "fs/promises";
|
|
194
|
+
import { PdfDown } from "@d0paminedriven/pdfdown-ocr";
|
|
198
195
|
|
|
199
|
-
const pdf = new PdfDown(await readFile(
|
|
200
|
-
const result = await pdf.documentOcrAsync({ minTextLength: 10 })
|
|
196
|
+
const pdf = new PdfDown(await readFile("scanned-document.pdf"));
|
|
197
|
+
const result = await pdf.documentOcrAsync({ minTextLength: 10 });
|
|
201
198
|
|
|
202
199
|
// result.text — OcrPageText[] (page, text, source per page)
|
|
203
200
|
// result.structuredText — OcrStructuredPageText[] (header/body/footer + source per page)
|
|
@@ -209,24 +206,24 @@ const result = await pdf.documentOcrAsync({ minTextLength: 10 })
|
|
|
209
206
|
### Combined: OCR text + images for multimodal pipelines
|
|
210
207
|
|
|
211
208
|
```typescript
|
|
212
|
-
import { readFile } from
|
|
213
|
-
import { PdfDown } from
|
|
209
|
+
import { readFile } from "fs/promises";
|
|
210
|
+
import { PdfDown } from "@d0paminedriven/pdfdown-ocr";
|
|
214
211
|
|
|
215
|
-
const pdf = new PdfDown(await readFile(
|
|
212
|
+
const pdf = new PdfDown(await readFile("scanned-document.pdf"));
|
|
216
213
|
|
|
217
214
|
const [ocrText, images] = await Promise.all([
|
|
218
215
|
pdf.textWithOcrPerPageAsync({ minTextLength: 10 }),
|
|
219
216
|
pdf.imagesPerPageAsync(),
|
|
220
|
-
])
|
|
217
|
+
]);
|
|
221
218
|
|
|
222
|
-
const imagesByPage = Map.groupBy(images, (img) => img.page)
|
|
219
|
+
const imagesByPage = Map.groupBy(images, (img) => img.page);
|
|
223
220
|
|
|
224
221
|
for (const { page, text, source } of ocrText) {
|
|
225
222
|
const pageImages = (imagesByPage.get(page) ?? []).map((img) => ({
|
|
226
|
-
dataUrl: `data:image/png;base64,${img.data.toString(
|
|
223
|
+
dataUrl: `data:image/png;base64,${img.data.toString("base64")}`,
|
|
227
224
|
width: img.width,
|
|
228
225
|
height: img.height,
|
|
229
|
-
}))
|
|
226
|
+
}));
|
|
230
227
|
// Send { page, text, source, images: pageImages } to your embedding pipeline
|
|
231
228
|
}
|
|
232
229
|
```
|
|
@@ -235,9 +232,9 @@ for (const { page, text, source } of ocrText) {
|
|
|
235
232
|
|
|
236
233
|
Both methods extract everything from a PDF in a single call. The difference is how text is extracted:
|
|
237
234
|
|
|
238
|
-
| Method
|
|
239
|
-
|
|
240
|
-
| `document()` / `documentAsync()`
|
|
235
|
+
| Method | Text extraction | Return type | Use when |
|
|
236
|
+
| -------------------------------------- | ------------------------ | ---------------- | ---------------------------------------- |
|
|
237
|
+
| `document()` / `documentAsync()` | Native PDF text only | `PdfDocument` | PDF has selectable text |
|
|
241
238
|
| `documentOcr()` / `documentOcrAsync()` | Native with OCR fallback | `PdfDocumentOcr` | PDF may contain scanned/image-only pages |
|
|
242
239
|
|
|
243
240
|
`PdfDocumentOcr` uses `OcrPageText` (with `source: 'Native' | 'Ocr'`) and `OcrStructuredPageText` (with header/body/footer split plus source) instead of the base `PageText` and `StructuredPageText` types. Images, annotations, and metadata are identical in both.
|
|
@@ -256,9 +253,13 @@ Both methods extract everything from a PDF in a single call. The difference is h
|
|
|
256
253
|
|
|
257
254
|
Prebuilt binaries are provided for:
|
|
258
255
|
|
|
259
|
-
- macOS (
|
|
256
|
+
- macOS (ARM64)
|
|
260
257
|
- Linux glibc (x64, ARM64)
|
|
261
258
|
|
|
259
|
+
Intel macOS is not built: the OCR package links the system Tesseract, and Homebrew no longer
|
|
260
|
+
ships Intel bottles, so there is no supported way to obtain the library on that platform.
|
|
261
|
+
The base `@d0paminedriven/pdfdown` package still ships an Intel macOS binary.
|
|
262
|
+
|
|
262
263
|
## Relationship to `@d0paminedriven/pdfdown`
|
|
263
264
|
|
|
264
265
|
Same Rust codebase, compiled with the `ocr` Cargo feature flag enabled. This package is a strict superset -- you can use it as a drop-in replacement for the base package if you need OCR capabilities.
|
package/index.d.ts
CHANGED
|
@@ -1,218 +1,234 @@
|
|
|
1
1
|
/* auto-generated by NAPI-RS */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
export declare class PdfDown {
|
|
4
|
-
constructor(buffer: Buffer)
|
|
5
|
-
textPerPage(): Array<PageText>
|
|
6
|
-
imagesPerPage(): Array<PageImage>
|
|
7
|
-
annotationsPerPage(): Array<PageAnnotation>
|
|
8
|
-
metadata(): PdfMeta
|
|
9
|
-
textPerPageAsync(): Promise<Array<PageText>>
|
|
10
|
-
imagesPerPageAsync(): Promise<Array<PageImage>>
|
|
11
|
-
annotationsPerPageAsync(): Promise<Array<PageAnnotation>>
|
|
12
|
-
metadataAsync(): Promise<PdfMeta>
|
|
13
|
-
document(): PdfDocument
|
|
14
|
-
documentAsync(): Promise<PdfDocument>
|
|
15
|
-
structuredText(): Array<StructuredPageText>
|
|
16
|
-
structuredTextAsync(): Promise<Array<StructuredPageText>>
|
|
17
|
-
textWithOcrPerPage(opts?: OcrOptions | undefined | null): Array<OcrPageText>
|
|
18
|
-
textWithOcrPerPageAsync(opts?: OcrOptions | undefined | null): Promise<Array<OcrPageText>>
|
|
19
|
-
documentOcr(opts?: OcrOptions | undefined | null): PdfDocumentOcr
|
|
20
|
-
documentOcrAsync(opts?: OcrOptions | undefined | null): Promise<PdfDocumentOcr>
|
|
21
|
-
renderPagesAsync(opts?: RenderOptions | undefined | null): Promise<Array<RenderedPage>>
|
|
22
|
-
}
|
|
23
3
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Which binding artifact the generated loader actually loaded: `'native'` for
|
|
6
|
+
* a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
|
|
7
|
+
* flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
|
|
8
|
+
* can point the loader at a WASI artifact this package does not build itself.
|
|
9
|
+
*/
|
|
10
|
+
export declare const __napiBindingTarget: "native" | "wasm32-wasi" | "wasm32-wasip1";
|
|
29
11
|
|
|
30
|
-
export declare
|
|
12
|
+
export declare class PdfDown {
|
|
13
|
+
constructor(buffer: Buffer);
|
|
14
|
+
textPerPage(): Array<PageText>;
|
|
15
|
+
imagesPerPage(): Array<PageImage>;
|
|
16
|
+
annotationsPerPage(): Array<PageAnnotation>;
|
|
17
|
+
metadata(): PdfMeta;
|
|
18
|
+
textPerPageAsync(): Promise<Array<PageText>>;
|
|
19
|
+
imagesPerPageAsync(): Promise<Array<PageImage>>;
|
|
20
|
+
annotationsPerPageAsync(): Promise<Array<PageAnnotation>>;
|
|
21
|
+
metadataAsync(): Promise<PdfMeta>;
|
|
22
|
+
document(): PdfDocument;
|
|
23
|
+
documentAsync(): Promise<PdfDocument>;
|
|
24
|
+
structuredText(): Array<StructuredPageText>;
|
|
25
|
+
structuredTextAsync(): Promise<Array<StructuredPageText>>;
|
|
26
|
+
textWithOcrPerPage(opts?: OcrOptions | undefined | null): Array<OcrPageText>;
|
|
27
|
+
textWithOcrPerPageAsync(opts?: OcrOptions | undefined | null): Promise<Array<OcrPageText>>;
|
|
28
|
+
documentOcr(opts?: OcrOptions | undefined | null): PdfDocumentOcr;
|
|
29
|
+
documentOcrAsync(opts?: OcrOptions | undefined | null): Promise<PdfDocumentOcr>;
|
|
30
|
+
renderPagesAsync(opts?: RenderOptions | undefined | null): Promise<Array<RenderedPage>>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type BoxType = "CropBox" | "MediaBox" | "Unknown";
|
|
34
|
+
|
|
35
|
+
export declare function capabilities(): Capabilities;
|
|
31
36
|
|
|
32
37
|
export interface Capabilities {
|
|
33
|
-
ocr: boolean
|
|
34
|
-
render: boolean
|
|
38
|
+
ocr: boolean;
|
|
39
|
+
render: boolean;
|
|
35
40
|
}
|
|
36
41
|
|
|
37
|
-
export declare function extractAnnotationsPerPage(buffer: Buffer): Array<PageAnnotation
|
|
42
|
+
export declare function extractAnnotationsPerPage(buffer: Buffer): Array<PageAnnotation>;
|
|
38
43
|
|
|
39
|
-
export declare function extractAnnotationsPerPageAsync(
|
|
44
|
+
export declare function extractAnnotationsPerPageAsync(
|
|
45
|
+
buffer: Buffer,
|
|
46
|
+
): Promise<Array<PageAnnotation>>;
|
|
40
47
|
|
|
41
|
-
export declare function extractImagesPerPage(buffer: Buffer): Array<PageImage
|
|
48
|
+
export declare function extractImagesPerPage(buffer: Buffer): Array<PageImage>;
|
|
42
49
|
|
|
43
|
-
export declare function extractImagesPerPageAsync(buffer: Buffer): Promise<Array<PageImage
|
|
50
|
+
export declare function extractImagesPerPageAsync(buffer: Buffer): Promise<Array<PageImage>>;
|
|
44
51
|
|
|
45
|
-
export declare function extractStructuredTextPerPage(buffer: Buffer): Array<StructuredPageText
|
|
52
|
+
export declare function extractStructuredTextPerPage(buffer: Buffer): Array<StructuredPageText>;
|
|
46
53
|
|
|
47
|
-
export declare function extractStructuredTextPerPageAsync(
|
|
54
|
+
export declare function extractStructuredTextPerPageAsync(
|
|
55
|
+
buffer: Buffer,
|
|
56
|
+
): Promise<Array<StructuredPageText>>;
|
|
48
57
|
|
|
49
|
-
export declare function extractTextPerPage(buffer: Buffer): Array<PageText
|
|
58
|
+
export declare function extractTextPerPage(buffer: Buffer): Array<PageText>;
|
|
50
59
|
|
|
51
|
-
export declare function extractTextPerPageAsync(buffer: Buffer): Promise<Array<PageText
|
|
60
|
+
export declare function extractTextPerPageAsync(buffer: Buffer): Promise<Array<PageText>>;
|
|
52
61
|
|
|
53
|
-
export declare function extractTextWithOcrPerPage(
|
|
62
|
+
export declare function extractTextWithOcrPerPage(
|
|
63
|
+
buffer: Buffer,
|
|
64
|
+
opts?: OcrOptions | undefined | null,
|
|
65
|
+
): Array<OcrPageText>;
|
|
54
66
|
|
|
55
|
-
export declare function extractTextWithOcrPerPageAsync(
|
|
67
|
+
export declare function extractTextWithOcrPerPageAsync(
|
|
68
|
+
buffer: Buffer,
|
|
69
|
+
opts?: OcrOptions | undefined | null,
|
|
70
|
+
): Promise<Array<OcrPageText>>;
|
|
56
71
|
|
|
57
72
|
export interface OcrOptions {
|
|
58
|
-
lang?: string
|
|
59
|
-
minTextLength?: number
|
|
60
|
-
maxThreads?: number
|
|
61
|
-
render?: RenderMode
|
|
62
|
-
renderDpi?: number
|
|
63
|
-
pdfiumPath?: string
|
|
73
|
+
lang?: string;
|
|
74
|
+
minTextLength?: number;
|
|
75
|
+
maxThreads?: number;
|
|
76
|
+
render?: RenderMode;
|
|
77
|
+
renderDpi?: number;
|
|
78
|
+
pdfiumPath?: string;
|
|
64
79
|
}
|
|
65
80
|
|
|
66
81
|
export interface OcrPageText {
|
|
67
|
-
page: number
|
|
68
|
-
text: string
|
|
69
|
-
source: TextSource
|
|
82
|
+
page: number;
|
|
83
|
+
text: string;
|
|
84
|
+
source: TextSource;
|
|
70
85
|
}
|
|
71
86
|
|
|
72
87
|
export interface OcrStructuredPageText {
|
|
73
|
-
page: number
|
|
74
|
-
header: string
|
|
75
|
-
body: string
|
|
76
|
-
footer: string
|
|
77
|
-
source: TextSource
|
|
88
|
+
page: number;
|
|
89
|
+
header: string;
|
|
90
|
+
body: string;
|
|
91
|
+
footer: string;
|
|
92
|
+
source: TextSource;
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
export interface PageAnnotation {
|
|
81
|
-
page: number
|
|
82
|
-
subtype: string
|
|
83
|
-
rect: Array<number
|
|
84
|
-
uri?: string
|
|
85
|
-
dest?: string
|
|
86
|
-
content?: string
|
|
96
|
+
page: number;
|
|
97
|
+
subtype: string;
|
|
98
|
+
rect: Array<number>;
|
|
99
|
+
uri?: string;
|
|
100
|
+
dest?: string;
|
|
101
|
+
content?: string;
|
|
87
102
|
}
|
|
88
103
|
|
|
89
104
|
export interface PageBox {
|
|
90
105
|
/** Number of pages that share these dimensions. */
|
|
91
|
-
pageCount: number
|
|
92
|
-
left: number
|
|
93
|
-
bottom: number
|
|
94
|
-
right: number
|
|
95
|
-
top: number
|
|
96
|
-
width: number
|
|
97
|
-
height: number
|
|
98
|
-
boxType: BoxType
|
|
106
|
+
pageCount: number;
|
|
107
|
+
left: number;
|
|
108
|
+
bottom: number;
|
|
109
|
+
right: number;
|
|
110
|
+
top: number;
|
|
111
|
+
width: number;
|
|
112
|
+
height: number;
|
|
113
|
+
boxType: BoxType;
|
|
99
114
|
/**
|
|
100
115
|
* Present only on non-dominant boxes — lists the specific pages with these
|
|
101
116
|
* dimensions. `None` on the first (most frequent) entry means "all pages
|
|
102
117
|
* not listed in any other entry's `pages` array."
|
|
103
118
|
*/
|
|
104
|
-
pages?: Array<number
|
|
119
|
+
pages?: Array<number>;
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
export interface PageImage {
|
|
108
|
-
page: number
|
|
109
|
-
imageIndex: number
|
|
110
|
-
width: number
|
|
111
|
-
height: number
|
|
112
|
-
data: Buffer
|
|
113
|
-
colorSpace: string
|
|
114
|
-
bitsPerComponent: number
|
|
115
|
-
filter: string
|
|
116
|
-
xobjectName: string
|
|
117
|
-
objectId: string
|
|
123
|
+
page: number;
|
|
124
|
+
imageIndex: number;
|
|
125
|
+
width: number;
|
|
126
|
+
height: number;
|
|
127
|
+
data: Buffer;
|
|
128
|
+
colorSpace: string;
|
|
129
|
+
bitsPerComponent: number;
|
|
130
|
+
filter: string;
|
|
131
|
+
xobjectName: string;
|
|
132
|
+
objectId: string;
|
|
118
133
|
}
|
|
119
134
|
|
|
120
135
|
export interface PageText {
|
|
121
|
-
page: number
|
|
122
|
-
text: string
|
|
136
|
+
page: number;
|
|
137
|
+
text: string;
|
|
123
138
|
}
|
|
124
139
|
|
|
125
|
-
export declare function pdfDocument(buffer: Buffer): PdfDocument
|
|
140
|
+
export declare function pdfDocument(buffer: Buffer): PdfDocument;
|
|
126
141
|
|
|
127
142
|
export interface PdfDocument {
|
|
128
|
-
version: string
|
|
129
|
-
isLinearized: boolean
|
|
130
|
-
pageCount: number
|
|
131
|
-
creator?: string
|
|
132
|
-
producer?: string
|
|
133
|
-
creationDate?: string
|
|
134
|
-
modificationDate?: string
|
|
135
|
-
pageBoxes: Array<PageBox
|
|
136
|
-
totalImages: number
|
|
137
|
-
totalAnnotations: number
|
|
138
|
-
imagePages: Array<number
|
|
139
|
-
annotationPages: Array<number
|
|
140
|
-
text: Array<PageText
|
|
141
|
-
structuredText: Array<StructuredPageText
|
|
142
|
-
images: Array<PageImage
|
|
143
|
-
annotations: Array<PageAnnotation
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export declare function pdfDocumentAsync(buffer: Buffer): Promise<PdfDocument
|
|
147
|
-
|
|
148
|
-
export declare function pdfDocumentOcr(
|
|
143
|
+
version: string;
|
|
144
|
+
isLinearized: boolean;
|
|
145
|
+
pageCount: number;
|
|
146
|
+
creator?: string;
|
|
147
|
+
producer?: string;
|
|
148
|
+
creationDate?: string;
|
|
149
|
+
modificationDate?: string;
|
|
150
|
+
pageBoxes: Array<PageBox>;
|
|
151
|
+
totalImages: number;
|
|
152
|
+
totalAnnotations: number;
|
|
153
|
+
imagePages: Array<number>;
|
|
154
|
+
annotationPages: Array<number>;
|
|
155
|
+
text: Array<PageText>;
|
|
156
|
+
structuredText: Array<StructuredPageText>;
|
|
157
|
+
images: Array<PageImage>;
|
|
158
|
+
annotations: Array<PageAnnotation>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export declare function pdfDocumentAsync(buffer: Buffer): Promise<PdfDocument>;
|
|
162
|
+
|
|
163
|
+
export declare function pdfDocumentOcr(
|
|
164
|
+
buffer: Buffer,
|
|
165
|
+
opts?: OcrOptions | undefined | null,
|
|
166
|
+
): PdfDocumentOcr;
|
|
149
167
|
|
|
150
168
|
export interface PdfDocumentOcr {
|
|
151
|
-
version: string
|
|
152
|
-
isLinearized: boolean
|
|
153
|
-
pageCount: number
|
|
154
|
-
creator?: string
|
|
155
|
-
producer?: string
|
|
156
|
-
creationDate?: string
|
|
157
|
-
modificationDate?: string
|
|
158
|
-
pageBoxes: Array<PageBox
|
|
159
|
-
totalImages: number
|
|
160
|
-
totalAnnotations: number
|
|
161
|
-
imagePages: Array<number
|
|
162
|
-
annotationPages: Array<number
|
|
163
|
-
text: Array<OcrPageText
|
|
164
|
-
structuredText: Array<OcrStructuredPageText
|
|
165
|
-
images: Array<PageImage
|
|
166
|
-
annotations: Array<PageAnnotation
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export declare function pdfDocumentOcrAsync(
|
|
169
|
+
version: string;
|
|
170
|
+
isLinearized: boolean;
|
|
171
|
+
pageCount: number;
|
|
172
|
+
creator?: string;
|
|
173
|
+
producer?: string;
|
|
174
|
+
creationDate?: string;
|
|
175
|
+
modificationDate?: string;
|
|
176
|
+
pageBoxes: Array<PageBox>;
|
|
177
|
+
totalImages: number;
|
|
178
|
+
totalAnnotations: number;
|
|
179
|
+
imagePages: Array<number>;
|
|
180
|
+
annotationPages: Array<number>;
|
|
181
|
+
text: Array<OcrPageText>;
|
|
182
|
+
structuredText: Array<OcrStructuredPageText>;
|
|
183
|
+
images: Array<PageImage>;
|
|
184
|
+
annotations: Array<PageAnnotation>;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export declare function pdfDocumentOcrAsync(
|
|
188
|
+
buffer: Buffer,
|
|
189
|
+
opts?: OcrOptions | undefined | null,
|
|
190
|
+
): Promise<PdfDocumentOcr>;
|
|
170
191
|
|
|
171
192
|
export interface PdfMeta {
|
|
172
|
-
pageCount: number
|
|
173
|
-
version: string
|
|
174
|
-
isLinearized: boolean
|
|
175
|
-
creator?: string
|
|
176
|
-
producer?: string
|
|
177
|
-
creationDate?: string
|
|
178
|
-
modificationDate?: string
|
|
179
|
-
pageBoxes: Array<PageBox
|
|
193
|
+
pageCount: number;
|
|
194
|
+
version: string;
|
|
195
|
+
isLinearized: boolean;
|
|
196
|
+
creator?: string;
|
|
197
|
+
producer?: string;
|
|
198
|
+
creationDate?: string;
|
|
199
|
+
modificationDate?: string;
|
|
200
|
+
pageBoxes: Array<PageBox>;
|
|
180
201
|
}
|
|
181
202
|
|
|
182
|
-
export declare function pdfMetadata(buffer: Buffer): PdfMeta
|
|
203
|
+
export declare function pdfMetadata(buffer: Buffer): PdfMeta;
|
|
183
204
|
|
|
184
|
-
export declare function pdfMetadataAsync(buffer: Buffer): Promise<PdfMeta
|
|
205
|
+
export declare function pdfMetadataAsync(buffer: Buffer): Promise<PdfMeta>;
|
|
185
206
|
|
|
186
207
|
export interface RenderedPage {
|
|
187
|
-
page: number
|
|
188
|
-
width: number
|
|
189
|
-
height: number
|
|
190
|
-
dpi: number
|
|
191
|
-
data: Buffer
|
|
208
|
+
page: number;
|
|
209
|
+
width: number;
|
|
210
|
+
height: number;
|
|
211
|
+
dpi: number;
|
|
212
|
+
data: Buffer;
|
|
192
213
|
}
|
|
193
214
|
|
|
194
|
-
export
|
|
195
|
-
Auto = 'Auto',
|
|
196
|
-
Never = 'Never',
|
|
197
|
-
Always = 'Always'
|
|
198
|
-
}
|
|
215
|
+
export type RenderMode = "Auto" | "Never" | "Always";
|
|
199
216
|
|
|
200
217
|
export interface RenderOptions {
|
|
201
|
-
dpi?: number
|
|
202
|
-
mode?: RenderMode
|
|
218
|
+
dpi?: number;
|
|
219
|
+
mode?: RenderMode;
|
|
203
220
|
}
|
|
204
221
|
|
|
205
|
-
export declare function renderPagesAsync(
|
|
222
|
+
export declare function renderPagesAsync(
|
|
223
|
+
buffer: Buffer,
|
|
224
|
+
opts?: RenderOptions | undefined | null,
|
|
225
|
+
): Promise<Array<RenderedPage>>;
|
|
206
226
|
|
|
207
227
|
export interface StructuredPageText {
|
|
208
|
-
page: number
|
|
209
|
-
header: string
|
|
210
|
-
body: string
|
|
211
|
-
footer: string
|
|
228
|
+
page: number;
|
|
229
|
+
header: string;
|
|
230
|
+
body: string;
|
|
231
|
+
footer: string;
|
|
212
232
|
}
|
|
213
233
|
|
|
214
|
-
export
|
|
215
|
-
Native = 'Native',
|
|
216
|
-
Ocr = 'Ocr',
|
|
217
|
-
Rendered = 'Rendered'
|
|
218
|
-
}
|
|
234
|
+
export type TextSource = "Native" | "Ocr" | "Rendered";
|