@d0paminedriven/pdfdown-ocr 0.10.0 → 0.12.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/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /* auto-generated by NAPI-RS */
2
- /* eslint-disable */
3
2
 
4
3
  /**
5
4
  * Which binding artifact the generated loader actually loaded: `'native'` for
@@ -11,10 +10,33 @@ export declare const __napiBindingTarget: "native" | "wasm32-wasi" | "wasm32-was
11
10
 
12
11
  export declare class PdfDown {
13
12
  constructor(buffer: Buffer);
13
+ /** Open a PDF or a workbook off the JavaScript thread; resolves to a `PdfDown`. */
14
+ static openAsync(buffer: Buffer): Promise<PdfDown>;
15
+ /** The format this document was opened as. */
16
+ get format(): DocumentFormat;
17
+ /** The cells of a workbook's selected sheets, typed, with their display text and formulas. */
18
+ spreadsheetCells(opts?: SpreadsheetOptions | undefined | null): Array<SheetCells>;
19
+ spreadsheetCellsAsync(opts?: SpreadsheetOptions | undefined | null): Promise<Array<SheetCells>>;
14
20
  textPerPage(): Array<PageText>;
15
21
  imagesPerPage(): Array<PageImage>;
16
22
  annotationsPerPage(): Array<PageAnnotation>;
17
23
  metadata(): PdfMeta;
24
+ /**
25
+ * Positioned words and lines per page: a PDF's content stream (native text only), or one
26
+ * logical page per selected sheet of a workbook, where `opts` picks the sheets and whether
27
+ * hidden rows and columns keep their extents. A PDF ignores `opts`.
28
+ */
29
+ layout(opts?: SpreadsheetOptions | undefined | null): Array<PageLayout>;
30
+ layoutAsync(opts?: SpreadsheetOptions | undefined | null): Promise<Array<PageLayout>>;
31
+ attachments(): Array<Attachment>;
32
+ attachmentsAsync(): Promise<Array<Attachment>>;
33
+ /**
34
+ * Structured invoice data. A PDF reads its embedded Factur-X / ZUGFeRD / XRechnung / UBL
35
+ * XML; a workbook returns `source: "None"` with a warning until the layout-based engine
36
+ * reads spreadsheet pages.
37
+ */
38
+ invoice(opts?: InvoiceOptions | undefined | null): InvoiceResult;
39
+ invoiceAsync(opts?: InvoiceOptions | undefined | null): Promise<InvoiceResult>;
18
40
  textPerPageAsync(): Promise<Array<PageText>>;
19
41
  imagesPerPageAsync(): Promise<Array<PageImage>>;
20
42
  annotationsPerPageAsync(): Promise<Array<PageAnnotation>>;
@@ -23,13 +45,71 @@ export declare class PdfDown {
23
45
  documentAsync(): Promise<PdfDocument>;
24
46
  structuredText(): Array<StructuredPageText>;
25
47
  structuredTextAsync(): Promise<Array<StructuredPageText>>;
48
+ formFieldsPerPage(): Array<PageFormField>;
49
+ formFieldsPerPageAsync(): Promise<Array<PageFormField>>;
26
50
  textWithOcrPerPage(opts?: OcrOptions | undefined | null): Array<OcrPageText>;
27
51
  textWithOcrPerPageAsync(opts?: OcrOptions | undefined | null): Promise<Array<OcrPageText>>;
52
+ /** Positioned words and lines per page with the OCR cascade. */
53
+ layoutWithOcr(opts?: OcrOptions | undefined | null): Array<PageLayout>;
54
+ layoutWithOcrAsync(opts?: OcrOptions | undefined | null): Promise<Array<PageLayout>>;
28
55
  documentOcr(opts?: OcrOptions | undefined | null): PdfDocumentOcr;
29
56
  documentOcrAsync(opts?: OcrOptions | undefined | null): Promise<PdfDocumentOcr>;
30
57
  renderPagesAsync(opts?: RenderOptions | undefined | null): Promise<Array<RenderedPage>>;
31
58
  }
32
59
 
60
+ /** `value` is `lines` joined with `
61
+ `. */
62
+ export interface AddressField {
63
+ value: string;
64
+ text: string;
65
+ confidence: number;
66
+ span?: FieldSpan;
67
+ lines: Array<string>;
68
+ }
69
+
70
+ /**
71
+ * An aircraft or engine the invoice relates to. Maintenance, parts and
72
+ * program invoices identify the asset by airframe (model, manufacturer serial
73
+ * number, registration) and/or by engine (model, engine serial number); one
74
+ * invoice can cover several assets, so `InvoiceFields.aircraft` is a list.
75
+ */
76
+ export interface AircraftReference {
77
+ /** Airframe model, e.g. "Challenger 350", "Global 6000", "Phenom 300". */
78
+ model?: StringField;
79
+ /** Manufacturer serial number (MSN). */
80
+ serialNumber?: StringField;
81
+ /** Registration / tail number, e.g. "N123AB", "C-GXYZ". */
82
+ registration?: StringField;
83
+ /** Engine model, e.g. "BR710", "AE 3007", "PW308C". */
84
+ engineModel?: StringField;
85
+ /** Engine serial number (ESN). */
86
+ engineSerialNumber?: StringField;
87
+ span?: FieldSpan;
88
+ }
89
+
90
+ /**
91
+ * A file embedded in the PDF: a `/Names /EmbeddedFiles` entry, a catalog
92
+ * `/AF` associated file, or a page-level `/FileAttachment` annotation.
93
+ */
94
+ export interface Attachment {
95
+ name: string;
96
+ /** From the embedded file stream's `/Subtype`, e.g. `text/xml`. */
97
+ mimeType?: string;
98
+ /** Decoded payload size in bytes. */
99
+ size: number;
100
+ /** `/AFRelationship`: `Source`, `Data`, `Alternative`, `Supplement`, ... */
101
+ relationship?: string;
102
+ description?: string;
103
+ /** 1-based page for a `/FileAttachment` annotation; absent for document-level files. */
104
+ page?: number;
105
+ data: Buffer;
106
+ }
107
+
108
+ /** Every embedded file: `/Names /EmbeddedFiles`, catalog `/AF`, and page `/FileAttachment` annotations. */
109
+ export declare function attachments(buffer: Buffer): Array<Attachment>;
110
+
111
+ export declare function attachmentsAsync(buffer: Buffer): Promise<Array<Attachment>>;
112
+
33
113
  export type BoxType = "CropBox" | "MediaBox" | "Unknown";
34
114
 
35
115
  export declare function capabilities(): Capabilities;
@@ -39,21 +119,98 @@ export interface Capabilities {
39
119
  render: boolean;
40
120
  }
41
121
 
122
+ /** A rectangle in the sheet frame: points, y up, with A1's top-left corner at `(0, height)`. */
123
+ export interface CellBox {
124
+ x0: number;
125
+ y0: number;
126
+ x1: number;
127
+ y1: number;
128
+ }
129
+
130
+ export interface ChoiceOption {
131
+ exportValue: string;
132
+ displayValue: string;
133
+ }
134
+
135
+ /**
136
+ * Which tier named the currency: evidence on the page (an ISO code or an unambiguous glyph),
137
+ * content priors such as the vendor's country, the caller's option, or nothing.
138
+ */
139
+ export type CurrencySource = "Page" | "Content" | "Option" | "Unknown";
140
+
141
+ /** `value` is an ISO 8601 calendar date, `YYYY-MM-DD`. */
142
+ export interface DateField {
143
+ value: string;
144
+ text: string;
145
+ confidence: number;
146
+ span?: FieldSpan;
147
+ }
148
+
149
+ export type DateOrder = "Auto" | "MDY" | "DMY" | "YMD";
150
+
151
+ /** `Pdf`, `Xlsx`, or `Unknown` with what the buffer was instead. */
152
+ export declare function detectFormat(buffer: Buffer): FormatDetection;
153
+
154
+ /** `detectFormat` off the JavaScript thread: a zip's package directory is read to name it. */
155
+ export declare function detectFormatAsync(buffer: Buffer): Promise<FormatDetection>;
156
+
157
+ /** What `detectFormat` and `PdfDown` recognise. */
158
+ export type DocumentFormat = "Pdf" | "Xlsx" | "Unknown";
159
+
160
+ export type EInvoiceStandard = "FacturX" | "ZUGFeRD" | "XRechnung" | "UBL" | "Unknown";
161
+
162
+ export interface EmbeddedInvoiceXml {
163
+ filename: string;
164
+ standard: EInvoiceStandard;
165
+ /**
166
+ * The guideline / customization identifier, e.g.
167
+ * `urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic`.
168
+ */
169
+ profile?: string;
170
+ xml: string;
171
+ }
172
+
42
173
  export declare function extractAnnotationsPerPage(buffer: Buffer): Array<PageAnnotation>;
43
174
 
44
- export declare function extractAnnotationsPerPageAsync(
45
- buffer: Buffer,
46
- ): Promise<Array<PageAnnotation>>;
175
+ export declare function extractAnnotationsPerPageAsync(buffer: Buffer): Promise<Array<PageAnnotation>>;
176
+
177
+ export declare function extractFormFieldsPerPage(buffer: Buffer): Array<PageFormField>;
178
+
179
+ export declare function extractFormFieldsPerPageAsync(buffer: Buffer): Promise<Array<PageFormField>>;
47
180
 
48
181
  export declare function extractImagesPerPage(buffer: Buffer): Array<PageImage>;
49
182
 
50
183
  export declare function extractImagesPerPageAsync(buffer: Buffer): Promise<Array<PageImage>>;
51
184
 
52
- export declare function extractStructuredTextPerPage(buffer: Buffer): Array<StructuredPageText>;
185
+ /**
186
+ * Structured invoice data. This version reads embedded Factur-X / ZUGFeRD /
187
+ * XRechnung / UBL XML; documents without it return `source: "None"`.
188
+ */
189
+ export declare function extractInvoice(buffer: Buffer, opts?: InvoiceOptions | undefined | null): InvoiceResult;
53
190
 
54
- export declare function extractStructuredTextPerPageAsync(
191
+ export declare function extractInvoiceAsync(
55
192
  buffer: Buffer,
56
- ): Promise<Array<StructuredPageText>>;
193
+ opts?: InvoiceOptions | undefined | null
194
+ ): Promise<InvoiceResult>;
195
+
196
+ /**
197
+ * Positioned words and lines per page with the OCR cascade: native glyph
198
+ * placement, then OCR of embedded images mapped through their placements,
199
+ * then (with PDFium) OCR of the rasterised page.
200
+ */
201
+ export declare function extractLayoutWithOcrPerPage(
202
+ buffer: Buffer,
203
+ opts?: OcrOptions | undefined | null
204
+ ): Array<PageLayout>;
205
+
206
+ export declare function extractLayoutWithOcrPerPageAsync(
207
+ buffer: Buffer,
208
+ opts?: OcrOptions | undefined | null
209
+ ): Promise<Array<PageLayout>>;
210
+
211
+ export declare function extractStructuredTextPerPage(buffer: Buffer): Array<StructuredPageText>;
212
+
213
+ export declare function extractStructuredTextPerPageAsync(buffer: Buffer): Promise<Array<StructuredPageText>>;
57
214
 
58
215
  export declare function extractTextPerPage(buffer: Buffer): Array<PageText>;
59
216
 
@@ -61,14 +218,216 @@ export declare function extractTextPerPageAsync(buffer: Buffer): Promise<Array<P
61
218
 
62
219
  export declare function extractTextWithOcrPerPage(
63
220
  buffer: Buffer,
64
- opts?: OcrOptions | undefined | null,
221
+ opts?: OcrOptions | undefined | null
65
222
  ): Array<OcrPageText>;
66
223
 
67
224
  export declare function extractTextWithOcrPerPageAsync(
68
225
  buffer: Buffer,
69
- opts?: OcrOptions | undefined | null,
226
+ opts?: OcrOptions | undefined | null
70
227
  ): Promise<Array<OcrPageText>>;
71
228
 
229
+ /** Where a field was read from, in PDF user space on a 1-based page. */
230
+ export interface FieldSpan {
231
+ page: number;
232
+ x0: number;
233
+ y0: number;
234
+ x1: number;
235
+ y1: number;
236
+ }
237
+
238
+ /** The outcome of `detectFormat`: the format, and for `Unknown` what the input was instead. */
239
+ export interface FormatDetection {
240
+ format: DocumentFormat;
241
+ detail?: string;
242
+ }
243
+
244
+ /**
245
+ * Document-level AcroForm facts. Present on `PdfMeta` / `PdfDocument` when `/AcroForm` exists
246
+ * or orphan widgets were found.
247
+ */
248
+ export interface FormInfo {
249
+ /** `/AcroForm` present (false when only orphan widgets were found). */
250
+ hasAcroForm: boolean;
251
+ /** `/AcroForm /XFA` present (XFA is not parsed). */
252
+ hasXfa: boolean;
253
+ needAppearances: boolean;
254
+ sigFlags: number;
255
+ /** Logical fields, placed + unplaced; may differ from `totalFormFields`. */
256
+ fieldCount: number;
257
+ /** Placements; always equals `totalFormFields` and `formFields.length`. */
258
+ widgetCount: number;
259
+ unplacedFields: Array<UnplacedFormField>;
260
+ /** The `/Kids` depth cap was hit somewhere: the result is partial. */
261
+ truncated: boolean;
262
+ /** Dangling references, non-array `/Annots`, non-dictionary `/Kids` entries, depth cap. */
263
+ warnings: Array<string>;
264
+ }
265
+
266
+ export type InvoiceDocumentType = "Invoice" | "CreditNote" | "Unknown";
267
+
268
+ /**
269
+ * Field names mirror the de-facto vocabulary of common invoice extractors so
270
+ * consumers can swap sources with a thin mapper. Naming only: nothing here
271
+ * talks to any service.
272
+ */
273
+ export interface InvoiceFields {
274
+ vendorName?: StringField;
275
+ vendorAddress?: AddressField;
276
+ vendorTaxId?: StringField;
277
+ vendorEmail?: StringField;
278
+ vendorPhone?: StringField;
279
+ vendorWebsite?: StringField;
280
+ customerName?: StringField;
281
+ customerId?: StringField;
282
+ customerAddress?: AddressField;
283
+ customerTaxId?: StringField;
284
+ billingAddress?: AddressField;
285
+ shippingAddress?: AddressField;
286
+ remittanceAddress?: AddressField;
287
+ invoiceId?: StringField;
288
+ invoiceDate?: DateField;
289
+ dueDate?: DateField;
290
+ purchaseOrder?: StringField;
291
+ paymentTerm?: StringField;
292
+ serviceStartDate?: DateField;
293
+ serviceEndDate?: DateField;
294
+ currencyCode?: string;
295
+ subTotal?: MoneyField;
296
+ totalDiscount?: MoneyField;
297
+ totalTax?: MoneyField;
298
+ shippingCost?: MoneyField;
299
+ invoiceTotal?: MoneyField;
300
+ amountDue?: MoneyField;
301
+ previousUnpaidBalance?: MoneyField;
302
+ /** MRO work order / shop order the invoice bills against. */
303
+ workOrder?: StringField;
304
+ /** Aircraft and engines the invoice relates to; empty when none is identified. */
305
+ aircraft: Array<AircraftReference>;
306
+ taxDetails: Array<TaxDetail>;
307
+ paymentDetails: Array<PaymentDetail>;
308
+ items: Array<InvoiceItem>;
309
+ }
310
+
311
+ /**
312
+ * The layout track over pages from anywhere: a PDF's own layout, `layoutWithOcr`, a workbook's
313
+ * logical pages, or pages the caller built.
314
+ */
315
+ export declare function invoiceFromLayout(
316
+ pages: Array<PageLayout>,
317
+ opts?: InvoiceOptions | undefined | null
318
+ ): InvoiceResult;
319
+
320
+ export declare function invoiceFromLayoutAsync(
321
+ pages: Array<PageLayout>,
322
+ opts?: InvoiceOptions | undefined | null
323
+ ): Promise<InvoiceResult>;
324
+
325
+ export interface InvoiceItem {
326
+ description?: StringField;
327
+ productCode?: StringField;
328
+ quantity?: NumberField;
329
+ unit?: StringField;
330
+ unitPrice?: MoneyField;
331
+ taxRate?: NumberField;
332
+ tax?: MoneyField;
333
+ discount?: MoneyField;
334
+ date?: DateField;
335
+ amount?: MoneyField;
336
+ /** Absent when the item came from embedded XML (no page geometry). */
337
+ span?: FieldSpan;
338
+ }
339
+
340
+ /**
341
+ * Options accepted by every invoice entry point. `preferEmbeddedXml` picks the embedded
342
+ * XML over the pages when both exist; `languages`, `currency`, `dateOrder` and
343
+ * `decimalSeparator` steer the page reader where the page leaves a choice;
344
+ * `includeCandidates` lists, in `warnings`, the candidates each field was chosen from;
345
+ * `includeLayout` is reserved.
346
+ */
347
+ export interface InvoiceOptions {
348
+ /** Label lexicons to enable; default `["en"]`. */
349
+ languages?: Array<string>;
350
+ /** ISO 4217 hint when the page shows only symbols. */
351
+ currency?: string;
352
+ dateOrder?: DateOrder;
353
+ decimalSeparator?: "Auto" | "." | ",";
354
+ /** Default `true`. Embedded Factur-X / ZUGFeRD / XRechnung / UBL XML is used when present. */
355
+ preferEmbeddedXml?: boolean;
356
+ /** Reserved; accepted and ignored. */
357
+ includeLayout?: boolean;
358
+ /**
359
+ * Default `false`. Lists, in `warnings`, the candidates each field was chosen from, with
360
+ * their scores.
361
+ */
362
+ includeCandidates?: boolean;
363
+ }
364
+
365
+ export interface InvoiceResult {
366
+ source: InvoiceSource;
367
+ documentType: InvoiceDocumentType;
368
+ /** Document-level confidence, 0..1. */
369
+ confidence: number;
370
+ fields: InvoiceFields;
371
+ warnings: Array<string>;
372
+ embeddedXml?: EmbeddedInvoiceXml;
373
+ /** Which tier named `fields.currencyCode`; absent when no layout pass ran. */
374
+ currencySource?: CurrencySource;
375
+ /** The evidence behind `documentType: CreditNote`; empty otherwise. */
376
+ creditSignals: Array<string>;
377
+ }
378
+
379
+ /**
380
+ * Which extraction path produced the result: embedded XML, the page text (native, OCR,
381
+ * rendered or mixed), a workbook's cells, or `None` when the document had no readable
382
+ * pages and no embedded XML.
383
+ */
384
+ export type InvoiceSource = "EmbeddedXml" | "Native" | "Ocr" | "Rendered" | "Mixed" | "Spreadsheet" | "None";
385
+
386
+ /**
387
+ * The logical pages of a workbook buffer's selected sheets, as `PageLayout` with
388
+ * `source: "Spreadsheet"`.
389
+ */
390
+ export declare function layoutFromXlsx(buffer: Buffer, opts?: SpreadsheetOptions | undefined | null): Array<PageLayout>;
391
+
392
+ export declare function layoutFromXlsxAsync(
393
+ buffer: Buffer,
394
+ opts?: SpreadsheetOptions | undefined | null
395
+ ): Promise<Array<PageLayout>>;
396
+
397
+ /**
398
+ * Positioned words and lines per page from the content stream (native text only).
399
+ * Coordinates are PDF user space in points, y up.
400
+ */
401
+ export declare function layoutPerPage(buffer: Buffer): Array<PageLayout>;
402
+
403
+ export declare function layoutPerPageAsync(buffer: Buffer): Promise<Array<PageLayout>>;
404
+
405
+ /**
406
+ * Money as a JS number plus the exact printed text; `text` is authoritative
407
+ * when cents matter.
408
+ */
409
+ export interface MoneyField {
410
+ value: number;
411
+ text: string;
412
+ confidence: number;
413
+ span?: FieldSpan;
414
+ currencyCode?: string;
415
+ currencySymbol?: string;
416
+ }
417
+
418
+ export interface NumberField {
419
+ value: number;
420
+ text: string;
421
+ confidence: number;
422
+ span?: FieldSpan;
423
+ }
424
+
425
+ /**
426
+ * Whether a Number cell's value is a whole number JavaScript can hold exactly, or a fraction.
427
+ * A percentage is a fraction (50% is 0.5); the subtype is about the value, not the format.
428
+ */
429
+ export type NumberSubtype = "Integer" | "Float";
430
+
72
431
  export interface OcrOptions {
73
432
  lang?: string;
74
433
  minTextLength?: number;
@@ -119,6 +478,177 @@ export interface PageBox {
119
478
  pages?: Array<number>;
120
479
  }
121
480
 
481
+ export type PageFormField =
482
+ | {
483
+ type: "Text";
484
+ page: number;
485
+ rect: Array<number>;
486
+ objectId: string;
487
+ fieldObjectId: string;
488
+ name: string;
489
+ partialName: string;
490
+ widgetIndex: number;
491
+ widgetCount: number;
492
+ value?: string;
493
+ defaultValue?: string;
494
+ tooltip?: string;
495
+ mappingName?: string;
496
+ readOnly: boolean;
497
+ required: boolean;
498
+ noExport: boolean;
499
+ hasActions: boolean;
500
+ multiline: boolean;
501
+ password: boolean;
502
+ comb: boolean;
503
+ richText: boolean;
504
+ maxLen?: number;
505
+ }
506
+ | {
507
+ type: "Checkbox";
508
+ page: number;
509
+ rect: Array<number>;
510
+ objectId: string;
511
+ fieldObjectId: string;
512
+ name: string;
513
+ partialName: string;
514
+ widgetIndex: number;
515
+ widgetCount: number;
516
+ value?: string;
517
+ defaultValue?: string;
518
+ tooltip?: string;
519
+ mappingName?: string;
520
+ readOnly: boolean;
521
+ required: boolean;
522
+ noExport: boolean;
523
+ hasActions: boolean;
524
+ onState?: string;
525
+ exportValue?: string;
526
+ checked: boolean;
527
+ }
528
+ | {
529
+ type: "Radio";
530
+ page: number;
531
+ rect: Array<number>;
532
+ objectId: string;
533
+ fieldObjectId: string;
534
+ name: string;
535
+ partialName: string;
536
+ widgetIndex: number;
537
+ widgetCount: number;
538
+ value?: string;
539
+ defaultValue?: string;
540
+ tooltip?: string;
541
+ mappingName?: string;
542
+ readOnly: boolean;
543
+ required: boolean;
544
+ noExport: boolean;
545
+ hasActions: boolean;
546
+ onState?: string;
547
+ exportValue?: string;
548
+ selected: boolean;
549
+ }
550
+ | {
551
+ type: "ComboBox";
552
+ page: number;
553
+ rect: Array<number>;
554
+ objectId: string;
555
+ fieldObjectId: string;
556
+ name: string;
557
+ partialName: string;
558
+ widgetIndex: number;
559
+ widgetCount: number;
560
+ value?: string;
561
+ defaultValue?: string;
562
+ tooltip?: string;
563
+ mappingName?: string;
564
+ readOnly: boolean;
565
+ required: boolean;
566
+ noExport: boolean;
567
+ hasActions: boolean;
568
+ options: Array<ChoiceOption>;
569
+ editable: boolean;
570
+ }
571
+ | {
572
+ type: "ListBox";
573
+ page: number;
574
+ rect: Array<number>;
575
+ objectId: string;
576
+ fieldObjectId: string;
577
+ name: string;
578
+ partialName: string;
579
+ widgetIndex: number;
580
+ widgetCount: number;
581
+ value?: string;
582
+ defaultValue?: string;
583
+ tooltip?: string;
584
+ mappingName?: string;
585
+ readOnly: boolean;
586
+ required: boolean;
587
+ noExport: boolean;
588
+ hasActions: boolean;
589
+ options: Array<ChoiceOption>;
590
+ multiSelect: boolean;
591
+ values?: Array<string>;
592
+ }
593
+ | {
594
+ type: "PushButton";
595
+ page: number;
596
+ rect: Array<number>;
597
+ objectId: string;
598
+ fieldObjectId: string;
599
+ name: string;
600
+ partialName: string;
601
+ widgetIndex: number;
602
+ widgetCount: number;
603
+ value?: string;
604
+ defaultValue?: string;
605
+ tooltip?: string;
606
+ mappingName?: string;
607
+ readOnly: boolean;
608
+ required: boolean;
609
+ noExport: boolean;
610
+ hasActions: boolean;
611
+ }
612
+ | {
613
+ type: "Signature";
614
+ page: number;
615
+ rect: Array<number>;
616
+ objectId: string;
617
+ fieldObjectId: string;
618
+ name: string;
619
+ partialName: string;
620
+ widgetIndex: number;
621
+ widgetCount: number;
622
+ value?: string;
623
+ defaultValue?: string;
624
+ tooltip?: string;
625
+ mappingName?: string;
626
+ readOnly: boolean;
627
+ required: boolean;
628
+ noExport: boolean;
629
+ hasActions: boolean;
630
+ signed: boolean;
631
+ }
632
+ | {
633
+ type: "Unknown";
634
+ page: number;
635
+ rect: Array<number>;
636
+ objectId: string;
637
+ fieldObjectId: string;
638
+ name: string;
639
+ partialName: string;
640
+ widgetIndex: number;
641
+ widgetCount: number;
642
+ value?: string;
643
+ defaultValue?: string;
644
+ tooltip?: string;
645
+ mappingName?: string;
646
+ readOnly: boolean;
647
+ required: boolean;
648
+ noExport: boolean;
649
+ hasActions: boolean;
650
+ };
651
+
122
652
  export interface PageImage {
123
653
  page: number;
124
654
  imageIndex: number;
@@ -132,11 +662,55 @@ export interface PageImage {
132
662
  objectId: string;
133
663
  }
134
664
 
665
+ export interface PageLayout {
666
+ page: number;
667
+ /**
668
+ * CropBox (fallback MediaBox) size in points. Coordinates in `words`,
669
+ * `lines` and `images` are raw user space, not shifted to this box's origin.
670
+ */
671
+ width: number;
672
+ height: number;
673
+ /** `/Rotate`, reported and not applied. */
674
+ rotate: number;
675
+ /**
676
+ * Clockwise degrees (0, 90, 180, 270) the OCR tiers turned the page so its
677
+ * text reads upright: the turn carrying the most confident OCR text across
678
+ * the page's images (the tiles of a tiled scan vote together). Every word,
679
+ * line and image placement is expressed in that turned frame, and `width`
680
+ * and `height` swap for a quarter turn. An image with more than a few words
681
+ * that reads upright at a different turn is named in a warning: its words
682
+ * read sideways in the page frame. The render tier reads the page as
683
+ * displayed, so its turn includes `/Rotate`. Always 0 for `Native` pages.
684
+ * For any page, displayed coordinates are this frame turned clockwise by
685
+ * `rotate - contentRotation` (mod 360).
686
+ */
687
+ contentRotation: number;
688
+ /**
689
+ * Deepest cascade tier that ran: `Native`, or `Ocr` / `Rendered` on a page
690
+ * whose native words (if any) were kept alongside the OCR words.
691
+ */
692
+ source: TextSource;
693
+ /** Spreadsheet pages only: the sheet this logical page projects. */
694
+ sheet?: string;
695
+ words: Array<TextWord>;
696
+ lines: Array<TextLine>;
697
+ images: Array<PlacedImage>;
698
+ warnings: Array<string>;
699
+ }
700
+
135
701
  export interface PageText {
136
702
  page: number;
137
703
  text: string;
138
704
  }
139
705
 
706
+ export interface PaymentDetail {
707
+ iban?: StringField;
708
+ swift?: StringField;
709
+ bankName?: StringField;
710
+ accountNumber?: StringField;
711
+ routingNumber?: StringField;
712
+ }
713
+
140
714
  export declare function pdfDocument(buffer: Buffer): PdfDocument;
141
715
 
142
716
  export interface PdfDocument {
@@ -156,14 +730,15 @@ export interface PdfDocument {
156
730
  structuredText: Array<StructuredPageText>;
157
731
  images: Array<PageImage>;
158
732
  annotations: Array<PageAnnotation>;
733
+ form?: FormInfo;
734
+ formFields: Array<PageFormField>;
735
+ totalFormFields: number;
736
+ formFieldPages: Array<number>;
159
737
  }
160
738
 
161
739
  export declare function pdfDocumentAsync(buffer: Buffer): Promise<PdfDocument>;
162
740
 
163
- export declare function pdfDocumentOcr(
164
- buffer: Buffer,
165
- opts?: OcrOptions | undefined | null,
166
- ): PdfDocumentOcr;
741
+ export declare function pdfDocumentOcr(buffer: Buffer, opts?: OcrOptions | undefined | null): PdfDocumentOcr;
167
742
 
168
743
  export interface PdfDocumentOcr {
169
744
  version: string;
@@ -182,11 +757,15 @@ export interface PdfDocumentOcr {
182
757
  structuredText: Array<OcrStructuredPageText>;
183
758
  images: Array<PageImage>;
184
759
  annotations: Array<PageAnnotation>;
760
+ form?: FormInfo;
761
+ formFields: Array<PageFormField>;
762
+ totalFormFields: number;
763
+ formFieldPages: Array<number>;
185
764
  }
186
765
 
187
766
  export declare function pdfDocumentOcrAsync(
188
767
  buffer: Buffer,
189
- opts?: OcrOptions | undefined | null,
768
+ opts?: OcrOptions | undefined | null
190
769
  ): Promise<PdfDocumentOcr>;
191
770
 
192
771
  export interface PdfMeta {
@@ -198,12 +777,26 @@ export interface PdfMeta {
198
777
  creationDate?: string;
199
778
  modificationDate?: string;
200
779
  pageBoxes: Array<PageBox>;
780
+ /** AcroForm facts; present when `/AcroForm` exists or orphan widgets were found. */
781
+ form?: FormInfo;
201
782
  }
202
783
 
203
784
  export declare function pdfMetadata(buffer: Buffer): PdfMeta;
204
785
 
205
786
  export declare function pdfMetadataAsync(buffer: Buffer): Promise<PdfMeta>;
206
787
 
788
+ /**
789
+ * Where an image XObject was painted: the unit square under the CTM at the
790
+ * `Do` operator, as an axis-aligned box in user space.
791
+ */
792
+ export interface PlacedImage {
793
+ xobjectName: string;
794
+ x0: number;
795
+ y0: number;
796
+ x1: number;
797
+ y1: number;
798
+ }
799
+
207
800
  export interface RenderedPage {
208
801
  page: number;
209
802
  width: number;
@@ -221,9 +814,221 @@ export interface RenderOptions {
221
814
 
222
815
  export declare function renderPagesAsync(
223
816
  buffer: Buffer,
224
- opts?: RenderOptions | undefined | null,
817
+ opts?: RenderOptions | undefined | null
225
818
  ): Promise<Array<RenderedPage>>;
226
819
 
820
+ /**
821
+ * One cell of a worksheet: a discriminated union on `type` whose typed value is `value`
822
+ * (none for `Blank`): a Number carries the full double plus its `subtype` and the
823
+ * `currencySymbol` its format names; a Date carries an ISO date or date-time; a Time the
824
+ * clock of a time-only cell. `text` is the display text, `raw` the stored spelling (the
825
+ * serial for dates and times), `format` the code that produced `text`, `formula` the expression stored on this
826
+ * cell, `sharedFormula` the master cell when this cell follows a shared formula, `cached`
827
+ * whether a result was stored, `merge` the range this cell anchors, `hidden` whether its row
828
+ * or column is hidden, `box` its rectangle in the sheet frame (a merged anchor spans its
829
+ * range).
830
+ */
831
+ export type SheetCell =
832
+ | {
833
+ type: "Text";
834
+ ref: string;
835
+ row: number;
836
+ col: number;
837
+ text: string;
838
+ raw: string;
839
+ format?: string;
840
+ formatSupported: boolean;
841
+ formula?: string;
842
+ sharedFormula?: string;
843
+ cached: boolean;
844
+ merge?: string;
845
+ hidden: boolean;
846
+ box: CellBox;
847
+ value: string;
848
+ }
849
+ | {
850
+ type: "Number";
851
+ ref: string;
852
+ row: number;
853
+ col: number;
854
+ text: string;
855
+ raw: string;
856
+ format?: string;
857
+ formatSupported: boolean;
858
+ formula?: string;
859
+ sharedFormula?: string;
860
+ cached: boolean;
861
+ merge?: string;
862
+ hidden: boolean;
863
+ box: CellBox;
864
+ value: number;
865
+ subtype: NumberSubtype;
866
+ currencySymbol?: string;
867
+ }
868
+ | {
869
+ type: "Boolean";
870
+ ref: string;
871
+ row: number;
872
+ col: number;
873
+ text: string;
874
+ raw: string;
875
+ format?: string;
876
+ formatSupported: boolean;
877
+ formula?: string;
878
+ sharedFormula?: string;
879
+ cached: boolean;
880
+ merge?: string;
881
+ hidden: boolean;
882
+ box: CellBox;
883
+ value: boolean;
884
+ }
885
+ | {
886
+ type: "Error";
887
+ ref: string;
888
+ row: number;
889
+ col: number;
890
+ text: string;
891
+ raw: string;
892
+ format?: string;
893
+ formatSupported: boolean;
894
+ formula?: string;
895
+ sharedFormula?: string;
896
+ cached: boolean;
897
+ merge?: string;
898
+ hidden: boolean;
899
+ box: CellBox;
900
+ value: string;
901
+ }
902
+ | {
903
+ type: "Date";
904
+ ref: string;
905
+ row: number;
906
+ col: number;
907
+ text: string;
908
+ raw: string;
909
+ format?: string;
910
+ formatSupported: boolean;
911
+ formula?: string;
912
+ sharedFormula?: string;
913
+ cached: boolean;
914
+ merge?: string;
915
+ hidden: boolean;
916
+ box: CellBox;
917
+ value: string;
918
+ }
919
+ | {
920
+ type: "Time";
921
+ ref: string;
922
+ row: number;
923
+ col: number;
924
+ text: string;
925
+ raw: string;
926
+ format?: string;
927
+ formatSupported: boolean;
928
+ formula?: string;
929
+ sharedFormula?: string;
930
+ cached: boolean;
931
+ merge?: string;
932
+ hidden: boolean;
933
+ box: CellBox;
934
+ value: string;
935
+ }
936
+ | {
937
+ type: "Blank";
938
+ ref: string;
939
+ row: number;
940
+ col: number;
941
+ text: string;
942
+ raw: string;
943
+ format?: string;
944
+ formatSupported: boolean;
945
+ formula?: string;
946
+ sharedFormula?: string;
947
+ cached: boolean;
948
+ merge?: string;
949
+ hidden: boolean;
950
+ box: CellBox;
951
+ };
952
+
953
+ /** One selected worksheet's cells, with the sheet facts a reader needs beside them. */
954
+ export interface SheetCells {
955
+ sheet: string;
956
+ /** Position in the workbook, 0-based. */
957
+ index: number;
958
+ hidden: boolean;
959
+ /** The declared `<dimension>`, which a producer may overstate. */
960
+ dimension?: string;
961
+ printArea?: string;
962
+ /** Merged ranges in A1 form. */
963
+ merges: Array<string>;
964
+ /**
965
+ * The sheet frame's size in points: A1 to the last non-empty cell or merged range, with hidden
966
+ * rows and columns counted or not per `hiddenCells`.
967
+ */
968
+ width: number;
969
+ height: number;
970
+ /** Points; what a column or row absent from `columns` / `rows` measures. */
971
+ defaultColumnWidth: number;
972
+ defaultRowHeight: number;
973
+ /** Only the columns and rows that differ from the default or are hidden. */
974
+ columns: Array<SheetColumn>;
975
+ rows: Array<SheetRow>;
976
+ warnings: Array<string>;
977
+ cells: Array<SheetCell>;
978
+ }
979
+
980
+ /** A column whose width differs from the sheet default, or that is hidden. 0-based. */
981
+ export interface SheetColumn {
982
+ index: number;
983
+ /** Points; zero for a hidden column when hidden cells are excluded. */
984
+ width: number;
985
+ hidden: boolean;
986
+ }
987
+
988
+ /**
989
+ * A row whose height differs from the sheet default (auto-fit growth included), or that is
990
+ * hidden. 0-based.
991
+ */
992
+ export interface SheetRow {
993
+ index: number;
994
+ /** Points; zero for a hidden row when hidden cells are excluded. */
995
+ height: number;
996
+ hidden: boolean;
997
+ }
998
+
999
+ /** The cells of a workbook buffer's selected sheets. */
1000
+ export declare function spreadsheetCells(
1001
+ buffer: Buffer,
1002
+ opts?: SpreadsheetOptions | undefined | null
1003
+ ): Array<SheetCells>;
1004
+
1005
+ export declare function spreadsheetCellsAsync(
1006
+ buffer: Buffer,
1007
+ opts?: SpreadsheetOptions | undefined | null
1008
+ ): Promise<Array<SheetCells>>;
1009
+
1010
+ /** Workbook options shared by `spreadsheetCells` and `layout`. */
1011
+ export interface SpreadsheetOptions {
1012
+ /** Sheet names to include, in workbook order; default: every visible sheet. */
1013
+ sheets?: Array<string>;
1014
+ /** Include hidden sheets (default false). */
1015
+ hiddenSheets?: boolean;
1016
+ /**
1017
+ * Cells in hidden rows and columns. For `spreadsheetCells` the default is true: they are listed
1018
+ * with `hidden: true`. For `layout` the default is false: zero extent and omitted; true gives
1019
+ * them their real extents back.
1020
+ */
1021
+ hiddenCells?: boolean;
1022
+ }
1023
+
1024
+ export interface StringField {
1025
+ value: string;
1026
+ /** The exact source text the value was derived from. */
1027
+ text: string;
1028
+ confidence: number;
1029
+ span?: FieldSpan;
1030
+ }
1031
+
227
1032
  export interface StructuredPageText {
228
1033
  page: number;
229
1034
  header: string;
@@ -231,4 +1036,101 @@ export interface StructuredPageText {
231
1036
  footer: string;
232
1037
  }
233
1038
 
234
- export type TextSource = "Native" | "Ocr" | "Rendered";
1039
+ export interface TaxDetail {
1040
+ rate?: NumberField;
1041
+ amount?: MoneyField;
1042
+ base?: MoneyField;
1043
+ category?: StringField;
1044
+ }
1045
+
1046
+ /**
1047
+ * Words sharing a baseline band, left to right. `firstWord` / `wordCount`
1048
+ * address a contiguous slice of `PageLayout.words`.
1049
+ */
1050
+ export interface TextLine {
1051
+ text: string;
1052
+ x0: number;
1053
+ y0: number;
1054
+ x1: number;
1055
+ y1: number;
1056
+ firstWord: number;
1057
+ wordCount: number;
1058
+ }
1059
+
1060
+ /**
1061
+ * The deepest tier of the OCR cascade that ran for a page: `Native` when the
1062
+ * page's own glyphs were the page, `Ocr` when its embedded rasters were OCR'd,
1063
+ * `Rendered` when the page was rasterised and OCR'd (only with the `render`
1064
+ * feature). A hybrid page keeps its native words alongside the OCR words and
1065
+ * still reports the OCR tier, even when that tier added no words; tell the
1066
+ * two apart by `confidence`, which only OCR words carry, and see the "native
1067
+ * words kept" warnings. `Spreadsheet` is the logical page of a workbook sheet,
1068
+ * laid out from column widths and row heights. Present in every build.
1069
+ */
1070
+ export type TextSource = "Native" | "Ocr" | "Rendered" | "Spreadsheet";
1071
+
1072
+ /** One word with its box in PDF user space (points, y up). */
1073
+ export interface TextWord {
1074
+ text: string;
1075
+ x0: number;
1076
+ y0: number;
1077
+ x1: number;
1078
+ y1: number;
1079
+ /** Index into `PageLayout.lines`. */
1080
+ line: number;
1081
+ /** Native only: font size in user space (after the CTM), in points. */
1082
+ fontSize?: number;
1083
+ /** Native only: base font name with any subset prefix stripped. */
1084
+ fontName?: string;
1085
+ /**
1086
+ * Native: from the font descriptor and name; absent when the font gives no weight evidence
1087
+ * (anonymous names such as `CIDFont+F1`) and for OCR words.
1088
+ */
1089
+ bold?: boolean;
1090
+ italic?: boolean;
1091
+ /** Native only: true when the word is set in a barcode font, so its glyphs are bars, not letters. */
1092
+ symbolic?: boolean;
1093
+ /** OCR only: Tesseract word confidence, 0..1. */
1094
+ confidence?: number;
1095
+ /**
1096
+ * Spreadsheet only: the reference of the cell this word was laid out from (`"C3"`); the
1097
+ * anchor for a merged range.
1098
+ */
1099
+ cell?: string;
1100
+ }
1101
+
1102
+ /**
1103
+ * A logical field with no widget placed on any page. Keeps the full field payload; only
1104
+ * geometry and per-widget state are absent.
1105
+ */
1106
+ export interface UnplacedFormField {
1107
+ /**
1108
+ * `"N G obj"`, or `"<parent fieldObjectId>/kid I"` / `"/Fields I"` when the field
1109
+ * dictionary itself is written inline.
1110
+ */
1111
+ fieldObjectId: string;
1112
+ name: string;
1113
+ partialName: string;
1114
+ type: PageFormField["type"];
1115
+ value?: string;
1116
+ /** Multi-select list boxes. */
1117
+ values?: Array<string>;
1118
+ defaultValue?: string;
1119
+ tooltip?: string;
1120
+ mappingName?: string;
1121
+ /** Choice fields. */
1122
+ options?: Array<ChoiceOption>;
1123
+ maxLen?: number;
1124
+ readOnly: boolean;
1125
+ required: boolean;
1126
+ noExport: boolean;
1127
+ hasActions: boolean;
1128
+ multiline: boolean;
1129
+ password: boolean;
1130
+ comb: boolean;
1131
+ richText: boolean;
1132
+ editable: boolean;
1133
+ multiSelect: boolean;
1134
+ /** Signature fields: signature data present in /V (not cryptographic validation). */
1135
+ signed: boolean;
1136
+ }