Documind Turns Messy PDFs and Scans into Clean JSON
Anyone who has ever written a parser for bank statements or invoices knows this pain. You take pdf-parse or classic OCR, run it on a real document, and get a chaotic mess of lines where table columns are misaligned, dates get mixed up with contract numbers, and totals detach from line item names.
With the advent of multimodal language models, document parsing has become noticeably easier. But stitching together page-to-image conversion, model submission, structure validation, and final JSON assembly typically requires hundreds of lines of boilerplate code.
I recently came across Documind on GitHub, a project by the DocumindHQ team. It's a small Node.js library that handles all the dirty work of extracting structured data from unstructured documents.
What the library can do
Under the hood, Documind combines system page rendering utilities and vision models. The project grew out of the popular Zerox tool but evolved into a standalone platform for working with data schemas.
The library solves four specific tasks:
- Reads various formats: PDF, DOCX, HTML, TXT, PNG, and JPG.
- Accepts your field schema and returns predictable JSON populated with data from the document.
- Works with both the OpenAI cloud API and local models via Llava or Llama 3.2 Vision.
- Converts complex multi-page documents into clean Markdown, preserving table and list structures.
If you don't have time to manually define a field schema, Documind can generate one automatically based on the contents of the first document.
Quick start and system dependencies
The library is written in JavaScript for Node.js version 18 and above. Since rendering PDF pages to images requires low-level tools, you need to install Ghostscript and GraphicsMagick in your system before installing the npm package.
On macOS, this is done via Homebrew:
brew install ghostscript graphicsmagick
On Ubuntu or Debian:
sudo apt-get update
sudo apt-get install -y ghostscript graphicsmagick
After that, install the package itself:
npm install documind
To work with OpenAI, create a .env file in the project root and pass the key:
OPENAI_API_KEY=your_openai_api_key
How to define a data schema
The central idea behind Documind is that you define the shape of the output object through a field array. Each field has a name, type (string, number, array, object, boolean, enum), and a text description that serves as a hint for the neural network.
Here's an example schema for parsing a bank statement with a nested transaction table:
const schema = [
{
name: "accountNumber",
type: "string",
description: "The account number of the bank statement."
},
{
name: "openingBalance",
type: "number",
description: "The opening balance of the account."
},
{
name: "transactions",
type: "array",
description: "List of transactions in the account.",
children: [
{
name: "date",
type: "string",
description: "Transaction date."
},
{
name: "creditAmount",
type: "number",
description: "Credit Amount of the transaction."
},
{
name: "debitAmount",
type: "number",
description: "Debit Amount of the transaction."
},
{
name: "description",
type: "string",
description: "Transaction description."
}
]
},
{
name: "closingBalance",
type: "number",
description: "The closing balance of the account."
}
];
Now pass the schema and file URL to the extract function:
import { extract } from 'documind';
async function main() {
const result = await extract({
file: 'https://example.com/bank_statement.pdf',
schema
});
console.log(JSON.stringify(result, null, 2));
}
main();
The result is a ready-to-use object without the need to parse raw text with regex:
{
"success": true,
"pages": 1,
"data": {
"accountNumber": "100002345",
"openingBalance": 3200,
"transactions": [
{
"date": "2021-05-12",
"creditAmount": null,
"debitAmount": 100,
"description": "transfer to Tom"
},
{
"date": "2021-05-12",
"creditAmount": 50,
"debitAmount": null,
"description": "For lunch the other day"
}
],
"closingBalance": 2420
},
"fileName": "bank_statement.pdf"
}
Ready-made templates
For typical documents like receipts, invoices, or standard statements, you don't need to write a schema from scratch. The library includes built-in templates.
You can check the list of available presets like this:
import { templates } from 'documind';
console.log(templates.list());
And invoking parsing by template is even simpler:
import { extract } from 'documind';
const result = await extract({
file: 'https://example.com/bank_statement.pdf',
template: 'bank_statement'
});
Local models and data security
Documents often contain personal data, medical records, or confidential financial information that cannot be sent to external cloud APIs.
Documind's developers built in support for local vision models. You can deploy Llama 3.2 Vision or Llava on your own GPU server and direct requests there. The parsing process remains the same, but the data never leaves your private network.
What to keep in mind
Before deploying the project to production, there are a couple of nuances to consider:
- AGPL v3.0 license. If you plan to embed Documind directly into a closed commercial backend, the strict AGPL requirements may become a legal issue. In that case, it makes more sense to isolate document processing into a separate microservice.
- System binaries. Ghostscript and GraphicsMagick complicate deployment in serverless environments like AWS Lambda or Vercel Functions if you're not building a custom Docker image.
Who will find it useful
Documind is a great fit for teams building incoming document processing pipelines, automating fintech services, or preparing unstructured document databases for upload to vector stores (RAG).
The tool eliminates the need to write fragile regex-based parsers and gives you a typed result in just a few lines of code. If you need to quickly automate manual document entry, this repository is definitely worth checking out.
Related projects