{"_id":"mistral-ocr","_rev":"3-709045d1d09bf227372b07d19112401a","name":"mistral-ocr","dist-tags":{"latest":"0.1.3"},"versions":{"0.1.0":{"name":"mistral-ocr","version":"0.1.0","keywords":["mistral","ocr","pdf","markdown","docx","document-ai","scanned-pdf"],"license":"MIT","_id":"mistral-ocr@0.1.0","maintainers":[{"name":"rhk","email":"fabien.antoine@gmail.com"}],"homepage":"https://github.com/rhanka/mistral-ocr#readme","bugs":{"url":"https://github.com/rhanka/mistral-ocr/issues"},"bin":{"mistral-ocr":"build/cli.js"},"dist":{"shasum":"ae283c0ab6bb97d8a6a0cbdf529ba87f19b58d5c","tarball":"https://registry.npmjs.org/mistral-ocr/-/mistral-ocr-0.1.0.tgz","fileCount":18,"integrity":"sha512-PAt2QA8NW2mSMmNmUpsyo7AYjDvw07IhIBUG6Ato7ncDje4j8TEyhy9e6oNYwKjR5zz6gMfNzmqJZBWkrFWmjg==","signatures":[{"sig":"MEQCIDTw5syEUo19SfRaSGfQZF/u1Qr/rML6q0eHzY5YDBucAiBZ8bwYY+f6ce+tGOQRr5OU/NWuLF4uaUyMGTcpg3s5ZQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":47498},"type":"module","types":"./build/index.d.ts","engines":{"node":">=20"},"exports":{".":{"types":"./build/index.d.ts","import":"./build/index.js"}},"gitHead":"a67df9159ef7391c56a3527c3acbc7d5a69a9082","scripts":{"dev":"tsx src/cli.ts","test":"npm run build","build":"rm -rf build && tsc -p tsconfig.json","start":"node build/cli.js","verify":"npm test && npm run pack:dry-run","pack:dry-run":"npm pack --dry-run --cache ./.npm-cache","prepublishOnly":"npm run verify"},"_npmUser":{"name":"rhk","email":"fabien.antoine@gmail.com"},"repository":{"url":"git+https://github.com/rhanka/mistral-ocr.git","type":"git"},"_npmVersion":"11.6.2","description":"PDF to Markdown and DOCX conversion powered by Mistral OCR.","directories":{},"_nodeVersion":"24.14.1","dependencies":{"docx":"^9.5.1","@mistralai/mistralai":"^1.15.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.7.2","typescript":"^5.4.5","@types/node":"^20.14.2"},"_npmOperationalInternal":{"tmp":"tmp/mistral-ocr_0.1.0_1776387775014_0.9500384840163478","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"mistral-ocr","version":"0.1.1","keywords":["mistral","ocr","pdf","markdown","docx","document-ai","scanned-pdf"],"license":"MIT","_id":"mistral-ocr@0.1.1","maintainers":[{"name":"rhk","email":"fabien.antoine@gmail.com"}],"homepage":"https://github.com/rhanka/mistral-ocr#readme","bugs":{"url":"https://github.com/rhanka/mistral-ocr/issues"},"bin":{"mistral-ocr":"build/cli.js"},"dist":{"shasum":"86912fb4002c39dae908eca614e8bf81e6df1a9d","tarball":"https://registry.npmjs.org/mistral-ocr/-/mistral-ocr-0.1.1.tgz","fileCount":21,"integrity":"sha512-i4AhbKhQswJ92Kb+HLKBPcDOSBtBs1bnq9ImHWojpU2hU6aMZRDpCo6Sg4G8C2Rj0+eXyNFYEotw9qBo1XGBHg==","signatures":[{"sig":"MEYCIQDoAcuXfY6+Me1cN34V+WttYBqx2Fl1Vwz+X4uD5TWprgIhAM1Tw9KAu7gjMWDWtYyNagcB3j+vOumZ9neNdLeRItHZ","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/mistral-ocr@0.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":82656},"type":"module","types":"./build/index.d.ts","engines":{"node":">=20"},"exports":{".":{"types":"./build/index.d.ts","import":"./build/index.js"}},"gitHead":"451573ecda5df84c0661e650c22c184199f21967","scripts":{"dev":"tsx src/cli.ts","test":"npm run build && node --test test/*.test.mjs","build":"rm -rf build && tsc -p tsconfig.json","start":"node build/cli.js","verify":"npm test && npm run pack:dry-run","pack:dry-run":"npm pack --dry-run --cache ./.npm-cache","prepublishOnly":"npm run verify"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:20920a2f-e585-46c1-bc70-7b37c5d5472b"}},"repository":{"url":"git+https://github.com/rhanka/mistral-ocr.git","type":"git"},"_npmVersion":"11.6.2","description":"PDF to Markdown and DOCX conversion powered by Mistral OCR.","directories":{},"_nodeVersion":"24.14.1","dependencies":{"docx":"^9.5.1","@mistralai/mistralai":"^1.15.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.7.2","typescript":"^5.4.5","@types/node":"^20.14.2"},"_npmOperationalInternal":{"tmp":"tmp/mistral-ocr_0.1.1_1776648642903_0.8108159933995971","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"mistral-ocr","version":"0.1.3","description":"PDF to Markdown and DOCX conversion powered by Mistral OCR.","type":"module","bin":{"mistral-ocr":"build/cli.js"},"exports":{".":{"types":"./build/index.d.ts","import":"./build/index.js"}},"types":"./build/index.d.ts","engines":{"node":">=20"},"scripts":{"dev":"tsx src/cli.ts","build":"rm -rf build && tsc -p tsconfig.json","pack:dry-run":"npm pack --dry-run --cache ./.npm-cache","start":"node build/cli.js","test":"npm run build && node --test test/*.test.mjs","verify":"npm test && npm run pack:dry-run","prepublishOnly":"npm run verify"},"dependencies":{"@mistralai/mistralai":"^1.15.1","docx":"^9.5.1"},"devDependencies":{"@types/node":"^20.14.2","tsx":"^4.7.2","typescript":"^5.4.5"},"publishConfig":{"access":"public"},"keywords":["mistral","ocr","pdf","markdown","docx","document-ai","scanned-pdf"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/rhanka/mistral-ocr.git"},"homepage":"https://github.com/rhanka/mistral-ocr#readme","bugs":{"url":"https://github.com/rhanka/mistral-ocr/issues"},"gitHead":"ff7f23e198db0f8fa8e3d5147a89a64442c70a6c","_id":"mistral-ocr@0.1.3","_nodeVersion":"24.17.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-Ugo17A5Pb0HHUZ7LAA3fm1lpYDm5/G6F68zn2qe/5xt9iLeYVHOU8/SxeXKVTPyyWblBbFCn/4tmnODtd2FovQ==","shasum":"d3939a4ad7ec8f1e9e6a7cde5fc52944d6f08f7e","tarball":"https://registry.npmjs.org/mistral-ocr/-/mistral-ocr-0.1.3.tgz","fileCount":21,"unpackedSize":92459,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/mistral-ocr@0.1.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDb/xmfJBQmZBGh1QZquw5Fr+p21wT+aT6acrwrnQUsrQIgJe8+ruBsJjxM6G9g/7cARKeLYT44/4LX7iBs/fZfKnI="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:20920a2f-e585-46c1-bc70-7b37c5d5472b"}},"directories":{},"maintainers":[{"name":"rhk","email":"fabien.antoine@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mistral-ocr_0.1.3_1782321836840_0.23134526622546092"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-17T01:02:54.904Z","modified":"2026-06-24T17:23:57.341Z","0.1.0":"2026-04-17T01:02:55.157Z","0.1.1":"2026-04-20T01:30:43.038Z","0.1.3":"2026-06-24T17:23:57.038Z"},"bugs":{"url":"https://github.com/rhanka/mistral-ocr/issues"},"license":"MIT","homepage":"https://github.com/rhanka/mistral-ocr#readme","keywords":["mistral","ocr","pdf","markdown","docx","document-ai","scanned-pdf"],"repository":{"type":"git","url":"git+https://github.com/rhanka/mistral-ocr.git"},"description":"PDF to Markdown and DOCX conversion powered by Mistral OCR.","maintainers":[{"name":"rhk","email":"fabien.antoine@gmail.com"}],"readme":"# mistral-ocr\n\n`mistral-ocr` converts PDFs into Markdown and/or DOCX using Mistral OCR 4 (`mistral-ocr-4-0`) by default.\n\nThe project exposes:\n\n- a `mistral-ocr` CLI\n- a reusable JavaScript/TypeScript API\n\n## Installation\n\nUse it as an npm package:\n\n```bash\nnpm install mistral-ocr\n```\n\nFor local package development:\n\n```bash\nnpm install\nnpm run build\n```\n\nRequired environment variable:\n\n```bash\nexport MISTRAL_API_KEY=...\n```\n\n## Usage CLI\n\nStandard conversion to Markdown + DOCX with image extraction:\n\n```bash\nnpx mistral-ocr convert ./document.pdf\n```\n\nDefault outputs:\n\n- `./document.md`\n- `./document.docx`\n- `./document-images/`\n\nMain options:\n\n```bash\nnpx mistral-ocr convert ./document.pdf \\\n  --output-dir ./out \\\n  --markdown ./out/document.md \\\n  --docx ./out/document.docx \\\n  --images-dir ./out/images \\\n  --model mistral-ocr-4-0\n```\n\nUse `--model mistral-ocr-latest` if you explicitly want to follow Mistral's moving latest alias.\n\nGenerate Markdown only:\n\n```bash\nnpx mistral-ocr convert ./document.pdf --no-docx\n```\n\nGenerate DOCX only:\n\n```bash\nnpx mistral-ocr convert ./document.pdf --no-markdown\n```\n\nBatch OCR conversion:\n\n```bash\nnpx mistral-ocr batch ./doc-a.pdf ./doc-b.pdf --output-dir ./out\n```\n\nBatch mode uses Mistral's Batch Inference endpoint for OCR, waits for the job by default, then writes one Markdown/DOCX pair per input PDF:\n\n- `./out/doc-a.md`\n- `./out/doc-a.docx`\n- `./out/doc-a-images/`\n- `./out/doc-b.md`\n- `./out/doc-b.docx`\n- `./out/doc-b-images/`\n\nSubmit a batch job without waiting for results:\n\n```bash\nnpx mistral-ocr batch ./doc-a.pdf ./doc-b.pdf --no-wait\n```\n\nUseful batch options:\n\n```bash\nnpx mistral-ocr batch ./doc-a.pdf ./doc-b.pdf \\\n  --output-dir ./out \\\n  --poll-interval 10 \\\n  --timeout 1800 \\\n  --no-docx\n```\n\nOCR 4 options are available in both single-file and batch modes:\n\n```bash\nnpx mistral-ocr convert ./document.pdf \\\n  --table-format html \\\n  --extract-header \\\n  --extract-footer \\\n  --image-limit 20 \\\n  --image-min-size 128\n```\n\nStructured document annotations can be requested with JSON response formats:\n\n```bash\nnpx mistral-ocr convert ./document.pdf \\\n  --document-annotation-format '{\"type\":\"json_schema\",\"jsonSchema\":{\"name\":\"summary\",\"schema\":{\"type\":\"object\"}}}' \\\n  --document-annotation-prompt \"Extract a compact document summary.\"\n```\n\n## Library Usage\n\n```ts\nimport { convertPdf } from 'mistral-ocr';\n\nconst result = await convertPdf('./document.pdf', {\n  markdownPath: './out/document.md',\n  docxPath: './out/document.docx',\n  imageOutputDir: './out/images',\n  tableFormat: 'html',\n  extractHeader: true,\n  extractFooter: true,\n});\n\nconsole.log(result.markdown);\nconsole.log(result.docxBuffer?.length);\n```\n\nExample without writing to disk:\n\n```ts\nimport { convertPdf } from 'mistral-ocr';\n\nconst result = await convertPdf('./document.pdf', {\n  generateDocx: false,\n  logger: false,\n});\n\nconsole.log(result.markdown);\n```\n\nBatch API:\n\n```ts\nimport { convertPdfBatch, createOcrBatch, waitForOcrBatch } from 'mistral-ocr';\n\nconst batch = await convertPdfBatch(['./doc-a.pdf', './doc-b.pdf'], {\n  outputDir: './out',\n  generateDocx: false,\n});\n\nconsole.log(batch.job.id);\nconsole.log(batch.entries.map((entry) => entry.markdownPath));\n\nconst submitted = await createOcrBatch(['./large-a.pdf', './large-b.pdf']);\nconst finished = await waitForOcrBatch(submitted.job.id);\nconsole.log(finished.status);\n```\n\n## Scan-Specific Notes\n\nThis library follows the format returned by the Mistral OCR API:\n\n- text is returned as Markdown, page by page\n- extracted images are first referenced as placeholders in the OCR Markdown, then remapped to local files when `imageOutputDir` is provided\n- DOCX generation is intentionally lightweight and focuses on headings, paragraphs, and images\n\nPractical implications:\n\n- scanned PDFs, multi-column layouts, tables, figures, and captions are generally handled well by `mistral-ocr-4-0`\n- OCR 4 adds explicit controls for table output (`markdown` or `html`), header/footer extraction, image extraction limits, and structured document or bounding-box annotations\n- complex tables, equations, or very rich layouts remain most faithful in the raw Markdown produced by the model\n- DOCX output does not try to perfectly reconstruct the original Word-style layout; it aims to produce a usable document\n\nOfficial references:\n\n- API OCR Mistral: https://docs.mistral.ai/capabilities/document_ai/basic_ocr/\n- Mistral Batch Inference: https://docs.mistral.ai/capabilities/batch/\n- Mistral OCR 4 benchmark and release notes: https://mistral.ai/news/ocr-4/\n\n## Exported API\n\n- `convertPdf(input, options)`\n- `convertPdfBatch(inputs, options)`\n- `createOcrBatch(inputs, options)`\n- `waitForOcrBatch(jobId, options)`\n- `listOcrBatchOutputs(job, options)`\n- `markdownToDocx(markdown, options)`\n- `createMistralClient(apiKey?)`\n- `buildMarkdownFromOcrResponse(ocrResponse, replacements?)`\n- `extractImagesFromOcrResponse(ocrResponse)`\n- `writeExtractedImages(images, imageOutputDir, referenceBaseDir?)`\n\n## Development\n\n```bash\nnpm run build\nnode build/cli.js --help\n```\n\n## Release\n\nPublishing is handled by GitHub Actions through npm Trusted Publishing.\n\nRelease flow:\n\n```bash\nnpm version patch\ngit push origin master --follow-tags\n```\n\nThe publish job only runs for `v*` tags. Before publishing, CI verifies that:\n\n- the Git tag matches `package.json` exactly, for example `v0.1.1` for version `0.1.1`\n- the package version is not already present on npm\n- `npm run verify` passes\n\n## Local Tests\n\nFor local testing in this workspace, the Mistral key can be loaded from `../top-ai-ideas-fullstack/.env`.\n\nRecommended test PDF:\n\n- `New York illustrated` (Library of Congress, 1878), 122 illustrated pages, public domain\n- source page: https://www.loc.gov/item/01014750/\n- direct PDF: https://tile.loc.gov/storage-services/public/gdcmassbookdig/newyorkillustrat03newy/newyorkillustrat03newy.pdf\n\nUseful commands:\n\n```bash\nnpm run build\nmkdir -p .scratch/mistral-ocr-tests\ncurl -L https://tile.loc.gov/storage-services/public/gdcmassbookdig/newyorkillustrat03newy/newyorkillustrat03newy.pdf -o .scratch/mistral-ocr-tests/new-york-illustrated.pdf\n\nbash -lc 'set -a; source ../top-ai-ideas-fullstack/.env >/dev/null 2>&1; set +a; node build/cli.js convert .scratch/mistral-ocr-tests/new-york-illustrated.pdf --output-dir .scratch/mistral-ocr-tests/new-york-illustrated-out'\n\nbash -lc 'set -a; source ../top-ai-ideas-fullstack/.env >/dev/null 2>&1; set +a; node build/cli.js convert CONTRIBUATION_AI_AERONAUTIQUE.pdf --output-dir .scratch/mistral-ocr-tests/contribution-out'\n\nbash -lc 'set -a; source ../top-ai-ideas-fullstack/.env >/dev/null 2>&1; set +a; node build/cli.js batch CONTRIBUATION_AI_AERONAUTIQUE.pdf .scratch/mistral-ocr-tests/new-york-illustrated.pdf --output-dir .scratch/mistral-ocr-tests/batch-out --no-docx'\n```\n","readmeFilename":"README.md"}