Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/code_samples/v2_classification.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const inputSource = new mindee.PathInput({ inputPath: filePath });

// Send for processing
const response = await mindeeClient.enqueueAndGetResult(
mindee.v2.product.Classification,
mindee.product.Classification,
inputSource,
params,
);
Expand Down
2 changes: 1 addition & 1 deletion docs/code_samples/v2_crop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const inputSource = new mindee.PathInput({ inputPath: filePath });

// Send for processing
const response = await mindeeClient.enqueueAndGetResult(
mindee.v2.product.Crop,
mindee.product.Crop,
inputSource,
params,
);
Expand Down
2 changes: 1 addition & 1 deletion docs/code_samples/v2_extraction.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const inputSource = new mindee.PathInput({ inputPath: filePath });

// Send for processing
const response = await mindeeClient.enqueueAndGetResult(
mindee.v2.product.Extraction,
mindee.product.Extraction,
inputSource,
params,
);
Expand Down
2 changes: 1 addition & 1 deletion docs/code_samples/v2_ocr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const inputSource = new mindee.PathInput({ inputPath: filePath });

// Send for processing
const response = await mindeeClient.enqueueAndGetResult(
mindee.v2.product.Ocr,
mindee.product.Ocr,
inputSource,
params,
);
Expand Down
2 changes: 1 addition & 1 deletion docs/code_samples/v2_split.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const inputSource = new mindee.PathInput({ inputPath: filePath });

// Send for processing
const response = await mindeeClient.enqueueAndGetResult(
mindee.v2.product.Split,
mindee.product.Split,
inputSource,
params,
);
Expand Down
7 changes: 5 additions & 2 deletions src/image/imageExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ let pdfLib: typeof pdfLibTypes | null = null;

async function getPdfLib(): Promise<typeof pdfLibTypes> {
if (!pdfLib) {
const pdfLibImport = await loadOptionalDependency<typeof pdfLibTypes>("@cantoo/pdf-lib", "Text Embedding");
const pdfLibImport = await loadOptionalDependency<typeof pdfLibTypes>(
"@cantoo/pdf-lib", "Text Embedding"
);
pdfLib = (pdfLibImport as any).default || pdfLibImport;
}
return pdfLib!;
Expand All @@ -23,7 +25,8 @@ async function getPdfLib(): Promise<typeof pdfLibTypes> {
*/
export async function extractFromPage(
pdfPage: pdfLibTypes.PDFPage,
polygons: Polygon[]) {
polygons: Polygon[]
) {
const pdfLib = await getPdfLib();
const { width, height } = pdfPage.getSize();
const extractedElements :Uint8Array[] = [];
Expand Down
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Core
export {
InputSource,
Base64Input,
Expand All @@ -10,16 +11,19 @@ export {
} from "./input/index.js";
export type { PageOptions } from "./input/index.js";
export * as image from "./image/index.js";
export * as pdf from "./pdf/index.js";
export * as geometry from "./geometry/index.js";

// V1
export * as v1 from "./v1/index.js";

// V2
export * as v2 from "./v2/index.js";

// Consider v2 the default
export * as product from "./v2/product/index.js";
export {
Client,
InferenceFile,
InferenceModel,
JobResponse,
ErrorResponse,
} from "./v2/index.js";
Expand Down
18 changes: 12 additions & 6 deletions src/pdf/pdfCompressor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ async function compressPagesWithQuality(
for (let i = 0; i < extractedPdfInfo.pages.length; i++) {
const page = pdfDoc.getPages()[i];
const rasterizedPage = await rasterizePage(pdfData, i + 1, imageQuality);
const compressedImage = await compressImage(Buffer.from(rasterizedPage, "binary"), imageQuality);

const compressedImage = await compressImage(
Buffer.from(rasterizedPage, "binary"), imageQuality
);
if (!disableSourceText) {
await addTextToPdfPage(page, extractedText);
}
Expand Down Expand Up @@ -183,7 +184,9 @@ function calculateTotalCompressedSize(compressedPages: Buffer[]): number {
* @param imageQuality Compression quality.
* @returns True if compression was successful, false otherwise.
*/
function isCompressionSuccessful(totalCompressedSize: number, originalSize: number, imageQuality: number): boolean {
function isCompressionSuccessful(
totalCompressedSize: number, originalSize: number, imageQuality: number
): boolean {
const overhead = lerp(0.54, 0.18, imageQuality / 100);
return totalCompressedSize + totalCompressedSize * overhead < originalSize;
}
Expand Down Expand Up @@ -255,9 +258,12 @@ async function getFontFromName(fontName: string): Promise<pdfLibTypes.PDFFont> {
* @param index Index of the page to rasterize.
* @param quality Quality to apply during rasterization.
*/
async function rasterizePage(pdfData: Buffer, index: number, quality = 85): Promise<string> {

const popplerImport = await loadOptionalDependency<typeof popplerTypes>("node-poppler", "Image Processing");
async function rasterizePage(
pdfData: Buffer, index: number, quality = 85
): Promise<string> {
const popplerImport = await loadOptionalDependency<typeof popplerTypes>(
"node-poppler", "Image Processing"
);
const poppler = (popplerImport as any).default || popplerImport;
const popplerInstance = new poppler.Poppler();
const tmpPdf = tmp.fileSync();
Expand Down
6 changes: 2 additions & 4 deletions src/v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
export * as http from "./http/index.js";
export * as parsing from "./parsing/index.js";
export * as product from "./product/index.js";
export { LocalResponse } from "./parsing/localResponse.js";
export { Client } from "./client.js";
export {
InferenceFile,
InferenceModel,
JobResponse,
ErrorResponse,
LocalResponse,
} from "./parsing/index.js";
export type { PollingOptions } from "./client/index.js";
export type { PollingOptions, BaseParameters } from "./client/index.js";
2 changes: 1 addition & 1 deletion src/v2/parsing/inference/baseInference.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InferenceModel } from "./inferenceModel.js";
import { InferenceFile } from "@/v2/index.js";
import { InferenceFile } from "./inferenceFile.js";
import { StringDict } from "@/parsing/index.js";

export abstract class BaseInference {
Expand Down