mindee 4.36.0 → 4.36.2

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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v4.36.2 - 2026-01-05
4
+ ### Changes
5
+ * :wastebasket: deprecate docFromXxx methods
6
+
7
+
8
+ ## v4.36.1 - 2025-12-30
9
+ ### Fixes
10
+ * :bug: extracted images should take rotation into account
11
+ * :recycle: fix minor issues with param syntaxes
12
+
13
+
3
14
  ## v4.36.0 - 2025-12-19
4
15
  ### Changes
5
16
  * :sparkles: add support for dataschema param
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "4.36.0",
3
+ "version": "4.36.2",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "main": "src/index.js",
6
6
  "bin": "bin/mindee.js",
package/src/cli.js CHANGED
@@ -77,7 +77,7 @@ async function callParse(productClass, command, inputPath, options) {
77
77
  const mindeeClient = initClient(options);
78
78
  const predictParams = getPredictParams(options);
79
79
  const pageOptions = getPageOptions(options);
80
- const inputSource = mindeeClient.docFromPath(inputPath);
80
+ const inputSource = new input_1.PathInput({ inputPath: inputPath });
81
81
  let response;
82
82
  if (command === cliProducts_1.COMMAND_CUSTOM || command === cliProducts_1.COMMAND_GENERATED) {
83
83
  const customEndpoint = mindeeClient.createEndpoint(options.endpoint, options.account, options.version);
@@ -101,7 +101,7 @@ async function callEnqueueAndParse(productClass, command, inputPath, options) {
101
101
  const mindeeClient = initClient(options);
102
102
  const predictParams = getPredictParams(options);
103
103
  const pageOptions = getPageOptions(options);
104
- const inputSource = mindeeClient.docFromPath(inputPath);
104
+ const inputSource = new input_1.PathInput({ inputPath: inputPath });
105
105
  let response;
106
106
  if (command === cliProducts_1.COMMAND_CUSTOM || command === cliProducts_1.COMMAND_GENERATED) {
107
107
  const customEndpoint = mindeeClient.createEndpoint(options.endpoint, options.account, options.version);
package/src/client.d.ts CHANGED
@@ -215,35 +215,41 @@ export declare class Client {
215
215
  /**
216
216
  * Load an input document from a local path.
217
217
  * @param inputPath
218
+ * @deprecated Use `new mindee.PathInput()` instead.
218
219
  */
219
220
  docFromPath(inputPath: string): PathInput;
220
221
  /**
221
222
  * Load an input document from a base64 encoded string.
222
223
  * @param inputString input content, as a string.
223
224
  * @param filename file name.
225
+ * @deprecated Use `new mindee.Base64Input()` instead.
224
226
  */
225
227
  docFromBase64(inputString: string, filename: string): Base64Input;
226
228
  /**
227
229
  * Load an input document from a `stream.Readable` object.
228
230
  * @param inputStream input content, as a readable stream.
229
231
  * @param filename file name.
232
+ * @deprecated Use `new mindee.StreamInput()` instead.
230
233
  */
231
234
  docFromStream(inputStream: Readable, filename: string): StreamInput;
232
235
  /**
233
236
  * Load an input document from bytes.
234
237
  * @param inputBytes input content, as a Uint8Array or Buffer.
235
238
  * @param filename file name.
239
+ * @deprecated Use `new mindee.BytesInput()` instead.
236
240
  */
237
241
  docFromBytes(inputBytes: Uint8Array, filename: string): BytesInput;
238
242
  /**
239
243
  * Load an input document from a URL.
240
244
  * @param url input url. Must be HTTPS.
245
+ * @deprecated Use `new mindee.UrlInput()` instead.
241
246
  */
242
247
  docFromUrl(url: string): UrlInput;
243
248
  /**
244
249
  * Load an input document from a Buffer.
245
250
  * @param buffer input content, as a buffer.
246
251
  * @param filename file name.
252
+ * @deprecated Use `new mindee.BufferInput()` instead.
247
253
  */
248
254
  docFromBuffer(buffer: Buffer, filename: string): BufferInput;
249
255
  }
package/src/client.js CHANGED
@@ -274,6 +274,7 @@ Job status: ${pollResults.job.status}.`);
274
274
  /**
275
275
  * Load an input document from a local path.
276
276
  * @param inputPath
277
+ * @deprecated Use `new mindee.PathInput()` instead.
277
278
  */
278
279
  docFromPath(inputPath) {
279
280
  return new input_1.PathInput({
@@ -284,6 +285,7 @@ Job status: ${pollResults.job.status}.`);
284
285
  * Load an input document from a base64 encoded string.
285
286
  * @param inputString input content, as a string.
286
287
  * @param filename file name.
288
+ * @deprecated Use `new mindee.Base64Input()` instead.
287
289
  */
288
290
  docFromBase64(inputString, filename) {
289
291
  return new input_1.Base64Input({
@@ -295,6 +297,7 @@ Job status: ${pollResults.job.status}.`);
295
297
  * Load an input document from a `stream.Readable` object.
296
298
  * @param inputStream input content, as a readable stream.
297
299
  * @param filename file name.
300
+ * @deprecated Use `new mindee.StreamInput()` instead.
298
301
  */
299
302
  docFromStream(inputStream, filename) {
300
303
  return new input_1.StreamInput({
@@ -306,6 +309,7 @@ Job status: ${pollResults.job.status}.`);
306
309
  * Load an input document from bytes.
307
310
  * @param inputBytes input content, as a Uint8Array or Buffer.
308
311
  * @param filename file name.
312
+ * @deprecated Use `new mindee.BytesInput()` instead.
309
313
  */
310
314
  docFromBytes(inputBytes, filename) {
311
315
  return new input_1.BytesInput({
@@ -316,6 +320,7 @@ Job status: ${pollResults.job.status}.`);
316
320
  /**
317
321
  * Load an input document from a URL.
318
322
  * @param url input url. Must be HTTPS.
323
+ * @deprecated Use `new mindee.UrlInput()` instead.
319
324
  */
320
325
  docFromUrl(url) {
321
326
  return new input_1.UrlInput({
@@ -326,6 +331,7 @@ Job status: ${pollResults.job.status}.`);
326
331
  * Load an input document from a Buffer.
327
332
  * @param buffer input content, as a buffer.
328
333
  * @param filename file name.
334
+ * @deprecated Use `new mindee.BufferInput()` instead.
329
335
  */
330
336
  docFromBuffer(buffer, filename) {
331
337
  return new input_1.BufferInput({
@@ -44,3 +44,4 @@ export declare function getMinYCoordinate(polygon: Array<Point>): number;
44
44
  export declare function getMinXCoordinate(polygon: Array<Point>): number;
45
45
  export declare function compareOnY(polygon1: Array<Point>, polygon2: Array<Point>): number;
46
46
  export declare function compareOnX(polygon1: Array<Point>, polygon2: Array<Point>): number;
47
+ export declare function adjustForRotation(polygon: Array<Point>, orientation: number): Array<Point>;
@@ -13,6 +13,7 @@ exports.getMinYCoordinate = getMinYCoordinate;
13
13
  exports.getMinXCoordinate = getMinXCoordinate;
14
14
  exports.compareOnY = compareOnY;
15
15
  exports.compareOnX = compareOnX;
16
+ exports.adjustForRotation = adjustForRotation;
16
17
  /**
17
18
  * Get the central point (centroid) given a list of points.
18
19
  */
@@ -124,3 +125,15 @@ function compareOnX(polygon1, polygon2) {
124
125
  }
125
126
  return sort < 0 ? -1 : 1;
126
127
  }
128
+ function adjustForRotation(polygon, orientation) {
129
+ if (orientation === 90) {
130
+ return polygon.map(([x, y]) => [y, 1 - x]);
131
+ }
132
+ if (orientation === 180) {
133
+ return polygon.map(([x, y]) => [1 - x, 1 - y]);
134
+ }
135
+ if (orientation === 270) {
136
+ return polygon.map(([x, y]) => [1 - y, x]);
137
+ }
138
+ return polygon;
139
+ }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractFromPage = extractFromPage;
4
4
  const pdf_lib_1 = require("@cantoo/pdf-lib");
5
5
  const geometry_1 = require("../../geometry");
6
+ const polygonUtils_1 = require("../../geometry/polygonUtils");
6
7
  /**
7
8
  * Extracts elements from a page based off of a list of bounding boxes.
8
9
  *
@@ -15,7 +16,9 @@ async function extractFromPage(pdfPage, polygons) {
15
16
  // Manual upscale.
16
17
  // Fixes issues with the OCR.
17
18
  const qualityScale = 300 / 72;
18
- for (const polygon of polygons) {
19
+ const orientation = pdfPage.getRotation().angle;
20
+ for (const origPolygon of polygons) {
21
+ const polygon = (0, polygonUtils_1.adjustForRotation)(origPolygon, orientation);
19
22
  const tempPdf = await pdf_lib_1.PDFDocument.create();
20
23
  const newWidth = width * ((0, geometry_1.getMinMaxX)(polygon).max - (0, geometry_1.getMinMaxX)(polygon).min);
21
24
  const newHeight = height * ((0, geometry_1.getMinMaxY)(polygon).max - (0, geometry_1.getMinMaxY)(polygon).min);
@@ -25,17 +28,59 @@ async function extractFromPage(pdfPage, polygons) {
25
28
  top: height - ((0, geometry_1.getMinMaxY)(polygon).min * height),
26
29
  bottom: height - ((0, geometry_1.getMinMaxY)(polygon).max * height),
27
30
  });
28
- const samplePage = tempPdf.addPage([newWidth * qualityScale, newHeight * qualityScale]);
31
+ // Determine the final page dimensions based on orientation
32
+ let finalWidth;
33
+ let finalHeight;
34
+ if (orientation === 90 || orientation === 270) {
35
+ // For 90/270 rotations, swap width and height
36
+ finalWidth = newHeight * qualityScale;
37
+ finalHeight = newWidth * qualityScale;
38
+ }
39
+ else {
40
+ finalWidth = newWidth * qualityScale;
41
+ finalHeight = newHeight * qualityScale;
42
+ }
43
+ const samplePage = tempPdf.addPage([finalWidth, finalHeight]);
29
44
  samplePage.drawRectangle({
30
45
  x: 0,
31
46
  y: 0,
32
- width: newWidth * qualityScale,
33
- height: newHeight * qualityScale,
34
- });
35
- samplePage.drawPage(cropped, {
36
- width: newWidth * qualityScale,
37
- height: newHeight * qualityScale,
47
+ width: finalWidth,
48
+ height: finalHeight,
38
49
  });
50
+ // Draw the cropped page with rotation applied
51
+ if (orientation === 0) {
52
+ samplePage.drawPage(cropped, {
53
+ width: newWidth * qualityScale,
54
+ height: newHeight * qualityScale,
55
+ });
56
+ }
57
+ else if (orientation === 90) {
58
+ samplePage.drawPage(cropped, {
59
+ x: 0,
60
+ y: finalHeight,
61
+ width: newWidth * qualityScale,
62
+ height: newHeight * qualityScale,
63
+ rotate: (0, pdf_lib_1.degrees)(270),
64
+ });
65
+ }
66
+ else if (orientation === 180) {
67
+ samplePage.drawPage(cropped, {
68
+ x: finalWidth,
69
+ y: finalHeight,
70
+ width: newWidth * qualityScale,
71
+ height: newHeight * qualityScale,
72
+ rotate: (0, pdf_lib_1.degrees)(180),
73
+ });
74
+ }
75
+ else if (orientation === 270) {
76
+ samplePage.drawPage(cropped, {
77
+ x: finalWidth,
78
+ y: 0,
79
+ width: newWidth * qualityScale,
80
+ height: newHeight * qualityScale,
81
+ rotate: (0, pdf_lib_1.degrees)(90),
82
+ });
83
+ }
39
84
  extractedElements.push(await tempPdf.save());
40
85
  }
41
86
  return extractedElements;
@@ -65,6 +65,7 @@ async function extractReceipts(inputFile, inference) {
65
65
  const pdfDoc = await loadPdfDoc(inputFile);
66
66
  for (let pageId = 0; pageId < pdfDoc.getPageCount(); pageId++) {
67
67
  const [page] = await pdfDoc.copyPages(pdfDoc, [pageId]);
68
+ page.setRotation((0, pdf_lib_1.degrees)(inference.pages[pageId].orientation?.value ?? 0));
68
69
  const receiptPositions = inference.pages[pageId].prediction.receipts.map((receipt) => receipt.boundingBox);
69
70
  const extractedReceipts = await extractReceiptsFromPage(page, receiptPositions, pageId);
70
71
  images.push(...extractedReceipts);
@@ -71,8 +71,8 @@ class DataSchema {
71
71
  if (typeof dataSchema === "string") {
72
72
  this.replace = new DataSchemaReplace(JSON.parse(dataSchema)["replace"]);
73
73
  }
74
- else if (dataSchema["replace"] instanceof DataSchemaReplace) {
75
- this.replace = dataSchema["replace"];
74
+ else if (dataSchema instanceof DataSchema) {
75
+ this.replace = dataSchema.replace;
76
76
  }
77
77
  else {
78
78
  this.replace = new DataSchemaReplace(dataSchema["replace"]);