@d0paminedriven/pdfdown-ocr 0.14.0 → 0.15.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 +373 -0
- package/index.d.ts +2 -0
- package/package.json +5 -5
- package/pdfdown_ocr.napi.js +56 -56
package/README.md
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
# @d0paminedriven/pdfdown-ocr
|
|
2
|
+
|
|
3
|
+
[](https://github.com/DopamineDriven/assetdown/actions/workflows/pdfdown-node.yml)
|
|
4
|
+
|
|
5
|
+
Rust-powered PDF extraction for Node.js with Tesseract OCR fallback for image-only pages. A superset of [`@d0paminedriven/pdfdown`](https://www.npmjs.com/package/@d0paminedriven/pdfdown) -- includes all base extraction APIs (text, positioned text, images, annotations, form fields, attachments, invoice fields, structured text, metadata, page rendering) plus OCR.
|
|
6
|
+
|
|
7
|
+
**System requirement:** [Tesseract](https://github.com/tesseract-ocr/tesseract) 5.x must be installed on the host.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @d0paminedriven/pdfdown-ocr
|
|
13
|
+
yarn add @d0paminedriven/pdfdown-ocr
|
|
14
|
+
pnpm add @d0paminedriven/pdfdown-ocr
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
node ≥ 24. The package is an ES module.
|
|
18
|
+
|
|
19
|
+
### Tesseract setup
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Ubuntu/Debian (22.04 ships pre v5 > -- use the PPA for 5.x)
|
|
23
|
+
sudo add-apt-repository ppa:alex-p/tesseract-ocr5
|
|
24
|
+
sudo apt update
|
|
25
|
+
sudo apt install tesseract-ocr tesseract-ocr-eng -y
|
|
26
|
+
# Optional: all language packs
|
|
27
|
+
# sudo apt install tesseract-ocr-all
|
|
28
|
+
|
|
29
|
+
# macOS
|
|
30
|
+
brew install tesseract
|
|
31
|
+
|
|
32
|
+
# Arch
|
|
33
|
+
sudo pacman -S tesseract tesseract-data-eng
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Verify with `tesseract --version` -- you should see 5.x.
|
|
37
|
+
|
|
38
|
+
### Tessdata auto-detection
|
|
39
|
+
|
|
40
|
+
The package automatically detects the tessdata directory at runtime by parsing the output of `tesseract --list-langs`. The detected path is cached for the lifetime of the process using a `OnceLock<Option<String>>` -- no global environment mutation, fully thread-safe.
|
|
41
|
+
|
|
42
|
+
**Resolution order:**
|
|
43
|
+
|
|
44
|
+
1. `TESSDATA_PREFIX` environment variable (if set, used as-is -- no auto-detection runs)
|
|
45
|
+
2. Auto-detection via `tesseract --list-langs` (parses the path from `List of available languages in "/path/to/tessdata/"`)
|
|
46
|
+
3. Tesseract's compiled-in default (if neither of the above yields a path)
|
|
47
|
+
|
|
48
|
+
Most users will not need to set `TESSDATA_PREFIX` at all. The auto-detection handles standard installations on Ubuntu (`/usr/share/tesseract-ocr/5/tessdata/`), macOS Homebrew (`/opt/homebrew/share/tessdata/`), Arch, and any other layout where `tesseract` is on `PATH`.
|
|
49
|
+
|
|
50
|
+
Set `TESSDATA_PREFIX` explicitly only if:
|
|
51
|
+
|
|
52
|
+
- Tesseract is not on `PATH` but the tessdata directory exists elsewhere
|
|
53
|
+
- You want to override the detected path (e.g., pointing to a custom-trained data directory)
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Override example (not usually needed)
|
|
57
|
+
export TESSDATA_PREFIX="/opt/custom/tessdata"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## API
|
|
61
|
+
|
|
62
|
+
This package exports everything from `@d0paminedriven/pdfdown` (text, positioned text, images, annotations, AcroForm fields, attachments, embedded e-invoice extraction, invoice fields, structured text, metadata with page and paper sizes, page rendering, `capabilities()` -- sync and async), plus the OCR-specific APIs below. `PdfDocumentOcr` carries the same `pageBoxes`, `form`, `formFields`, `totalFormFields` and `formFieldPages` as `PdfDocument`; form extraction is read-only and needs neither Tesseract nor PDFium. See the [base package docs](https://www.npmjs.com/package/@d0paminedriven/pdfdown) for the full base API.
|
|
63
|
+
|
|
64
|
+
### OCR standalone functions
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
// Per-page OCR text extraction
|
|
68
|
+
export declare function extractTextWithOcrPerPage(
|
|
69
|
+
buffer: Buffer,
|
|
70
|
+
opts?: OcrOptions
|
|
71
|
+
): Array<OcrPageText>;
|
|
72
|
+
|
|
73
|
+
export declare function extractTextWithOcrPerPageAsync(
|
|
74
|
+
buffer: Buffer,
|
|
75
|
+
opts?: OcrOptions
|
|
76
|
+
): Promise<Array<OcrPageText>>;
|
|
77
|
+
|
|
78
|
+
// Full document extraction with OCR text fallback
|
|
79
|
+
export declare function pdfDocumentOcr(
|
|
80
|
+
buffer: Buffer,
|
|
81
|
+
opts?: OcrOptions
|
|
82
|
+
): PdfDocumentOcr;
|
|
83
|
+
|
|
84
|
+
export declare function pdfDocumentOcrAsync(
|
|
85
|
+
buffer: Buffer,
|
|
86
|
+
opts?: OcrOptions
|
|
87
|
+
): Promise<PdfDocumentOcr>;
|
|
88
|
+
|
|
89
|
+
// Positioned words and lines with the same three-tier cascade
|
|
90
|
+
export declare function extractLayoutWithOcrPerPage(
|
|
91
|
+
buffer: Buffer,
|
|
92
|
+
opts?: OcrOptions
|
|
93
|
+
): Array<PageLayout>;
|
|
94
|
+
|
|
95
|
+
export declare function extractLayoutWithOcrPerPageAsync(
|
|
96
|
+
buffer: Buffer,
|
|
97
|
+
opts?: OcrOptions
|
|
98
|
+
): Promise<Array<PageLayout>>;
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### `PdfDown` class (includes OCR methods)
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
export declare class PdfDown {
|
|
105
|
+
constructor(buffer: Buffer);
|
|
106
|
+
static openAsync(buffer: Buffer): Promise<PdfDown>;
|
|
107
|
+
|
|
108
|
+
// ── Base methods ──
|
|
109
|
+
textPerPage(): Array<PageText>;
|
|
110
|
+
textPerPageAsync(): Promise<Array<PageText>>;
|
|
111
|
+
structuredText(): Array<StructuredPageText>;
|
|
112
|
+
structuredTextAsync(): Promise<Array<StructuredPageText>>;
|
|
113
|
+
layout(): Array<PageLayout>;
|
|
114
|
+
layoutAsync(): Promise<Array<PageLayout>>;
|
|
115
|
+
imagesPerPage(): Array<PageImage>;
|
|
116
|
+
imagesPerPageAsync(): Promise<Array<PageImage>>;
|
|
117
|
+
annotationsPerPage(): Array<PageAnnotation>;
|
|
118
|
+
annotationsPerPageAsync(): Promise<Array<PageAnnotation>>;
|
|
119
|
+
formFieldsPerPage(): Array<PageFormField>;
|
|
120
|
+
formFieldsPerPageAsync(): Promise<Array<PageFormField>>;
|
|
121
|
+
attachments(): Array<Attachment>;
|
|
122
|
+
attachmentsAsync(): Promise<Array<Attachment>>;
|
|
123
|
+
invoice(opts?: InvoiceOptions): InvoiceResult;
|
|
124
|
+
invoiceAsync(opts?: InvoiceOptions): Promise<InvoiceResult>;
|
|
125
|
+
metadata(): PdfMeta;
|
|
126
|
+
metadataAsync(): Promise<PdfMeta>;
|
|
127
|
+
document(): PdfDocument;
|
|
128
|
+
documentAsync(): Promise<PdfDocument>;
|
|
129
|
+
renderPagesAsync(opts?: RenderOptions): Promise<Array<RenderedPage>>;
|
|
130
|
+
|
|
131
|
+
// ── OCR methods ──
|
|
132
|
+
textWithOcrPerPage(opts?: OcrOptions): Array<OcrPageText>;
|
|
133
|
+
textWithOcrPerPageAsync(opts?: OcrOptions): Promise<Array<OcrPageText>>;
|
|
134
|
+
documentOcr(opts?: OcrOptions): PdfDocumentOcr;
|
|
135
|
+
documentOcrAsync(opts?: OcrOptions): Promise<PdfDocumentOcr>;
|
|
136
|
+
layoutWithOcr(opts?: OcrOptions): Array<PageLayout>;
|
|
137
|
+
layoutWithOcrAsync(opts?: OcrOptions): Promise<Array<PageLayout>>;
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Types
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
// The deepest cascade tier that produced a page's text.
|
|
145
|
+
export type TextSource = "Native" | "Ocr" | "Rendered";
|
|
146
|
+
|
|
147
|
+
export interface OcrPageText {
|
|
148
|
+
page: number;
|
|
149
|
+
text: string;
|
|
150
|
+
source: TextSource;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface OcrStructuredPageText {
|
|
154
|
+
page: number;
|
|
155
|
+
header: string;
|
|
156
|
+
body: string;
|
|
157
|
+
footer: string;
|
|
158
|
+
source: TextSource;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export type RenderMode = "Auto" | "Never" | "Always";
|
|
162
|
+
|
|
163
|
+
export interface OcrOptions {
|
|
164
|
+
lang?: string; // Tesseract language code, default "eng"
|
|
165
|
+
minTextLength?: number; // non-whitespace char threshold before OCR fallback, default 1
|
|
166
|
+
maxThreads?: number; // cap on Rayon threads for OCR parallelism, default 4, clamped to [1, available CPUs]
|
|
167
|
+
render?: RenderMode; // the render tier, default "Auto"; see "The render tier and PDFium"
|
|
168
|
+
renderDpi?: number; // resolution pages are rendered at, default 300, clamped to 72..600
|
|
169
|
+
pdfiumPath?: string; // the PDFium library file to load, for a host where it is not on the search path
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface PdfDocumentOcr {
|
|
173
|
+
version: string;
|
|
174
|
+
isLinearized: boolean;
|
|
175
|
+
pageCount: number;
|
|
176
|
+
creator?: string;
|
|
177
|
+
producer?: string;
|
|
178
|
+
creationDate?: string;
|
|
179
|
+
modificationDate?: string;
|
|
180
|
+
pageBoxes: Array<PageBox>;
|
|
181
|
+
totalImages: number;
|
|
182
|
+
totalAnnotations: number;
|
|
183
|
+
imagePages: Array<number>;
|
|
184
|
+
annotationPages: Array<number>;
|
|
185
|
+
text: Array<OcrPageText>;
|
|
186
|
+
structuredText: Array<OcrStructuredPageText>;
|
|
187
|
+
images: Array<PageImage>;
|
|
188
|
+
annotations: Array<PageAnnotation>;
|
|
189
|
+
form?: FormInfo;
|
|
190
|
+
formFields: Array<PageFormField>;
|
|
191
|
+
totalFormFields: number;
|
|
192
|
+
formFieldPages: Array<number>;
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Usage
|
|
197
|
+
|
|
198
|
+
> **Use the async API for OCR.** The sync variants block the Node.js event loop for the duration of OCR processing, which can be significant for multi-page scanned documents.
|
|
199
|
+
|
|
200
|
+
### Standalone
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import { readFile } from "node:fs/promises";
|
|
204
|
+
|
|
205
|
+
import { extractTextWithOcrPerPageAsync } from "@d0paminedriven/pdfdown-ocr";
|
|
206
|
+
|
|
207
|
+
const pdf = await readFile("scanned-document.pdf");
|
|
208
|
+
const pages = await extractTextWithOcrPerPageAsync(pdf, {
|
|
209
|
+
lang: "eng",
|
|
210
|
+
minTextLength: 10
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
for (const { page, text, source } of pages) {
|
|
214
|
+
console.log(`Page ${page} [${source}]: ${text.slice(0, 100)}...`);
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Class-based (parse once, extract many)
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
import { readFile } from "node:fs/promises";
|
|
222
|
+
|
|
223
|
+
import { PdfDown } from "@d0paminedriven/pdfdown-ocr";
|
|
224
|
+
|
|
225
|
+
const pdf = new PdfDown(await readFile("scanned-document.pdf"));
|
|
226
|
+
|
|
227
|
+
// OCR text extraction
|
|
228
|
+
const pages = await pdf.textWithOcrPerPageAsync({
|
|
229
|
+
lang: "eng",
|
|
230
|
+
minTextLength: 10
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
// All base methods work too
|
|
234
|
+
const images = await pdf.imagesPerPageAsync();
|
|
235
|
+
const meta = pdf.metadata();
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Extract everything with OCR in one call
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
import { readFile } from "node:fs/promises";
|
|
242
|
+
|
|
243
|
+
import { PdfDown } from "@d0paminedriven/pdfdown-ocr";
|
|
244
|
+
|
|
245
|
+
const pdf = new PdfDown(await readFile("scanned-document.pdf"));
|
|
246
|
+
const result = await pdf.documentOcrAsync({ minTextLength: 10 });
|
|
247
|
+
|
|
248
|
+
// result.text — OcrPageText[] (page, text, source per page)
|
|
249
|
+
// result.structuredText — OcrStructuredPageText[] (header/body/footer + source per page)
|
|
250
|
+
// result.images — PageImage[] (decoded PNGs with dimensions and color space)
|
|
251
|
+
// result.annotations — PageAnnotation[] (links, destinations, rects)
|
|
252
|
+
// result.pageCount, result.version, result.creator, ...
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Combined: OCR text + images for multimodal pipelines
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
import { readFile } from "node:fs/promises";
|
|
259
|
+
|
|
260
|
+
import { PdfDown } from "@d0paminedriven/pdfdown-ocr";
|
|
261
|
+
|
|
262
|
+
const pdf = new PdfDown(await readFile("scanned-document.pdf"));
|
|
263
|
+
|
|
264
|
+
const [ocrText, images] = await Promise.all([
|
|
265
|
+
pdf.textWithOcrPerPageAsync({ minTextLength: 10 }),
|
|
266
|
+
pdf.imagesPerPageAsync()
|
|
267
|
+
]);
|
|
268
|
+
|
|
269
|
+
const imagesByPage = Map.groupBy(images, (img) => img.page);
|
|
270
|
+
|
|
271
|
+
for (const { page, text, source } of ocrText) {
|
|
272
|
+
const pageImages = (imagesByPage.get(page) ?? []).map((img) => ({
|
|
273
|
+
dataUrl: `data:image/png;base64,${img.data.toString("base64")}`,
|
|
274
|
+
width: img.width,
|
|
275
|
+
height: img.height
|
|
276
|
+
}));
|
|
277
|
+
// Send { page, text, source, images: pageImages } to your embedding pipeline
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### `document()` vs `documentOcr()`
|
|
282
|
+
|
|
283
|
+
Both methods extract everything from a PDF in a single call. The difference is how text is extracted:
|
|
284
|
+
|
|
285
|
+
| Method | Text extraction | Return type | Use when |
|
|
286
|
+
| -------------------------------------- | ------------------------ | ---------------- | ---------------------------------------- |
|
|
287
|
+
| `document()` / `documentAsync()` | Native PDF text only | `PdfDocument` | PDF has selectable text |
|
|
288
|
+
| `documentOcr()` / `documentOcrAsync()` | Native with OCR fallback | `PdfDocumentOcr` | PDF may contain scanned/image-only pages |
|
|
289
|
+
|
|
290
|
+
`PdfDocumentOcr` uses `OcrPageText` (with `source: "Native" | "Ocr" | "Rendered"`) and `OcrStructuredPageText` (with header/body/footer split plus source) instead of the base `PageText` and `StructuredPageText` types. Images, annotations, metadata, page boxes and the read-only AcroForm data (`form`, `formFields`, `totalFormFields`, `formFieldPages`; see the base package docs) are identical in both.
|
|
291
|
+
|
|
292
|
+
### Positioned text with OCR
|
|
293
|
+
|
|
294
|
+
`extractLayoutWithOcrPerPage` returns the base package's `PageLayout` shape (words, lines and image placements with boxes in PDF points) for every page, choosing the source per page exactly like the text cascade:
|
|
295
|
+
|
|
296
|
+
1. **Native** -- glyphs placed from the content stream, with `fontName` / `fontSize` / `bold` on every word.
|
|
297
|
+
2. **Ocr** -- the page's embedded raster images are OCR'd and each Tesseract word box is mapped through the image's `Do` placement onto the page. Words carry `confidence` (0..1) instead of font metadata.
|
|
298
|
+
3. **Rendered** -- with PDFium, the page is rasterised as displayed at `renderDpi` and OCR'd; word boxes are mapped back onto the page box in the page's own frame, the one native words use, and `contentRotation` includes `/Rotate`.
|
|
299
|
+
|
|
300
|
+
Copier and fax scans (`CCITTFaxDecode`, Group 3 and Group 4) are decoded in pure Rust, so they are read at tier 2 without PDFium. When the upright pass scores a mean Tesseract confidence under 55 (a landscape sheet scanned in portrait comes back as punctuation at 35-45), the raster is OCR'd again turned 90°, 270° and 180° and the best orientation wins. The page then reports `contentRotation`, the turn carrying the most confident OCR text across its images (the tiles of a tiled scan vote together), and every word, line and image placement is expressed in that turned frame, with `width`/`height` swapped for a quarter turn. A warning names each turned image with more than a few words and who decided the turn (the orientation detector or the confidence retry); such an image that reads upright at a different turn than the page is named too, since its words read sideways in the page frame. The render tier reads the page as displayed, so on a `/Rotate` page its `contentRotation` includes `/Rotate`; for any page, displayed coordinates are the reported frame turned clockwise by `rotate - contentRotation`. The same retry applies to `extractTextWithOcrPerPage`.
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
import { readFileSync } from "node:fs";
|
|
304
|
+
|
|
305
|
+
import { extractLayoutWithOcrPerPage } from "@d0paminedriven/pdfdown-ocr";
|
|
306
|
+
|
|
307
|
+
for (const page of extractLayoutWithOcrPerPage(readFileSync("scan.pdf"), {
|
|
308
|
+
render: "Auto"
|
|
309
|
+
})) {
|
|
310
|
+
console.log(`page ${page.page} (${page.source})`);
|
|
311
|
+
for (const line of page.lines) {
|
|
312
|
+
const confidence = page.words
|
|
313
|
+
.slice(line.firstWord, line.firstWord + line.wordCount)
|
|
314
|
+
.map((w) => w.confidence ?? 1);
|
|
315
|
+
console.log(` ${Math.min(...confidence).toFixed(2)} ${line.text}`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### The render tier and PDFium
|
|
321
|
+
|
|
322
|
+
Tier 3 of the cascade needs [PDFium](https://pdfium.googlesource.com/pdfium/), which is not bundled. It is looked for once per process, the first time anything asks for it (an OCR call, `renderPagesAsync` or `capabilities()`), and loaded from the first of these that works:
|
|
323
|
+
|
|
324
|
+
1. `pdfiumPath` in that call's `OcrOptions`: the library file itself (`libpdfium.so`, `libpdfium.dylib`)
|
|
325
|
+
2. The library file named by the `PDFIUM_LIBRARY_PATH` environment variable
|
|
326
|
+
3. The system's library search path
|
|
327
|
+
|
|
328
|
+
A `pdfiumPath` passed after that first look is ignored, so pass it on your first call or use the environment variable.
|
|
329
|
+
|
|
330
|
+
`capabilities()` returns `{ ocr: true, render }`, where `render` says whether PDFium was found. Without it the cascade stops at tier 2 and nothing fails: a page only a renderer could read comes back with whatever tiers 1 and 2 found.
|
|
331
|
+
|
|
332
|
+
`render` chooses how the tier is used:
|
|
333
|
+
|
|
334
|
+
| `render` | What happens |
|
|
335
|
+
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
336
|
+
| `"Auto"` | The default. A page is rendered when the cascade calls for it (see "How it works") |
|
|
337
|
+
| `"Never"` | No page is rendered, whether or not PDFium is there |
|
|
338
|
+
| `"Always"` | Every page is rendered and OCR'd first, and what was read replaces the page's own text. A render that reads nothing falls back to the cascade for that page |
|
|
339
|
+
|
|
340
|
+
`renderPagesAsync`, from the base package, returns the rendered pages themselves as PNG; see the base README's "Rendering pages".
|
|
341
|
+
|
|
342
|
+
## Invoices from scans
|
|
343
|
+
|
|
344
|
+
`invoice()` and `invoiceAsync()` read the header fields of a PDF from its pages (see the base README's "Invoices from pages" section). In this package they run the OCR cascade with default options on the **first and the last page only**, the two pages the header track reads, so a long scan does not cost a whole-document OCR; `source` then reports `Ocr`, `Rendered` or `Mixed` and every OCR'd field's confidence is scaled by its words' Tesseract confidence. For other OCR options, call `layoutWithOcr(opts)` yourself and hand the pages to `invoiceFromLayout(pages)`.
|
|
345
|
+
|
|
346
|
+
## How it works
|
|
347
|
+
|
|
348
|
+
1. **Text extraction (the cascade):** Each page is read natively first. A page goes to OCR when its native text is under `minTextLength` non-whitespace characters, or when its native words cover under 2% of the page while images cover more than half of it or the content stream paints 200 or more path operators (a scan with a stamp on it, or text printed as outlines); a few words on an otherwise empty cover sheet stay native. Tier 2 decodes the embedded rasters and feeds them to Tesseract; tier 3, with PDFium, renders the page when the page has no rasters but painted paths, or when tier 2 found nothing or only a weak result on a path-heavy page. On a hybrid page the native words stay and OCR adds only what they do not cover (duplicates dropped at IoU > 0.5); `source` reports the deepest tier that ran (`Native`, `Ocr` or `Rendered`), even when OCR added no words; OCR words carry `confidence`, native words do not, and a warning counts the native words kept. Orientation is decided per raster: an upright pass with a mean Tesseract confidence of 80 or more stands; below that the raster is shown to Tesseract's orientation detector (OSD), and only when OSD cannot decide and the upright pass scored under 55 is the raster read again at 90°, 270° and 180° with the best score winning.
|
|
349
|
+
|
|
350
|
+
2. **Structured text:** After text extraction, repeated header/footer lines are detected across pages using frequency analysis (requires 3+ pages). Each page's text is split into `header`, `body`, and `footer` sections. For OCR results, the `source` tag is preserved so you know whether each page's content came from native extraction or OCR.
|
|
351
|
+
|
|
352
|
+
3. **Parallelism:** OCR runs on a dedicated capped Rayon thread pool (default 4 threads, configurable via `maxThreads`) to prevent CPU oversubscription. Text extraction, image extraction, annotation extraction and form extraction run concurrently via `rayon::join` when using `documentOcr` / `documentOcrAsync`. The package entry point also sets `OMP_THREAD_LIMIT=1` before the native module loads, because libtesseract otherwise starts one OpenMP thread per core inside every recognise call and the workers thrash each other (measured on a 12-core machine over nine scanned pages: 13.7 s with the limit, 196 s without it). Parallelism therefore comes from `maxThreads`, not from OpenMP; set `OMP_THREAD_LIMIT` or `OMP_NUM_THREADS` yourself before importing the package to override this.
|
|
353
|
+
|
|
354
|
+
4. **Tessdata discovery:** On first OCR invocation, the tessdata path is resolved once and cached in a `OnceLock`. The `TESSDATA_PREFIX` environment variable is checked first; if unset, `tesseract --list-langs` is executed and its output is parsed to extract the path. No environment variables are mutated -- the path is passed directly to Tesseract's init function.
|
|
355
|
+
|
|
356
|
+
## Supported platforms
|
|
357
|
+
|
|
358
|
+
Prebuilt binaries are provided for:
|
|
359
|
+
|
|
360
|
+
| Platform | Architecture(s) |
|
|
361
|
+
| ------------- | --------------- |
|
|
362
|
+
| macOS | ARM64 |
|
|
363
|
+
| Linux (glibc) | x64, ARM64 |
|
|
364
|
+
|
|
365
|
+
Intel macOS is not built: the OCR package links the system Tesseract, and Homebrew no longer ships Intel bottles, so there is no supported way to obtain the library on that platform. The base `@d0paminedriven/pdfdown` package still ships an Intel macOS binary, and builds for the other platforms and WebAssembly as well.
|
|
366
|
+
|
|
367
|
+
## Relationship to `@d0paminedriven/pdfdown`
|
|
368
|
+
|
|
369
|
+
The same binding, built with its `ocr` feature, which adds the Tesseract cascade on top of the base readers. This package is a strict superset -- you can use it as a drop-in replacement for the base package if you need OCR capabilities. The two are released together at one version.
|
|
370
|
+
|
|
371
|
+
## License
|
|
372
|
+
|
|
373
|
+
MIT
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d0paminedriven/pdfdown-ocr",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Rust powered PDF extraction for Node with OCR and optional rendering (requires system tesseract).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"aarch64-unknown-linux-gnu"
|
|
34
34
|
],
|
|
35
35
|
"constEnum": false,
|
|
36
|
-
"dtsHeader": "/* auto-generated by @d0paminedriven/pdfdown-ocr
|
|
36
|
+
"dtsHeader": "/* auto-generated by @d0paminedriven/pdfdown-ocr */\n\n"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">=24"
|
|
40
40
|
},
|
|
41
41
|
"optionalDependencies": {
|
|
42
|
-
"@d0paminedriven/pdfdown-ocr-darwin-arm64": "0.
|
|
43
|
-
"@d0paminedriven/pdfdown-ocr-linux-x64-gnu": "0.
|
|
44
|
-
"@d0paminedriven/pdfdown-ocr-linux-arm64-gnu": "0.
|
|
42
|
+
"@d0paminedriven/pdfdown-ocr-darwin-arm64": "0.15.0",
|
|
43
|
+
"@d0paminedriven/pdfdown-ocr-linux-x64-gnu": "0.15.0",
|
|
44
|
+
"@d0paminedriven/pdfdown-ocr-linux-arm64-gnu": "0.15.0"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/pdfdown_ocr.napi.js
CHANGED
|
@@ -97,8 +97,8 @@ function requireNative() {
|
|
|
97
97
|
try {
|
|
98
98
|
const binding = require('@d0paminedriven/pdfdown-ocr-android-arm64')
|
|
99
99
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-android-arm64/package.json').version
|
|
100
|
-
if (bindingPackageVersion !== '0.
|
|
101
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
100
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
101
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
102
102
|
}
|
|
103
103
|
return binding
|
|
104
104
|
} catch (e) {
|
|
@@ -113,8 +113,8 @@ function requireNative() {
|
|
|
113
113
|
try {
|
|
114
114
|
const binding = require('@d0paminedriven/pdfdown-ocr-android-arm-eabi')
|
|
115
115
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-android-arm-eabi/package.json').version
|
|
116
|
-
if (bindingPackageVersion !== '0.
|
|
117
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
116
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
117
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
118
118
|
}
|
|
119
119
|
return binding
|
|
120
120
|
} catch (e) {
|
|
@@ -134,8 +134,8 @@ function requireNative() {
|
|
|
134
134
|
try {
|
|
135
135
|
const binding = require('@d0paminedriven/pdfdown-ocr-win32-x64-gnu')
|
|
136
136
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-win32-x64-gnu/package.json').version
|
|
137
|
-
if (bindingPackageVersion !== '0.
|
|
138
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
137
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
138
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
139
139
|
}
|
|
140
140
|
return binding
|
|
141
141
|
} catch (e) {
|
|
@@ -150,8 +150,8 @@ function requireNative() {
|
|
|
150
150
|
try {
|
|
151
151
|
const binding = require('@d0paminedriven/pdfdown-ocr-win32-x64-msvc')
|
|
152
152
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-win32-x64-msvc/package.json').version
|
|
153
|
-
if (bindingPackageVersion !== '0.
|
|
154
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
153
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
154
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
155
155
|
}
|
|
156
156
|
return binding
|
|
157
157
|
} catch (e) {
|
|
@@ -167,8 +167,8 @@ function requireNative() {
|
|
|
167
167
|
try {
|
|
168
168
|
const binding = require('@d0paminedriven/pdfdown-ocr-win32-ia32-msvc')
|
|
169
169
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-win32-ia32-msvc/package.json').version
|
|
170
|
-
if (bindingPackageVersion !== '0.
|
|
171
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
170
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
171
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
172
172
|
}
|
|
173
173
|
return binding
|
|
174
174
|
} catch (e) {
|
|
@@ -183,8 +183,8 @@ function requireNative() {
|
|
|
183
183
|
try {
|
|
184
184
|
const binding = require('@d0paminedriven/pdfdown-ocr-win32-arm64-msvc')
|
|
185
185
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-win32-arm64-msvc/package.json').version
|
|
186
|
-
if (bindingPackageVersion !== '0.
|
|
187
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
186
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
187
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
188
188
|
}
|
|
189
189
|
return binding
|
|
190
190
|
} catch (e) {
|
|
@@ -202,8 +202,8 @@ function requireNative() {
|
|
|
202
202
|
try {
|
|
203
203
|
const binding = require('@d0paminedriven/pdfdown-ocr-darwin-universal')
|
|
204
204
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-darwin-universal/package.json').version
|
|
205
|
-
if (bindingPackageVersion !== '0.
|
|
206
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
205
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
206
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
207
207
|
}
|
|
208
208
|
return binding
|
|
209
209
|
} catch (e) {
|
|
@@ -218,8 +218,8 @@ function requireNative() {
|
|
|
218
218
|
try {
|
|
219
219
|
const binding = require('@d0paminedriven/pdfdown-ocr-darwin-x64')
|
|
220
220
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-darwin-x64/package.json').version
|
|
221
|
-
if (bindingPackageVersion !== '0.
|
|
222
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
221
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
222
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
223
223
|
}
|
|
224
224
|
return binding
|
|
225
225
|
} catch (e) {
|
|
@@ -234,8 +234,8 @@ function requireNative() {
|
|
|
234
234
|
try {
|
|
235
235
|
const binding = require('@d0paminedriven/pdfdown-ocr-darwin-arm64')
|
|
236
236
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-darwin-arm64/package.json').version
|
|
237
|
-
if (bindingPackageVersion !== '0.
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
237
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
239
|
}
|
|
240
240
|
return binding
|
|
241
241
|
} catch (e) {
|
|
@@ -254,8 +254,8 @@ function requireNative() {
|
|
|
254
254
|
try {
|
|
255
255
|
const binding = require('@d0paminedriven/pdfdown-ocr-freebsd-x64')
|
|
256
256
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-freebsd-x64/package.json').version
|
|
257
|
-
if (bindingPackageVersion !== '0.
|
|
258
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
257
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
258
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
259
259
|
}
|
|
260
260
|
return binding
|
|
261
261
|
} catch (e) {
|
|
@@ -270,8 +270,8 @@ function requireNative() {
|
|
|
270
270
|
try {
|
|
271
271
|
const binding = require('@d0paminedriven/pdfdown-ocr-freebsd-arm64')
|
|
272
272
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-freebsd-arm64/package.json').version
|
|
273
|
-
if (bindingPackageVersion !== '0.
|
|
274
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
273
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
274
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
275
275
|
}
|
|
276
276
|
return binding
|
|
277
277
|
} catch (e) {
|
|
@@ -286,8 +286,8 @@ function requireNative() {
|
|
|
286
286
|
try {
|
|
287
287
|
const binding = require('@d0paminedriven/pdfdown-ocr-freebsd-ppc64')
|
|
288
288
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-freebsd-ppc64/package.json').version
|
|
289
|
-
if (bindingPackageVersion !== '0.
|
|
290
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
289
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
290
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
291
291
|
}
|
|
292
292
|
return binding
|
|
293
293
|
} catch (e) {
|
|
@@ -307,8 +307,8 @@ function requireNative() {
|
|
|
307
307
|
try {
|
|
308
308
|
const binding = require('@d0paminedriven/pdfdown-ocr-linux-x64-musl')
|
|
309
309
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-linux-x64-musl/package.json').version
|
|
310
|
-
if (bindingPackageVersion !== '0.
|
|
311
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
310
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
311
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
312
312
|
}
|
|
313
313
|
return binding
|
|
314
314
|
} catch (e) {
|
|
@@ -323,8 +323,8 @@ function requireNative() {
|
|
|
323
323
|
try {
|
|
324
324
|
const binding = require('@d0paminedriven/pdfdown-ocr-linux-x64-gnu')
|
|
325
325
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-linux-x64-gnu/package.json').version
|
|
326
|
-
if (bindingPackageVersion !== '0.
|
|
327
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
326
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
327
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
328
328
|
}
|
|
329
329
|
return binding
|
|
330
330
|
} catch (e) {
|
|
@@ -341,8 +341,8 @@ function requireNative() {
|
|
|
341
341
|
try {
|
|
342
342
|
const binding = require('@d0paminedriven/pdfdown-ocr-linux-arm64-musl')
|
|
343
343
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-linux-arm64-musl/package.json').version
|
|
344
|
-
if (bindingPackageVersion !== '0.
|
|
345
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
344
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
345
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
346
346
|
}
|
|
347
347
|
return binding
|
|
348
348
|
} catch (e) {
|
|
@@ -357,8 +357,8 @@ function requireNative() {
|
|
|
357
357
|
try {
|
|
358
358
|
const binding = require('@d0paminedriven/pdfdown-ocr-linux-arm64-gnu')
|
|
359
359
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-linux-arm64-gnu/package.json').version
|
|
360
|
-
if (bindingPackageVersion !== '0.
|
|
361
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
360
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
361
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
362
362
|
}
|
|
363
363
|
return binding
|
|
364
364
|
} catch (e) {
|
|
@@ -375,8 +375,8 @@ function requireNative() {
|
|
|
375
375
|
try {
|
|
376
376
|
const binding = require('@d0paminedriven/pdfdown-ocr-linux-arm-musleabihf')
|
|
377
377
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-linux-arm-musleabihf/package.json').version
|
|
378
|
-
if (bindingPackageVersion !== '0.
|
|
379
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
378
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
379
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
380
380
|
}
|
|
381
381
|
return binding
|
|
382
382
|
} catch (e) {
|
|
@@ -391,8 +391,8 @@ function requireNative() {
|
|
|
391
391
|
try {
|
|
392
392
|
const binding = require('@d0paminedriven/pdfdown-ocr-linux-arm-gnueabihf')
|
|
393
393
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-linux-arm-gnueabihf/package.json').version
|
|
394
|
-
if (bindingPackageVersion !== '0.
|
|
395
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
394
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
395
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
396
396
|
}
|
|
397
397
|
return binding
|
|
398
398
|
} catch (e) {
|
|
@@ -409,8 +409,8 @@ function requireNative() {
|
|
|
409
409
|
try {
|
|
410
410
|
const binding = require('@d0paminedriven/pdfdown-ocr-linux-loong64-musl')
|
|
411
411
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-linux-loong64-musl/package.json').version
|
|
412
|
-
if (bindingPackageVersion !== '0.
|
|
413
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
412
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
413
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
414
414
|
}
|
|
415
415
|
return binding
|
|
416
416
|
} catch (e) {
|
|
@@ -425,8 +425,8 @@ function requireNative() {
|
|
|
425
425
|
try {
|
|
426
426
|
const binding = require('@d0paminedriven/pdfdown-ocr-linux-loong64-gnu')
|
|
427
427
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-linux-loong64-gnu/package.json').version
|
|
428
|
-
if (bindingPackageVersion !== '0.
|
|
429
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
428
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
429
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
430
430
|
}
|
|
431
431
|
return binding
|
|
432
432
|
} catch (e) {
|
|
@@ -443,8 +443,8 @@ function requireNative() {
|
|
|
443
443
|
try {
|
|
444
444
|
const binding = require('@d0paminedriven/pdfdown-ocr-linux-riscv64-musl')
|
|
445
445
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-linux-riscv64-musl/package.json').version
|
|
446
|
-
if (bindingPackageVersion !== '0.
|
|
447
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
446
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
447
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
448
448
|
}
|
|
449
449
|
return binding
|
|
450
450
|
} catch (e) {
|
|
@@ -459,8 +459,8 @@ function requireNative() {
|
|
|
459
459
|
try {
|
|
460
460
|
const binding = require('@d0paminedriven/pdfdown-ocr-linux-riscv64-gnu')
|
|
461
461
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-linux-riscv64-gnu/package.json').version
|
|
462
|
-
if (bindingPackageVersion !== '0.
|
|
463
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
462
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
463
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
464
464
|
}
|
|
465
465
|
return binding
|
|
466
466
|
} catch (e) {
|
|
@@ -476,8 +476,8 @@ function requireNative() {
|
|
|
476
476
|
try {
|
|
477
477
|
const binding = require('@d0paminedriven/pdfdown-ocr-linux-ppc64-gnu')
|
|
478
478
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-linux-ppc64-gnu/package.json').version
|
|
479
|
-
if (bindingPackageVersion !== '0.
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
479
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
481
|
}
|
|
482
482
|
return binding
|
|
483
483
|
} catch (e) {
|
|
@@ -492,8 +492,8 @@ function requireNative() {
|
|
|
492
492
|
try {
|
|
493
493
|
const binding = require('@d0paminedriven/pdfdown-ocr-linux-s390x-gnu')
|
|
494
494
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-linux-s390x-gnu/package.json').version
|
|
495
|
-
if (bindingPackageVersion !== '0.
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
495
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
497
|
}
|
|
498
498
|
return binding
|
|
499
499
|
} catch (e) {
|
|
@@ -512,8 +512,8 @@ function requireNative() {
|
|
|
512
512
|
try {
|
|
513
513
|
const binding = require('@d0paminedriven/pdfdown-ocr-openharmony-arm64')
|
|
514
514
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-openharmony-arm64/package.json').version
|
|
515
|
-
if (bindingPackageVersion !== '0.
|
|
516
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
515
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
516
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
517
517
|
}
|
|
518
518
|
return binding
|
|
519
519
|
} catch (e) {
|
|
@@ -528,8 +528,8 @@ function requireNative() {
|
|
|
528
528
|
try {
|
|
529
529
|
const binding = require('@d0paminedriven/pdfdown-ocr-openharmony-x64')
|
|
530
530
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-openharmony-x64/package.json').version
|
|
531
|
-
if (bindingPackageVersion !== '0.
|
|
532
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
531
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
532
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
533
533
|
}
|
|
534
534
|
return binding
|
|
535
535
|
} catch (e) {
|
|
@@ -544,8 +544,8 @@ function requireNative() {
|
|
|
544
544
|
try {
|
|
545
545
|
const binding = require('@d0paminedriven/pdfdown-ocr-openharmony-arm')
|
|
546
546
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-openharmony-arm/package.json').version
|
|
547
|
-
if (bindingPackageVersion !== '0.
|
|
548
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
547
|
+
if (bindingPackageVersion !== '0.15.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
548
|
+
throw new Error(`Native binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
549
549
|
}
|
|
550
550
|
return binding
|
|
551
551
|
} catch (e) {
|
|
@@ -686,8 +686,8 @@ if (!nativeBinding || forceWasi) {
|
|
|
686
686
|
if (!candidateFailed) {
|
|
687
687
|
if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
688
688
|
const bindingPackageVersion = require('@d0paminedriven/pdfdown-ocr-wasm32-wasi/package.json').version
|
|
689
|
-
if (bindingPackageVersion !== '0.
|
|
690
|
-
throw new Error(`WASI binding package version mismatch, expected 0.
|
|
689
|
+
if (bindingPackageVersion !== '0.15.0') {
|
|
690
|
+
throw new Error(`WASI binding package version mismatch, expected 0.15.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
691
691
|
}
|
|
692
692
|
}
|
|
693
693
|
wasiBinding = require('@d0paminedriven/pdfdown-ocr-wasm32-wasi')
|