mindee 5.3.1 → 5.4.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 +5 -0
- package/package.json +1 -1
- package/src/image/extractedImages.d.ts +4 -0
- package/src/image/extractedImages.js +5 -0
- package/src/image/index.d.ts +1 -0
- package/src/image/index.js +1 -0
- package/src/pdf/extractedPdfs.d.ts +4 -0
- package/src/{v2/fileOperations/cropFiles.js → pdf/extractedPdfs.js} +1 -1
- package/src/pdf/index.d.ts +2 -0
- package/src/pdf/index.js +2 -0
- package/src/v2/fileOperations/crop.d.ts +4 -4
- package/src/v2/fileOperations/crop.js +6 -5
- package/src/v2/fileOperations/split.d.ts +3 -3
- package/src/v2/fileOperations/split.js +6 -6
- package/src/v2/product/crop/cropItem.d.ts +1 -1
- package/src/v2/product/crop/cropItem.js +3 -3
- package/src/v2/product/crop/cropResponse.d.ts +0 -8
- package/src/v2/product/crop/cropResponse.js +0 -9
- package/src/v2/product/crop/cropResult.d.ts +8 -0
- package/src/v2/product/crop/cropResult.js +9 -0
- package/src/v2/product/split/splitRange.d.ts +2 -1
- package/src/v2/product/split/splitRange.js +2 -2
- package/src/v2/product/split/splitResponse.d.ts +0 -7
- package/src/v2/product/split/splitResponse.js +0 -12
- package/src/v2/product/split/splitResult.d.ts +7 -0
- package/src/v2/product/split/splitResult.js +12 -0
- package/src/v2/fileOperations/cropFiles.d.ts +0 -4
- package/src/v2/fileOperations/splitFiles.d.ts +0 -4
- package/src/v2/fileOperations/splitFiles.js +0 -5
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/image/index.d.ts
CHANGED
package/src/image/index.js
CHANGED
package/src/pdf/index.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ export { extractPages, countPages } from "./pdfOperation.js";
|
|
|
2
2
|
export type { SplitPdf } from "./pdfOperation.js";
|
|
3
3
|
export { compressPdf } from "./pdfCompressor.js";
|
|
4
4
|
export { hasSourceText } from "./pdfUtils.js";
|
|
5
|
+
export { ExtractedPdf } from "./extractedPdf.js";
|
|
6
|
+
export { ExtractedPdfs } from "./extractedPdfs.js";
|
package/src/pdf/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { LocalInputSource } from "../../input/index.js";
|
|
2
2
|
import { CropItem } from "../../v2/product/crop/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import { ExtractedImage } from "../../image/index.js";
|
|
3
|
+
import { ExtractedImage, ExtractedImages } from "../../image/index.js";
|
|
5
4
|
/**
|
|
6
5
|
* Extracts a single specified crop from a given input source.
|
|
7
6
|
* @param inputSource Local input source.
|
|
8
7
|
* @param crop Crop to extract.
|
|
8
|
+
* @param quality JPEG quality of extracted image.
|
|
9
9
|
*/
|
|
10
|
-
export declare function extractSingleCrop(inputSource: LocalInputSource, crop: CropItem): Promise<ExtractedImage>;
|
|
10
|
+
export declare function extractSingleCrop(inputSource: LocalInputSource, crop: CropItem, quality?: number): Promise<ExtractedImage>;
|
|
11
11
|
/**
|
|
12
12
|
* Extracts a list of crops from a document.
|
|
13
13
|
* @param inputSource Local input source.
|
|
@@ -15,4 +15,4 @@ export declare function extractSingleCrop(inputSource: LocalInputSource, crop: C
|
|
|
15
15
|
* @param quality JPEG quality of extracted images.
|
|
16
16
|
* @return a list of extracted files, as a CropFiles object.
|
|
17
17
|
*/
|
|
18
|
-
export declare function
|
|
18
|
+
export declare function extractMultipleCrops(inputSource: LocalInputSource, crops: CropItem[], quality?: number): Promise<ExtractedImages>;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { MindeeError } from "../../errors/index.js";
|
|
2
2
|
import { extractImagesFromPolygon } from "../../image/imageExtractor.js";
|
|
3
|
-
import {
|
|
3
|
+
import { ExtractedImages } from "../../image/index.js";
|
|
4
4
|
import { logger } from "../../logger.js";
|
|
5
5
|
/**
|
|
6
6
|
* Extracts a single specified crop from a given input source.
|
|
7
7
|
* @param inputSource Local input source.
|
|
8
8
|
* @param crop Crop to extract.
|
|
9
|
+
* @param quality JPEG quality of extracted image.
|
|
9
10
|
*/
|
|
10
|
-
export async function extractSingleCrop(inputSource, crop) {
|
|
11
|
-
return (await
|
|
11
|
+
export async function extractSingleCrop(inputSource, crop, quality) {
|
|
12
|
+
return (await extractMultipleCrops(inputSource, [crop], quality))[0];
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Extracts a list of crops from a document.
|
|
@@ -17,7 +18,7 @@ export async function extractSingleCrop(inputSource, crop) {
|
|
|
17
18
|
* @param quality JPEG quality of extracted images.
|
|
18
19
|
* @return a list of extracted files, as a CropFiles object.
|
|
19
20
|
*/
|
|
20
|
-
export async function
|
|
21
|
+
export async function extractMultipleCrops(inputSource, crops, quality) {
|
|
21
22
|
if (crops.length === 0) {
|
|
22
23
|
throw new MindeeError("No crop indexes provided.");
|
|
23
24
|
}
|
|
@@ -32,5 +33,5 @@ export async function extractCrops(inputSource, crops, quality) {
|
|
|
32
33
|
polygonsByPage.get(pageId).push(crop.location.polygon);
|
|
33
34
|
}
|
|
34
35
|
const extractedCrops = await extractImagesFromPolygon(inputSource, polygonsByPage, quality);
|
|
35
|
-
return new
|
|
36
|
+
return new ExtractedImages(...extractedCrops);
|
|
36
37
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { LocalInputSource } from "../../input/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ExtractedPdfs } from "../../pdf/extractedPdfs.js";
|
|
3
3
|
/**
|
|
4
4
|
* Extracts a single specified split from a
|
|
5
5
|
* @param inputSource
|
|
6
6
|
* @param split
|
|
7
7
|
*/
|
|
8
|
-
export declare function extractSingleSplit(inputSource: LocalInputSource, split: number[]): Promise<
|
|
8
|
+
export declare function extractSingleSplit(inputSource: LocalInputSource, split: number[]): Promise<ExtractedPdfs>;
|
|
9
9
|
/**
|
|
10
10
|
* Extracts splits as complete PDFs from the document.
|
|
11
11
|
* @param inputSource Local input source.
|
|
@@ -13,7 +13,7 @@ export declare function extractSingleSplit(inputSource: LocalInputSource, split:
|
|
|
13
13
|
* @return a list of extracted files.
|
|
14
14
|
* @throws MindeeError if no indexes are provided.
|
|
15
15
|
*/
|
|
16
|
-
export declare function
|
|
16
|
+
export declare function extractMultipleSplits(inputSource: LocalInputSource, splits: number[][]): Promise<ExtractedPdfs>;
|
|
17
17
|
/**
|
|
18
18
|
* Expands a range of pages into a list of page indexes.
|
|
19
19
|
* @param range start and end of the page range
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { MindeeError } from "../../errors/index.js";
|
|
2
2
|
import { PdfExtractor } from "../../pdf/pdfExtractor.js";
|
|
3
|
-
import { SplitFiles } from "../../v2/fileOperations/splitFiles.js";
|
|
4
3
|
import { logger } from "../../logger.js";
|
|
5
4
|
import { ExtractedPdf } from "../../pdf/extractedPdf.js";
|
|
5
|
+
import { ExtractedPdfs } from "../../pdf/extractedPdfs.js";
|
|
6
6
|
/**
|
|
7
7
|
* Extracts a single specified split from a
|
|
8
8
|
* @param inputSource
|
|
9
9
|
* @param split
|
|
10
10
|
*/
|
|
11
11
|
export async function extractSingleSplit(inputSource, split) {
|
|
12
|
-
return await
|
|
12
|
+
return await extractMultipleSplits(inputSource, [split]);
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Extracts splits as complete PDFs from the document.
|
|
@@ -18,7 +18,7 @@ export async function extractSingleSplit(inputSource, split) {
|
|
|
18
18
|
* @return a list of extracted files.
|
|
19
19
|
* @throws MindeeError if no indexes are provided.
|
|
20
20
|
*/
|
|
21
|
-
export async function
|
|
21
|
+
export async function extractMultipleSplits(inputSource, splits) {
|
|
22
22
|
const pageGroups = splits.filter(e => e.length > 0);
|
|
23
23
|
if (pageGroups.length === 0) {
|
|
24
24
|
throw new MindeeError("No valid split indexes provided.");
|
|
@@ -28,14 +28,14 @@ export async function extractSplits(inputSource, splits) {
|
|
|
28
28
|
const pdfExtractor = new PdfExtractor(inputSource);
|
|
29
29
|
await pdfExtractor.init();
|
|
30
30
|
if (splits.length === 0) {
|
|
31
|
-
return new
|
|
31
|
+
return new ExtractedPdfs();
|
|
32
32
|
}
|
|
33
33
|
const pageCount = await pdfExtractor.getPageCount();
|
|
34
34
|
if (splits.length === 1 && splits[0].at(-1) === pageCount - 1) {
|
|
35
|
-
return new
|
|
35
|
+
return new ExtractedPdfs(new ExtractedPdf(inputSource.fileObject, inputSource.filename, pageCount));
|
|
36
36
|
}
|
|
37
37
|
const subDocuments = await pdfExtractor.extractSubDocuments(pageGroups);
|
|
38
|
-
return new
|
|
38
|
+
return new ExtractedPdfs(...subDocuments);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Expands a range of pages into a list of page indexes.
|
|
@@ -23,5 +23,5 @@ export declare class CropItem {
|
|
|
23
23
|
* @param inputSource The input file to extract from.
|
|
24
24
|
* @param quality Optional quality parameter for image extraction, default is undefined (full quality).
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
extractFromInputSource(inputSource: LocalInputSource, quality?: number): Promise<ExtractedImage>;
|
|
27
27
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FieldLocation } from "../../../v2/parsing/inference/field/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { extractSingleCrop } from "../../../v2/fileOperations/crop.js";
|
|
3
3
|
import { ExtractionResponse } from "../../../v2/product/index.js";
|
|
4
4
|
export class CropItem {
|
|
5
5
|
constructor(serverResponse) {
|
|
@@ -17,7 +17,7 @@ export class CropItem {
|
|
|
17
17
|
* @param inputSource The input file to extract from.
|
|
18
18
|
* @param quality Optional quality parameter for image extraction, default is undefined (full quality).
|
|
19
19
|
*/
|
|
20
|
-
async
|
|
21
|
-
return (await
|
|
20
|
+
async extractFromInputSource(inputSource, quality = 1) {
|
|
21
|
+
return (await extractSingleCrop(inputSource, this, quality));
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { LocalInputSource } from "../../../input/index.js";
|
|
2
1
|
import { StringDict } from "../../../parsing/stringDict.js";
|
|
3
|
-
import { CropFiles } from "../../../v2/fileOperations/cropFiles.js";
|
|
4
2
|
import { BaseResponse } from "../../../v2/parsing/index.js";
|
|
5
3
|
import { CropInference } from "./cropInference.js";
|
|
6
4
|
export declare class CropResponse extends BaseResponse {
|
|
@@ -12,10 +10,4 @@ export declare class CropResponse extends BaseResponse {
|
|
|
12
10
|
* @param serverResponse JSON response from the server.
|
|
13
11
|
*/
|
|
14
12
|
constructor(serverResponse: StringDict);
|
|
15
|
-
/**
|
|
16
|
-
* Extracts all crops from an input.
|
|
17
|
-
* @param inputSource The input file to extract from.
|
|
18
|
-
* @param quality Optional quality parameter for image extraction, default is undefined (full quality).
|
|
19
|
-
*/
|
|
20
|
-
extractFromFile(inputSource: LocalInputSource, quality?: number): Promise<CropFiles>;
|
|
21
13
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { extractCrops } from "../../../v2/fileOperations/crop.js";
|
|
2
1
|
import { BaseResponse } from "../../../v2/parsing/index.js";
|
|
3
2
|
import { CropInference } from "./cropInference.js";
|
|
4
3
|
export class CropResponse extends BaseResponse {
|
|
@@ -9,12 +8,4 @@ export class CropResponse extends BaseResponse {
|
|
|
9
8
|
super(serverResponse);
|
|
10
9
|
this.inference = new CropInference(serverResponse["inference"]);
|
|
11
10
|
}
|
|
12
|
-
/**
|
|
13
|
-
* Extracts all crops from an input.
|
|
14
|
-
* @param inputSource The input file to extract from.
|
|
15
|
-
* @param quality Optional quality parameter for image extraction, default is undefined (full quality).
|
|
16
|
-
*/
|
|
17
|
-
async extractFromFile(inputSource, quality = 1) {
|
|
18
|
-
return await extractCrops(inputSource, this.inference.result.crops, quality);
|
|
19
|
-
}
|
|
20
11
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { StringDict } from "../../../parsing/stringDict.js";
|
|
2
2
|
import { CropItem } from "../../../v2/product/crop/cropItem.js";
|
|
3
|
+
import { LocalInputSource } from "../../../input/index.js";
|
|
4
|
+
import { ExtractedImages } from "../../../image/extractedImages.js";
|
|
3
5
|
export declare class CropResult {
|
|
4
6
|
/**
|
|
5
7
|
* Fields contained in the inference.
|
|
@@ -7,4 +9,10 @@ export declare class CropResult {
|
|
|
7
9
|
crops: CropItem[];
|
|
8
10
|
constructor(serverResponse: StringDict);
|
|
9
11
|
toString(): string;
|
|
12
|
+
/**
|
|
13
|
+
* Extracts a single crop from an input.
|
|
14
|
+
* @param inputSource The input file to extract from.
|
|
15
|
+
* @param quality Optional quality parameter for image extraction, default is undefined (full quality).
|
|
16
|
+
*/
|
|
17
|
+
extractFromInputSource(inputSource: LocalInputSource, quality?: number): Promise<ExtractedImages>;
|
|
10
18
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CropItem } from "../../../v2/product/crop/cropItem.js";
|
|
2
|
+
import { extractMultipleCrops } from "../../../v2/fileOperations/crop.js";
|
|
2
3
|
export class CropResult {
|
|
3
4
|
constructor(serverResponse) {
|
|
4
5
|
/**
|
|
@@ -11,4 +12,12 @@ export class CropResult {
|
|
|
11
12
|
const crops = this.crops.map(item => item.toString()).join("\n");
|
|
12
13
|
return `Crops\n=====\n${crops}`;
|
|
13
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Extracts a single crop from an input.
|
|
17
|
+
* @param inputSource The input file to extract from.
|
|
18
|
+
* @param quality Optional quality parameter for image extraction, default is undefined (full quality).
|
|
19
|
+
*/
|
|
20
|
+
async extractFromInputSource(inputSource, quality = 1) {
|
|
21
|
+
return (await extractMultipleCrops(inputSource, this.crops, quality));
|
|
22
|
+
}
|
|
14
23
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StringDict } from "../../../parsing/index.js";
|
|
2
2
|
import { LocalInputSource } from "../../../input/index.js";
|
|
3
3
|
import { ExtractionResponse } from "../../../v2/product/index.js";
|
|
4
|
+
import { ExtractedPdf } from "../../../pdf/index.js";
|
|
4
5
|
/**
|
|
5
6
|
* Split inference result.
|
|
6
7
|
*/
|
|
@@ -24,5 +25,5 @@ export declare class SplitRange {
|
|
|
24
25
|
* Extracts a single split from the input file.
|
|
25
26
|
* @param inputSource The input file to extract from.
|
|
26
27
|
*/
|
|
27
|
-
extractFromFile(inputSource: LocalInputSource): Promise<
|
|
28
|
+
extractFromFile(inputSource: LocalInputSource): Promise<ExtractedPdf>;
|
|
28
29
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expandRange,
|
|
1
|
+
import { expandRange, extractMultipleSplits } from "../../../v2/fileOperations/split.js";
|
|
2
2
|
import { ExtractionResponse } from "../../../v2/product/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Split inference result.
|
|
@@ -21,6 +21,6 @@ export class SplitRange {
|
|
|
21
21
|
*/
|
|
22
22
|
async extractFromFile(inputSource) {
|
|
23
23
|
const pageRange = [expandRange(this.pageRange)];
|
|
24
|
-
return (await
|
|
24
|
+
return (await extractMultipleSplits(inputSource, pageRange))[0];
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { StringDict } from "../../../parsing/stringDict.js";
|
|
2
2
|
import { SplitInference } from "./splitInference.js";
|
|
3
3
|
import { BaseResponse } from "../../../v2/parsing/index.js";
|
|
4
|
-
import { LocalInputSource } from "../../../input/index.js";
|
|
5
|
-
import { SplitFiles } from "../../../v2/fileOperations/splitFiles.js";
|
|
6
4
|
export declare class SplitResponse extends BaseResponse {
|
|
7
5
|
/**
|
|
8
6
|
* Response for an OCR utility inference.
|
|
@@ -12,9 +10,4 @@ export declare class SplitResponse extends BaseResponse {
|
|
|
12
10
|
* @param serverResponse JSON response from the server.
|
|
13
11
|
*/
|
|
14
12
|
constructor(serverResponse: StringDict);
|
|
15
|
-
/**
|
|
16
|
-
* Extracts all splits from an input PDF.
|
|
17
|
-
* @param inputSource The input file to extract from.
|
|
18
|
-
*/
|
|
19
|
-
extractFromFile(inputSource: LocalInputSource): Promise<SplitFiles>;
|
|
20
13
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { SplitInference } from "./splitInference.js";
|
|
2
2
|
import { BaseResponse } from "../../../v2/parsing/index.js";
|
|
3
|
-
import { expandRange, extractSplits } from "../../../v2/fileOperations/split.js";
|
|
4
3
|
export class SplitResponse extends BaseResponse {
|
|
5
4
|
/**
|
|
6
5
|
* @param serverResponse JSON response from the server.
|
|
@@ -9,15 +8,4 @@ export class SplitResponse extends BaseResponse {
|
|
|
9
8
|
super(serverResponse);
|
|
10
9
|
this.inference = new SplitInference(serverResponse["inference"]);
|
|
11
10
|
}
|
|
12
|
-
/**
|
|
13
|
-
* Extracts all splits from an input PDF.
|
|
14
|
-
* @param inputSource The input file to extract from.
|
|
15
|
-
*/
|
|
16
|
-
async extractFromFile(inputSource) {
|
|
17
|
-
const splits = [];
|
|
18
|
-
for (const split of this.inference.result.splits) {
|
|
19
|
-
splits.push(expandRange(split.pageRange));
|
|
20
|
-
}
|
|
21
|
-
return await extractSplits(inputSource, splits);
|
|
22
|
-
}
|
|
23
11
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { SplitRange } from "./splitRange.js";
|
|
2
2
|
import { StringDict } from "../../../parsing/index.js";
|
|
3
|
+
import { LocalInputSource } from "../../../input/index.js";
|
|
4
|
+
import { ExtractedPdfs } from "../../../pdf/index.js";
|
|
3
5
|
/**
|
|
4
6
|
* Split result info.
|
|
5
7
|
*/
|
|
@@ -9,5 +11,10 @@ export declare class SplitResult {
|
|
|
9
11
|
*/
|
|
10
12
|
splits: SplitRange[];
|
|
11
13
|
constructor(rawResponse: StringDict);
|
|
14
|
+
/**
|
|
15
|
+
* Extracts all splits from an input PDF.
|
|
16
|
+
* @param inputSource The input file to extract from.
|
|
17
|
+
*/
|
|
18
|
+
extractFromInputSource(inputSource: LocalInputSource): Promise<ExtractedPdfs>;
|
|
12
19
|
toString(): string;
|
|
13
20
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SplitRange } from "./splitRange.js";
|
|
2
|
+
import { extractMultipleSplits, expandRange } from "../../../v2/fileOperations/split.js";
|
|
2
3
|
/**
|
|
3
4
|
* Split result info.
|
|
4
5
|
*/
|
|
@@ -6,6 +7,17 @@ export class SplitResult {
|
|
|
6
7
|
constructor(rawResponse) {
|
|
7
8
|
this.splits = rawResponse.splits.map((split) => new SplitRange(split));
|
|
8
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Extracts all splits from an input PDF.
|
|
12
|
+
* @param inputSource The input file to extract from.
|
|
13
|
+
*/
|
|
14
|
+
async extractFromInputSource(inputSource) {
|
|
15
|
+
const splits = [];
|
|
16
|
+
for (const split of this.splits) {
|
|
17
|
+
splits.push(expandRange(split.pageRange));
|
|
18
|
+
}
|
|
19
|
+
return await extractMultipleSplits(inputSource, splits);
|
|
20
|
+
}
|
|
9
21
|
toString() {
|
|
10
22
|
let splits = "\n";
|
|
11
23
|
if (this.splits.length > 0) {
|