A fast, helpful, and open-source document parser
lint
Pierre-Loic doulcet3e60ca88ac93
diff --git a/cli/parse.ts b/cli/parse.tsindex 2f7fbee..78883be 100644--- a/cli/parse.ts+++ b/cli/parse.ts@@ -306,7 +306,10 @@ program.option("--no-precise-bbox", "Disable precise bounding boxes").option("--recursive", "Recursively search input directory").option("--extension <ext>", 'Only process files with this extension (e.g., ".pdf")')- .option("--password <password>", "Password for encrypted/protected documents (applied to all files)")+ .option(+ "--password <password>",+ "Password for encrypted/protected documents (applied to all files)"+ ).option("--config <file>", "Config file (JSON)").option("-q, --quiet", "Suppress progress output").action(async (inputDir: string, outputDir: string, options: BatchParseCommandOptions) => {diff --git a/src/conversion/convertToPdf.ts b/src/conversion/convertToPdf.tsindex 2183586..eda5327 100644--- a/src/conversion/convertToPdf.ts+++ b/src/conversion/convertToPdf.ts@@ -235,7 +235,11 @@ export async function findImageMagickCommand(): Promise<{/*** Convert office documents using LibreOffice*/-export async function convertOfficeDocument(filePath: string, outputDir: string, password?: string): Promise<string> {+export async function convertOfficeDocument(+ filePath: string,+ outputDir: string,+ password?: string+): Promise<string> {const libreOfficeCmd = await findLibreOfficeCommand();if (!libreOfficeCmd) {throw new Error(diff --git a/src/core/parser.ts b/src/core/parser.tsindex 62df4e1..8b0cca6 100644--- a/src/core/parser.ts+++ b/src/core/parser.ts@@ -236,7 +236,10 @@ export class LiteParse {log(`Generating screenshots for: ${typeof input === "string" ? input : "<buffer>"}`);// Load PDF document to get page count and dimensions- const doc = await this.pdfEngine.loadDocument(input as string | Uint8Array, this.config.password);+ const doc = await this.pdfEngine.loadDocument(+ input as string | Uint8Array,+ this.config.password+ );const totalPages = doc.numPages;// Determine the input to pass to the renderer (file path or buffer)@@ -325,7 +328,12 @@ export class LiteParse {try {// Render page as image buffer- const imageBuffer = await this.pdfEngine.renderPageImage(doc, page.pageNum, this.config.dpi, this.config.password);+ const imageBuffer = await this.pdfEngine.renderPageImage(+ doc,+ page.pageNum,+ this.config.dpi,+ this.config.password+ );// Run OCR directly on the buffer (no temp file needed)log(` OCR on page ${page.pageNum}...`);diff --git a/src/engines/pdf/interface.ts b/src/engines/pdf/interface.tsindex 602a412..36e6844 100644--- a/src/engines/pdf/interface.ts+++ b/src/engines/pdf/interface.ts@@ -5,7 +5,12 @@ export interface PdfEngine {loadDocument(input: string | Uint8Array, password?: string): Promise<PdfDocument>;extractPage(doc: PdfDocument, pageNum: number): Promise<PageData>;extractAllPages(doc: PdfDocument, maxPages?: number, targetPages?: string): Promise<PageData[]>;- renderPageImage(doc: PdfDocument, pageNum: number, dpi: number, password?: string): Promise<Buffer>;+ renderPageImage(+ doc: PdfDocument,+ pageNum: number,+ dpi: number,+ password?: string+ ): Promise<Buffer>;close(doc: PdfDocument): Promise<void>;}diff --git a/src/engines/pdf/pdfjs.ts b/src/engines/pdf/pdfjs.tsindex 818498e..84f1913 100644--- a/src/engines/pdf/pdfjs.ts+++ b/src/engines/pdf/pdfjs.ts@@ -462,9 +462,15 @@ export class PdfJsEngine implements PdfEngine {const message = error instanceof Error ? error.message : String(error);if (message.includes("password") || message.includes("Password")) {if (password) {- throw new Error("Incorrect password for this PDF. Please check the password and try again.", { cause: error });+ throw new Error(+ "Incorrect password for this PDF. Please check the password and try again.",+ { cause: error }+ );} else {- throw new Error("This PDF is password-protected. Use --password <password> to provide the document password.", { cause: error });+ throw new Error(+ "This PDF is password-protected. Use --password <password> to provide the document password.",+ { cause: error }+ );}}throw error;@@ -639,7 +645,12 @@ export class PdfJsEngine implements PdfEngine {return pages;}- async renderPageImage(_doc: PdfDocument, pageNum: number, dpi: number, password?: string): Promise<Buffer> {+ async renderPageImage(+ _doc: PdfDocument,+ pageNum: number,+ dpi: number,+ password?: string+ ): Promise<Buffer> {if (!this.pdfiumRenderer) {this.pdfiumRenderer = new PdfiumRenderer();}