mindee 4.13.0 → 4.14.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/CHANGELOG.md +14 -0
- package/package.json +1 -1
- package/src/cli.js +108 -48
- package/src/imageOperations/{extractedImage.d.ts → common/extractedImage.d.ts} +6 -3
- package/src/imageOperations/{extractedImage.js → common/extractedImage.js} +6 -3
- package/src/imageOperations/common/imageExtractor.d.ts +9 -0
- package/src/imageOperations/common/imageExtractor.js +34 -0
- package/src/imageOperations/common/index.d.ts +2 -0
- package/src/imageOperations/common/index.js +7 -0
- package/src/imageOperations/index.d.ts +2 -4
- package/src/imageOperations/index.js +3 -5
- package/src/imageOperations/internal.d.ts +3 -5
- package/src/imageOperations/internal.js +5 -7
- package/src/imageOperations/{extractedInvoiceSplitterDocument.d.ts → invoiceSplitterExtractor/extractedInvoiceSplitterImage.d.ts} +4 -1
- package/src/imageOperations/{extractedInvoiceSplitterDocument.js → invoiceSplitterExtractor/extractedInvoiceSplitterImage.js} +4 -1
- package/src/imageOperations/invoiceSplitterExtractor/index.d.ts +2 -0
- package/src/imageOperations/invoiceSplitterExtractor/index.js +7 -0
- package/src/imageOperations/{invoiceSplitterExtractor.d.ts → invoiceSplitterExtractor/invoiceSplitterExtractor.d.ts} +3 -3
- package/src/imageOperations/{invoiceSplitterExtractor.js → invoiceSplitterExtractor/invoiceSplitterExtractor.js} +4 -4
- package/src/imageOperations/{extractedMultiReceiptImage.d.ts → multiReceiptsExtractor/extractedMultiReceiptImage.d.ts} +4 -1
- package/src/imageOperations/{extractedMultiReceiptImage.js → multiReceiptsExtractor/extractedMultiReceiptImage.js} +5 -2
- package/src/imageOperations/multiReceiptsExtractor/index.d.ts +2 -0
- package/src/imageOperations/multiReceiptsExtractor/index.js +7 -0
- package/src/imageOperations/{multiReceiptsExtractor.d.ts → multiReceiptsExtractor/multiReceiptsExtractor.d.ts} +3 -3
- package/src/imageOperations/{multiReceiptsExtractor.js → multiReceiptsExtractor/multiReceiptsExtractor.js} +22 -25
- package/src/parsing/standard/companyRegistration.d.ts +3 -0
- package/src/parsing/standard/companyRegistration.js +15 -0
- package/src/product/financialDocument/financialDocumentV1Document.d.ts +1 -1
- package/src/product/financialDocument/financialDocumentV1Document.js +3 -2
- package/src/product/financialDocument/financialDocumentV1LineItem.d.ts +2 -0
- package/src/product/financialDocument/financialDocumentV1LineItem.js +10 -0
- package/src/product/internationalId/internationalIdV2Document.d.ts +1 -1
- package/src/product/internationalId/internationalIdV2Document.js +1 -1
- package/src/product/invoice/invoiceV4Document.d.ts +1 -1
- package/src/product/invoice/invoiceV4Document.js +3 -2
- package/src/product/invoice/invoiceV4LineItem.d.ts +2 -0
- package/src/product/invoice/invoiceV4LineItem.js +10 -0
- package/src/product/multiReceiptsDetector/multiReceiptsDetectorV1Document.d.ts +1 -1
- package/src/product/multiReceiptsDetector/multiReceiptsDetectorV1Document.js +1 -1
- package/src/product/receipt/receiptV5Document.d.ts +1 -1
- package/src/product/receipt/receiptV5Document.js +1 -1
- package/src/product/us/healthcareCard/healthcareCardV1.d.ts +16 -0
- package/src/product/us/healthcareCard/healthcareCardV1.js +27 -0
- package/src/product/us/healthcareCard/healthcareCardV1Copay.d.ts +30 -0
- package/src/product/us/healthcareCard/healthcareCardV1Copay.js +66 -0
- package/src/product/us/healthcareCard/healthcareCardV1Document.d.ts +37 -0
- package/src/product/us/healthcareCard/healthcareCardV1Document.js +96 -0
- package/src/product/us/healthcareCard/index.d.ts +3 -0
- package/src/product/us/healthcareCard/index.js +9 -0
- package/src/product/us/index.d.ts +2 -1
- package/src/product/us/index.js +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.14.0 - 2024-07-24
|
|
4
|
+
### Changes
|
|
5
|
+
* :sparkles: add support for Healthcare Card V1
|
|
6
|
+
* :sparkles: add support for Invoice V4.7
|
|
7
|
+
* :sparkles: add support for Financial Document V1.9
|
|
8
|
+
* :recycle: update display for registration field
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## v4.13.1 - 2024-06-10
|
|
12
|
+
### Fixes
|
|
13
|
+
* :recycle: refactored image extraction module to allow for more generic manipulations
|
|
14
|
+
* :recycle: add tests for multipage receipts extraction
|
|
15
|
+
|
|
16
|
+
|
|
3
17
|
## v4.13.0 - 2024-05-28
|
|
4
18
|
### Changes
|
|
5
19
|
* :sparkles: add support for local response loading
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -58,6 +58,16 @@ const CLI_COMMAND_CONFIG = new Map([
|
|
|
58
58
|
sync: true,
|
|
59
59
|
},
|
|
60
60
|
],
|
|
61
|
+
[
|
|
62
|
+
"barcode-reader",
|
|
63
|
+
{
|
|
64
|
+
displayName: "Barcode Reader",
|
|
65
|
+
docClass: product.BarcodeReaderV1,
|
|
66
|
+
allWords: true,
|
|
67
|
+
async: false,
|
|
68
|
+
sync: true,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
61
71
|
[
|
|
62
72
|
"cropper",
|
|
63
73
|
{
|
|
@@ -69,125 +79,145 @@ const CLI_COMMAND_CONFIG = new Map([
|
|
|
69
79
|
},
|
|
70
80
|
],
|
|
71
81
|
[
|
|
72
|
-
"
|
|
82
|
+
"financial",
|
|
73
83
|
{
|
|
74
|
-
displayName: "
|
|
75
|
-
docClass: product.
|
|
76
|
-
allWords:
|
|
84
|
+
displayName: "Financial Document",
|
|
85
|
+
docClass: product.FinancialDocumentV1,
|
|
86
|
+
allWords: true,
|
|
77
87
|
async: true,
|
|
78
|
-
sync:
|
|
88
|
+
sync: true,
|
|
79
89
|
},
|
|
80
90
|
],
|
|
81
91
|
[
|
|
82
|
-
"
|
|
92
|
+
"fr-bank-account-details",
|
|
83
93
|
{
|
|
84
|
-
displayName: "
|
|
85
|
-
docClass: product.
|
|
86
|
-
allWords:
|
|
94
|
+
displayName: "FR Bank Account Details",
|
|
95
|
+
docClass: product.fr.BankAccountDetailsV2,
|
|
96
|
+
allWords: false,
|
|
87
97
|
async: false,
|
|
88
98
|
sync: true,
|
|
89
99
|
},
|
|
90
100
|
],
|
|
91
101
|
[
|
|
92
|
-
"
|
|
102
|
+
"fr-id-card",
|
|
93
103
|
{
|
|
94
|
-
displayName: "
|
|
95
|
-
docClass: product.
|
|
104
|
+
displayName: "FR ID Card",
|
|
105
|
+
docClass: product.fr.IdCardV1,
|
|
96
106
|
allWords: false,
|
|
97
|
-
async:
|
|
98
|
-
sync:
|
|
107
|
+
async: false,
|
|
108
|
+
sync: true,
|
|
99
109
|
},
|
|
100
110
|
],
|
|
101
111
|
[
|
|
102
|
-
"
|
|
112
|
+
"fr-carte-vitale",
|
|
103
113
|
{
|
|
104
|
-
displayName: "
|
|
105
|
-
docClass: product.
|
|
106
|
-
allWords:
|
|
114
|
+
displayName: "FR Carte Vitale",
|
|
115
|
+
docClass: product.fr.CarteVitaleV1,
|
|
116
|
+
allWords: false,
|
|
107
117
|
async: false,
|
|
108
118
|
sync: true,
|
|
109
119
|
},
|
|
110
120
|
],
|
|
111
121
|
[
|
|
112
|
-
"
|
|
122
|
+
"fr-carte-grise",
|
|
113
123
|
{
|
|
114
|
-
displayName: "
|
|
115
|
-
docClass: product.
|
|
124
|
+
displayName: "FR Carte Grise",
|
|
125
|
+
docClass: product.fr.CarteGriseV1,
|
|
116
126
|
allWords: false,
|
|
117
|
-
async:
|
|
118
|
-
sync:
|
|
127
|
+
async: false,
|
|
128
|
+
sync: true,
|
|
119
129
|
},
|
|
120
130
|
],
|
|
121
131
|
[
|
|
122
|
-
"
|
|
132
|
+
"eu-license-plate",
|
|
123
133
|
{
|
|
124
|
-
displayName: "
|
|
125
|
-
docClass: product.
|
|
134
|
+
displayName: "EU License Plate",
|
|
135
|
+
docClass: product.eu.LicensePlateV1,
|
|
126
136
|
allWords: false,
|
|
127
137
|
async: false,
|
|
128
138
|
sync: true,
|
|
129
139
|
},
|
|
130
140
|
],
|
|
131
141
|
[
|
|
132
|
-
"
|
|
142
|
+
"eu-driver-license",
|
|
133
143
|
{
|
|
134
|
-
displayName: "
|
|
135
|
-
docClass: product.
|
|
136
|
-
allWords:
|
|
144
|
+
displayName: "EU Driver License",
|
|
145
|
+
docClass: product.eu.DriverLicenseV1,
|
|
146
|
+
allWords: false,
|
|
137
147
|
async: false,
|
|
138
148
|
sync: true,
|
|
139
149
|
},
|
|
140
150
|
],
|
|
141
151
|
[
|
|
142
|
-
"
|
|
152
|
+
"international-id",
|
|
143
153
|
{
|
|
144
|
-
displayName: "
|
|
145
|
-
docClass: product.
|
|
154
|
+
displayName: "International Id",
|
|
155
|
+
docClass: product.InternationalIdV2,
|
|
146
156
|
allWords: false,
|
|
157
|
+
async: true,
|
|
158
|
+
sync: false,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
[
|
|
162
|
+
"invoice",
|
|
163
|
+
{
|
|
164
|
+
displayName: "Invoice",
|
|
165
|
+
docClass: product.InvoiceV4,
|
|
166
|
+
allWords: true,
|
|
147
167
|
async: false,
|
|
148
168
|
sync: true,
|
|
149
169
|
},
|
|
150
170
|
],
|
|
151
171
|
[
|
|
152
|
-
"
|
|
172
|
+
"invoice-splitter",
|
|
153
173
|
{
|
|
154
|
-
displayName: "
|
|
155
|
-
docClass: product.
|
|
174
|
+
displayName: "Invoice Splitter",
|
|
175
|
+
docClass: product.InvoiceSplitterV1,
|
|
156
176
|
allWords: false,
|
|
157
|
-
async:
|
|
158
|
-
sync:
|
|
177
|
+
async: true,
|
|
178
|
+
sync: false,
|
|
159
179
|
},
|
|
160
180
|
],
|
|
161
181
|
[
|
|
162
|
-
"
|
|
182
|
+
"multi-receipts-detector",
|
|
163
183
|
{
|
|
164
|
-
displayName: "
|
|
165
|
-
docClass: product.
|
|
184
|
+
displayName: "Multi Receipts Detector",
|
|
185
|
+
docClass: product.MultiReceiptsDetectorV1,
|
|
166
186
|
allWords: false,
|
|
167
187
|
async: false,
|
|
168
188
|
sync: true,
|
|
169
189
|
},
|
|
170
190
|
],
|
|
171
191
|
[
|
|
172
|
-
"
|
|
192
|
+
"passport",
|
|
173
193
|
{
|
|
174
|
-
displayName: "
|
|
175
|
-
docClass: product.
|
|
194
|
+
displayName: "Passport",
|
|
195
|
+
docClass: product.PassportV1,
|
|
176
196
|
allWords: false,
|
|
177
197
|
async: false,
|
|
178
198
|
sync: true,
|
|
179
199
|
},
|
|
180
200
|
],
|
|
181
201
|
[
|
|
182
|
-
"
|
|
202
|
+
"receipt",
|
|
183
203
|
{
|
|
184
|
-
displayName: "
|
|
185
|
-
docClass: product.
|
|
186
|
-
allWords:
|
|
204
|
+
displayName: "Expense Receipt",
|
|
205
|
+
docClass: product.ReceiptV5,
|
|
206
|
+
allWords: true,
|
|
187
207
|
async: false,
|
|
188
208
|
sync: true,
|
|
189
209
|
},
|
|
190
210
|
],
|
|
211
|
+
[
|
|
212
|
+
"resume",
|
|
213
|
+
{
|
|
214
|
+
displayName: "Resume",
|
|
215
|
+
docClass: product.ResumeV1,
|
|
216
|
+
allWords: false,
|
|
217
|
+
async: true,
|
|
218
|
+
sync: false,
|
|
219
|
+
},
|
|
220
|
+
],
|
|
191
221
|
[
|
|
192
222
|
"us-bank-check",
|
|
193
223
|
{
|
|
@@ -208,6 +238,36 @@ const CLI_COMMAND_CONFIG = new Map([
|
|
|
208
238
|
sync: true,
|
|
209
239
|
},
|
|
210
240
|
],
|
|
241
|
+
[
|
|
242
|
+
"us-healthcare-card",
|
|
243
|
+
{
|
|
244
|
+
displayName: "US Healthcare Card",
|
|
245
|
+
docClass: product.us.HealthcareCardV1,
|
|
246
|
+
allWords: false,
|
|
247
|
+
async: true,
|
|
248
|
+
sync: false,
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
[
|
|
252
|
+
"us-mail",
|
|
253
|
+
{
|
|
254
|
+
displayName: "US Mail",
|
|
255
|
+
docClass: product.us.UsMailV2,
|
|
256
|
+
allWords: false,
|
|
257
|
+
async: true,
|
|
258
|
+
sync: false,
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
[
|
|
262
|
+
"us-w9",
|
|
263
|
+
{
|
|
264
|
+
displayName: "US W9",
|
|
265
|
+
docClass: product.us.W9V1,
|
|
266
|
+
allWords: false,
|
|
267
|
+
async: true,
|
|
268
|
+
sync: false,
|
|
269
|
+
},
|
|
270
|
+
],
|
|
211
271
|
]);
|
|
212
272
|
//
|
|
213
273
|
// EXECUTE THE COMMANDS
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Buffer } from "node:buffer";
|
|
3
|
-
import { BufferInput } from "
|
|
4
|
-
|
|
3
|
+
import { BufferInput } from "../../input";
|
|
4
|
+
/**
|
|
5
|
+
* Generic class for image extraction
|
|
6
|
+
*/
|
|
7
|
+
export declare class ExtractedImage {
|
|
5
8
|
buffer: Buffer;
|
|
6
9
|
protected internalFileName: string;
|
|
7
|
-
constructor(buffer: Uint8Array, fileName: string);
|
|
10
|
+
protected constructor(buffer: Uint8Array, fileName: string);
|
|
8
11
|
/**
|
|
9
12
|
* Saves the document to a file.
|
|
10
13
|
*
|
|
@@ -5,11 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ExtractedImage = void 0;
|
|
7
7
|
const node_buffer_1 = require("node:buffer");
|
|
8
|
-
const errors_1 = require("
|
|
8
|
+
const errors_1 = require("../../errors");
|
|
9
9
|
const node_fs_1 = require("node:fs");
|
|
10
10
|
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const logger_1 = require("
|
|
12
|
-
const input_1 = require("
|
|
11
|
+
const logger_1 = require("../../logger");
|
|
12
|
+
const input_1 = require("../../input");
|
|
13
|
+
/**
|
|
14
|
+
* Generic class for image extraction
|
|
15
|
+
*/
|
|
13
16
|
class ExtractedImage {
|
|
14
17
|
constructor(buffer, fileName) {
|
|
15
18
|
this.buffer = node_buffer_1.Buffer.from(buffer);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PDFPage } from "pdf-lib";
|
|
2
|
+
import { Polygon } from "../../geometry";
|
|
3
|
+
/**
|
|
4
|
+
* Extracts elements from a page based off of a list of bounding boxes.
|
|
5
|
+
*
|
|
6
|
+
* @param pdfPage PDF Page to extract from.
|
|
7
|
+
* @param polygons List of coordinates to pull the elements from.
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractFromPage(pdfPage: PDFPage, polygons: Polygon[]): Promise<Uint8Array[]>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractFromPage = void 0;
|
|
4
|
+
const pdf_lib_1 = require("pdf-lib");
|
|
5
|
+
const geometry_1 = require("../../geometry");
|
|
6
|
+
/**
|
|
7
|
+
* Extracts elements from a page based off of a list of bounding boxes.
|
|
8
|
+
*
|
|
9
|
+
* @param pdfPage PDF Page to extract from.
|
|
10
|
+
* @param polygons List of coordinates to pull the elements from.
|
|
11
|
+
*/
|
|
12
|
+
async function extractFromPage(pdfPage, polygons) {
|
|
13
|
+
const { width, height } = pdfPage.getSize();
|
|
14
|
+
const extractedElements = [];
|
|
15
|
+
for (const polygon of polygons) {
|
|
16
|
+
const tempPdf = await pdf_lib_1.PDFDocument.create();
|
|
17
|
+
const newWidth = width * ((0, geometry_1.getMinMaxX)(polygon).max - (0, geometry_1.getMinMaxX)(polygon).min);
|
|
18
|
+
const newHeight = height * ((0, geometry_1.getMinMaxY)(polygon).max - (0, geometry_1.getMinMaxY)(polygon).min);
|
|
19
|
+
const cropped = await tempPdf.embedPage(pdfPage, {
|
|
20
|
+
left: (0, geometry_1.getMinMaxX)(polygon).min * width,
|
|
21
|
+
right: (0, geometry_1.getMinMaxX)(polygon).max * width,
|
|
22
|
+
top: height - ((0, geometry_1.getMinMaxY)(polygon).min * height),
|
|
23
|
+
bottom: height - ((0, geometry_1.getMinMaxY)(polygon).max * height),
|
|
24
|
+
});
|
|
25
|
+
const samplePage = tempPdf.addPage([newWidth, newHeight]);
|
|
26
|
+
samplePage.drawPage(cropped, {
|
|
27
|
+
width: newWidth,
|
|
28
|
+
height: newHeight,
|
|
29
|
+
});
|
|
30
|
+
extractedElements.push(await tempPdf.save());
|
|
31
|
+
}
|
|
32
|
+
return extractedElements;
|
|
33
|
+
}
|
|
34
|
+
exports.extractFromPage = extractFromPage;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractFromPage = exports.ExtractedImage = void 0;
|
|
4
|
+
var extractedImage_1 = require("./extractedImage");
|
|
5
|
+
Object.defineProperty(exports, "ExtractedImage", { enumerable: true, get: function () { return extractedImage_1.ExtractedImage; } });
|
|
6
|
+
var imageExtractor_1 = require("./imageExtractor");
|
|
7
|
+
Object.defineProperty(exports, "extractFromPage", { enumerable: true, get: function () { return imageExtractor_1.extractFromPage; } });
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export { extractReceipts } from "./multiReceiptsExtractor";
|
|
2
|
-
export { extractInvoices } from "./invoiceSplitterExtractor";
|
|
3
|
-
export { ExtractedMultiReceiptImage } from "./extractedMultiReceiptImage";
|
|
4
|
-
export { ExtractedInvoiceSplitterImage } from "./extractedInvoiceSplitterDocument";
|
|
1
|
+
export { extractReceipts, ExtractedMultiReceiptImage } from "./multiReceiptsExtractor";
|
|
2
|
+
export { extractInvoices, ExtractedInvoiceSplitterImage } from "./invoiceSplitterExtractor";
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExtractedInvoiceSplitterImage = exports.
|
|
3
|
+
exports.ExtractedInvoiceSplitterImage = exports.extractInvoices = exports.ExtractedMultiReceiptImage = exports.extractReceipts = void 0;
|
|
4
4
|
var multiReceiptsExtractor_1 = require("./multiReceiptsExtractor");
|
|
5
5
|
Object.defineProperty(exports, "extractReceipts", { enumerable: true, get: function () { return multiReceiptsExtractor_1.extractReceipts; } });
|
|
6
|
+
Object.defineProperty(exports, "ExtractedMultiReceiptImage", { enumerable: true, get: function () { return multiReceiptsExtractor_1.ExtractedMultiReceiptImage; } });
|
|
6
7
|
var invoiceSplitterExtractor_1 = require("./invoiceSplitterExtractor");
|
|
7
8
|
Object.defineProperty(exports, "extractInvoices", { enumerable: true, get: function () { return invoiceSplitterExtractor_1.extractInvoices; } });
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, "ExtractedMultiReceiptImage", { enumerable: true, get: function () { return extractedMultiReceiptImage_1.ExtractedMultiReceiptImage; } });
|
|
10
|
-
var extractedInvoiceSplitterDocument_1 = require("./extractedInvoiceSplitterDocument");
|
|
11
|
-
Object.defineProperty(exports, "ExtractedInvoiceSplitterImage", { enumerable: true, get: function () { return extractedInvoiceSplitterDocument_1.ExtractedInvoiceSplitterImage; } });
|
|
9
|
+
Object.defineProperty(exports, "ExtractedInvoiceSplitterImage", { enumerable: true, get: function () { return invoiceSplitterExtractor_1.ExtractedInvoiceSplitterImage; } });
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { extractReceipts } from "./multiReceiptsExtractor";
|
|
2
|
-
export { extractInvoices } from "./invoiceSplitterExtractor";
|
|
3
|
-
export {
|
|
4
|
-
export { ExtractedInvoiceSplitterImage } from "./extractedInvoiceSplitterDocument";
|
|
5
|
-
export { ExtractedImage } from "./extractedImage";
|
|
1
|
+
export { extractReceipts, ExtractedMultiReceiptImage } from "./multiReceiptsExtractor";
|
|
2
|
+
export { extractInvoices, ExtractedInvoiceSplitterImage } from "./invoiceSplitterExtractor";
|
|
3
|
+
export { ExtractedImage } from "./common";
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExtractedImage = exports.ExtractedInvoiceSplitterImage = exports.
|
|
3
|
+
exports.ExtractedImage = exports.ExtractedInvoiceSplitterImage = exports.extractInvoices = exports.ExtractedMultiReceiptImage = exports.extractReceipts = void 0;
|
|
4
4
|
var multiReceiptsExtractor_1 = require("./multiReceiptsExtractor");
|
|
5
5
|
Object.defineProperty(exports, "extractReceipts", { enumerable: true, get: function () { return multiReceiptsExtractor_1.extractReceipts; } });
|
|
6
|
+
Object.defineProperty(exports, "ExtractedMultiReceiptImage", { enumerable: true, get: function () { return multiReceiptsExtractor_1.ExtractedMultiReceiptImage; } });
|
|
6
7
|
var invoiceSplitterExtractor_1 = require("./invoiceSplitterExtractor");
|
|
7
8
|
Object.defineProperty(exports, "extractInvoices", { enumerable: true, get: function () { return invoiceSplitterExtractor_1.extractInvoices; } });
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Object.defineProperty(exports, "ExtractedInvoiceSplitterImage", { enumerable: true, get: function () { return extractedInvoiceSplitterDocument_1.ExtractedInvoiceSplitterImage; } });
|
|
12
|
-
var extractedImage_1 = require("./extractedImage");
|
|
13
|
-
Object.defineProperty(exports, "ExtractedImage", { enumerable: true, get: function () { return extractedImage_1.ExtractedImage; } });
|
|
9
|
+
Object.defineProperty(exports, "ExtractedInvoiceSplitterImage", { enumerable: true, get: function () { return invoiceSplitterExtractor_1.ExtractedInvoiceSplitterImage; } });
|
|
10
|
+
var common_1 = require("./common");
|
|
11
|
+
Object.defineProperty(exports, "ExtractedImage", { enumerable: true, get: function () { return common_1.ExtractedImage; } });
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { ExtractedImage } from "
|
|
1
|
+
import { ExtractedImage } from "../common/extractedImage";
|
|
2
|
+
/**
|
|
3
|
+
* Wrapper class for extracted invoice pages.
|
|
4
|
+
*/
|
|
2
5
|
export declare class ExtractedInvoiceSplitterImage extends ExtractedImage {
|
|
3
6
|
readonly pageIdMin: number;
|
|
4
7
|
readonly pageIdMax: number;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExtractedInvoiceSplitterImage = void 0;
|
|
4
|
-
const extractedImage_1 = require("
|
|
4
|
+
const extractedImage_1 = require("../common/extractedImage");
|
|
5
|
+
/**
|
|
6
|
+
* Wrapper class for extracted invoice pages.
|
|
7
|
+
*/
|
|
5
8
|
class ExtractedInvoiceSplitterImage extends extractedImage_1.ExtractedImage {
|
|
6
9
|
constructor(buffer, pageIndices) {
|
|
7
10
|
super(buffer, `invoice_p_${pageIndices[0]}-${pageIndices[1]}.pdf`);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtractedInvoiceSplitterImage = exports.extractInvoices = void 0;
|
|
4
|
+
var invoiceSplitterExtractor_1 = require("./invoiceSplitterExtractor");
|
|
5
|
+
Object.defineProperty(exports, "extractInvoices", { enumerable: true, get: function () { return invoiceSplitterExtractor_1.extractInvoices; } });
|
|
6
|
+
var extractedInvoiceSplitterImage_1 = require("./extractedInvoiceSplitterImage");
|
|
7
|
+
Object.defineProperty(exports, "ExtractedInvoiceSplitterImage", { enumerable: true, get: function () { return extractedInvoiceSplitterImage_1.ExtractedInvoiceSplitterImage; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { InvoiceSplitterV1 } from "
|
|
2
|
-
import { LocalInputSource } from "
|
|
3
|
-
import { ExtractedInvoiceSplitterImage } from "./
|
|
1
|
+
import { InvoiceSplitterV1 } from "../../product";
|
|
2
|
+
import { LocalInputSource } from "../../input/base";
|
|
3
|
+
import { ExtractedInvoiceSplitterImage } from "./extractedInvoiceSplitterImage";
|
|
4
4
|
/**
|
|
5
5
|
* Extracts & cuts the pages of a main document invoice according to the provided indexes.
|
|
6
6
|
*
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractInvoices = void 0;
|
|
4
4
|
const pdf_lib_1 = require("pdf-lib");
|
|
5
|
-
const errors_1 = require("
|
|
6
|
-
const product_1 = require("
|
|
7
|
-
const
|
|
5
|
+
const errors_1 = require("../../errors");
|
|
6
|
+
const product_1 = require("../../product");
|
|
7
|
+
const extractedInvoiceSplitterImage_1 = require("./extractedInvoiceSplitterImage");
|
|
8
8
|
async function splitPdf(pdfDoc, invoicePageGroups) {
|
|
9
9
|
if (invoicePageGroups.length === 0) {
|
|
10
10
|
return [];
|
|
@@ -21,7 +21,7 @@ async function splitPdf(pdfDoc, invoicePageGroups) {
|
|
|
21
21
|
subdocument.addPage(page);
|
|
22
22
|
});
|
|
23
23
|
const subdocumentBytes = await subdocument.save();
|
|
24
|
-
generatedPdfs.push(new
|
|
24
|
+
generatedPdfs.push(new extractedInvoiceSplitterImage_1.ExtractedInvoiceSplitterImage(subdocumentBytes, [invoicePageGroups[i][0], invoicePageGroups[i][invoicePageGroups[i].length - 1]]));
|
|
25
25
|
}
|
|
26
26
|
return generatedPdfs;
|
|
27
27
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { ExtractedImage } from "
|
|
1
|
+
import { ExtractedImage } from "../common";
|
|
2
|
+
/**
|
|
3
|
+
* Wrapper class for extracted multiple-receipts images.
|
|
4
|
+
*/
|
|
2
5
|
export declare class ExtractedMultiReceiptImage extends ExtractedImage {
|
|
3
6
|
readonly receiptId: number;
|
|
4
7
|
readonly pageId: number;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExtractedMultiReceiptImage = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const common_1 = require("../common");
|
|
5
|
+
/**
|
|
6
|
+
* Wrapper class for extracted multiple-receipts images.
|
|
7
|
+
*/
|
|
8
|
+
class ExtractedMultiReceiptImage extends common_1.ExtractedImage {
|
|
6
9
|
constructor(buffer, pageId, receiptId) {
|
|
7
10
|
super(buffer, `receipt_p${pageId}_${receiptId}.pdf`);
|
|
8
11
|
this.pageId = pageId;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtractedMultiReceiptImage = exports.extractReceipts = void 0;
|
|
4
|
+
var multiReceiptsExtractor_1 = require("./multiReceiptsExtractor");
|
|
5
|
+
Object.defineProperty(exports, "extractReceipts", { enumerable: true, get: function () { return multiReceiptsExtractor_1.extractReceipts; } });
|
|
6
|
+
var extractedMultiReceiptImage_1 = require("./extractedMultiReceiptImage");
|
|
7
|
+
Object.defineProperty(exports, "ExtractedMultiReceiptImage", { enumerable: true, get: function () { return extractedMultiReceiptImage_1.ExtractedMultiReceiptImage; } });
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { MultiReceiptsDetectorV1 } from "
|
|
1
|
+
import { MultiReceiptsDetectorV1 } from "../../product";
|
|
2
2
|
import { ExtractedMultiReceiptImage } from "./extractedMultiReceiptImage";
|
|
3
|
-
import { LocalInputSource } from "
|
|
3
|
+
import { LocalInputSource } from "../../input/base";
|
|
4
4
|
/**
|
|
5
5
|
* Extracts individual receipts from multi-receipts documents.
|
|
6
6
|
*
|
|
7
7
|
* @param inputFile File to extract sub-receipts from.
|
|
8
8
|
* @param inference Results of the inference.
|
|
9
|
-
* @returns Individual extracted receipts as an array of
|
|
9
|
+
* @returns Individual extracted receipts as an array of ExtractedMultiReceiptImage.
|
|
10
10
|
*/
|
|
11
11
|
export declare function extractReceipts(inputFile: LocalInputSource, inference: MultiReceiptsDetectorV1): Promise<ExtractedMultiReceiptImage[]>;
|
|
@@ -2,27 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractReceipts = void 0;
|
|
4
4
|
const pdf_lib_1 = require("pdf-lib");
|
|
5
|
-
const errors_1 = require("
|
|
6
|
-
const geometry_1 = require("../geometry");
|
|
5
|
+
const errors_1 = require("../../errors");
|
|
7
6
|
const extractedMultiReceiptImage_1 = require("./extractedMultiReceiptImage");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return new extractedMultiReceiptImage_1.ExtractedMultiReceiptImage(receiptBytes, pageId, receiptId);
|
|
7
|
+
const common_1 = require("../common");
|
|
8
|
+
/**
|
|
9
|
+
* Given a page and a set of coordinates, extracts & assigns individual receipts to an ExtractedMultiReceiptImage
|
|
10
|
+
* object.
|
|
11
|
+
*
|
|
12
|
+
* @param pdfPage PDF Page to extract from.
|
|
13
|
+
* @param boundingBoxes A set of coordinates delimiting the position of each receipt.
|
|
14
|
+
* @param pageId Id of the page the receipt is extracted from. Caution: this starts at 0, unlike the numbering in PDF
|
|
15
|
+
* pages.
|
|
16
|
+
*/
|
|
17
|
+
async function extractReceiptsFromPage(pdfPage, boundingBoxes, pageId) {
|
|
18
|
+
const extractedReceiptsRaw = await (0, common_1.extractFromPage)(pdfPage, boundingBoxes);
|
|
19
|
+
const extractedReceipts = [];
|
|
20
|
+
for (let i = 0; i < extractedReceiptsRaw.length; i++) {
|
|
21
|
+
extractedReceipts.push(new extractedMultiReceiptImage_1.ExtractedMultiReceiptImage(extractedReceiptsRaw[i], pageId, i));
|
|
22
|
+
}
|
|
23
|
+
return extractedReceipts;
|
|
26
24
|
}
|
|
27
25
|
async function loadPdfDoc(inputFile) {
|
|
28
26
|
let pdfDoc;
|
|
@@ -52,7 +50,7 @@ async function loadPdfDoc(inputFile) {
|
|
|
52
50
|
*
|
|
53
51
|
* @param inputFile File to extract sub-receipts from.
|
|
54
52
|
* @param inference Results of the inference.
|
|
55
|
-
* @returns Individual extracted receipts as an array of
|
|
53
|
+
* @returns Individual extracted receipts as an array of ExtractedMultiReceiptImage.
|
|
56
54
|
*/
|
|
57
55
|
async function extractReceipts(inputFile, inference) {
|
|
58
56
|
const images = [];
|
|
@@ -62,10 +60,9 @@ async function extractReceipts(inputFile, inference) {
|
|
|
62
60
|
const pdfDoc = await loadPdfDoc(inputFile);
|
|
63
61
|
for (let pageId = 0; pageId < pdfDoc.getPageCount(); pageId++) {
|
|
64
62
|
const [page] = await pdfDoc.copyPages(pdfDoc, [pageId]);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
63
|
+
const receiptPositions = inference.pages[pageId].prediction.receipts.map((receipt) => receipt.boundingBox);
|
|
64
|
+
const extractedReceipts = await extractReceiptsFromPage(page, receiptPositions, pageId);
|
|
65
|
+
images.push(...extractedReceipts);
|
|
69
66
|
}
|
|
70
67
|
return images;
|
|
71
68
|
}
|
|
@@ -9,4 +9,7 @@ export declare class CompanyRegistrationField extends Field {
|
|
|
9
9
|
/** Type of company registration. */
|
|
10
10
|
type: string;
|
|
11
11
|
constructor({ prediction, valueKey, reconstructed, pageId, }: BaseFieldConstructor);
|
|
12
|
+
toTableLine(): string;
|
|
13
|
+
toString(): string;
|
|
14
|
+
private printableValues;
|
|
12
15
|
}
|