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AAU,OAAO,IACxE,QAAQ,KAAK,EACjB,KAEG,CACX,CAEA,GAAI,QAAQ,OAAS,OAAQ,CACT,YACR,MAAM,QAAQ,KAC1B","file":"/npm/pdf-ocr-cli@1.0.1/dist/cli.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/pdf-ocr-cli@1.0.1/dist/cli.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","#!/usr/bin/env node\n\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.processPdf = processPdf;\nexports.createCli = createCli;\nconst fs_1 = __importDefault(require(\"fs\"));\nconst path_1 = __importDefault(require(\"path\"));\nconst commander_1 = require(\"commander\");\nconst ocr_1 = require(\"./ocr\");\nconst textToPdf_1 = require(\"./textToPdf\");\nconst splitPdf_1 = require(\"./splitPdf\");\nconst mergePdfs_1 = require(\"./mergePdfs\");\n/**\n * Sleep for a specified number of milliseconds\n * @param ms - Milliseconds to sleep\n */\nconst sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));\n/**\n * Process a PDF file through the OCR pipeline\n * @param inputPath - Path to the input PDF file\n * @param outputPath - Path to save the output PDF file\n * @param concurrency - Number of pages to process in parallel (not used)\n * @param maxPages - Maximum number of pages to process\n * @param ocrOptions - Options for OCR processing\n * @param sleepTime - Time to sleep between processing pages in milliseconds\n */\nasync function processPdf(inputPath, outputPath, concurrency = 2, maxPages, ocrOptions, sleepTime = 5000) {\n    try {\n        // Read the input PDF\n        const inputPdfBuffer = fs_1.default.readFileSync(inputPath);\n        // Split the PDF into individual pages\n        const pdfPages = await (0, splitPdf_1.splitPdf)(inputPdfBuffer, maxPages);\n        if (ocrOptions?.verbose) {\n            console.log(`PDF split into ${pdfPages.length} pages`);\n        }\n        // Process each page individually\n        const processedPages = [];\n        for (let i = 0; i < pdfPages.length; i++) {\n            if (ocrOptions?.verbose) {\n                console.log(`Processing page ${i + 1}/${pdfPages.length}...`);\n            }\n            try {\n                // Perform OCR on the current page\n                const ocrText = await (0, ocr_1.performOcr)(pdfPages[i], ocrOptions);\n                // Convert OCR text back to PDF\n                const pdfBuffer = await (0, textToPdf_1.textToPdf)(ocrText);\n                // Add the processed page to the result\n                processedPages.push(pdfBuffer);\n                if (ocrOptions?.verbose) {\n                    console.log(`Page ${i + 1} processed successfully`);\n                }\n                // Sleep between pages (except after the last page)\n                if (i < pdfPages.length - 1) {\n                    if (ocrOptions?.verbose) {\n                        console.log(`Sleeping for ${sleepTime}ms before processing next page...`);\n                    }\n                    await sleep(sleepTime);\n                }\n            }\n            catch (error) {\n                if (ocrOptions?.verbose) {\n                    console.error(`Error processing page ${i + 1}: ${error instanceof Error ? error.message : String(error)}`);\n                }\n                throw error;\n            }\n        }\n        // Merge the processed pages back into a single PDF\n        const outputPdfBuffer = await (0, mergePdfs_1.mergePdfs)(processedPages);\n        // Write the output PDF\n        fs_1.default.writeFileSync(outputPath, outputPdfBuffer);\n    }\n    catch (error) {\n        // Re-throw the error to be handled by the caller\n        throw error;\n    }\n}\n/**\n * Create the CLI program\n * @returns The commander program instance\n */\nfunction createCli() {\n    const program = new commander_1.Command();\n    program\n        .name('pdf-ocr')\n        .description('OCR a PDF file using Mistral API with optional LLM verification')\n        .version(require('../package.json').version)\n        .requiredOption('-i, --input <path>', 'Input PDF file path')\n        .requiredOption('-o, --output <path>', 'Output PDF file path')\n        .option('-c, --concurrency <number>', 'Number of pages to process in parallel', (value) => parseInt(value, 10), 2)\n        .option('-m, --max-pages <number>', 'Maximum number of pages to process', (value) => parseInt(value, 10))\n        .option('-r, --retries <number>', 'Maximum number of OCR retry attempts', (value) => parseInt(value, 10), 3)\n        .option('-d, --retry-delay <number>', 'Delay between OCR retries in milliseconds', (value) => parseInt(value, 10), 1000)\n        .option('-t, --timeout <number>', 'Timeout for OCR API requests in milliseconds', (value) => parseInt(value, 10), 30000)\n        .option('-s, --sleep <number>', 'Time to sleep between processing pages in milliseconds', (value) => parseInt(value, 10), 5000)\n        .option('-v, --verbose', 'Enable verbose logging for OCR process')\n        .option('--verify', 'Verify and improve OCR text using LLM')\n        .option('--max-tokens <number>', 'Maximum number of tokens for LLM verification', (value) => parseInt(value, 10), 1000)\n        .option('--temperature <number>', 'Temperature for LLM verification', (value) => parseFloat(value), 0.7)\n        .option('--top-p <number>', 'Top-p for LLM verification', (value) => parseFloat(value), 0.9)\n        .action(async (options) => {\n        try {\n            // Resolve paths to absolute paths\n            const inputPath = path_1.default.resolve(options.input);\n            const outputPath = path_1.default.resolve(options.output);\n            // Create OCR options from CLI options\n            const ocrOptions = {\n                maxRetries: options.retries,\n                retryDelay: options.retryDelay,\n                timeout: options.timeout,\n                verbose: options.verbose || false,\n                verifyContent: options.verify,\n                contentVerificationOptions: {\n                    maxTokens: options.maxTokens,\n                    temperature: options.temperature,\n                    topP: options.topP,\n                    verbose: options.verbose || false\n                }\n            };\n            console.log(`Processing ${inputPath}...`);\n            // Process the PDF\n            await processPdf(inputPath, outputPath, options.concurrency, options.maxPages, ocrOptions, options.sleep);\n            console.log(`OCR complete! Output saved to ${outputPath}`);\n        }\n        catch (error) {\n            console.error('Error:', error instanceof Error ? error.message : String(error));\n            process.exit(1);\n        }\n    });\n    return program;\n}\n// Only run the CLI if this file is executed directly\nif (require.main === module) {\n    const program = createCli();\n    program.parse(process.argv);\n}\n"]}