Node.js OCR SDK

node.js logo

License: MIT GitHub Workflow Status NPM Version Downloads

📘

Info

The OCR SDK is written in TypeScript for your coding pleasure and is officially supported on all current LTS versions of node.js.
All examples shown in this guide should work in both TypeScript and Javascript.

Quick Start

Here's the TL;DR of getting started.

First, get an API Key

Then, install this library:

npm install mindee

As an example, let's parse an invoice:

const mindee = require("mindee");
// for TS or modules:
// import * as mindee from "mindee";

// Init a new client
const mindeeClient = new mindee.Client({apiKey: "my-api-key"});

// Load a file from disk and parse it
const invoiceResponse = mindeeClient
    .docFromPath("/path/to/the/invoice.pdf")
    .parse(mindee.InvoiceV3);

// Print a the parsed data
invoiceResponse.then((resp) => {

  // The document property can be undefined:
  // * TypeScript will throw an error without this guard clause
  //   (or consider using '?' notation)
  // * JavaScript will be very happy to produce subtle bugs
  //   without this guard clause
  if (resp.document === undefined) return;

  // full object
  console.log(resp.document);
    
  // string summary
  console.log(resp.document.toString());
});

You can also use the client with your custom documents:

const mindee = require("mindee");
// for TS or modules:
// import * as mindee from "mindee";

// Init a new client and add your document endpoint
const mindeeClient = new mindee.Client({apiKey: "my-api-key"})
    .addEndpoint({
        accountName: "john",
        endpointName: "wsnine",
    });

// Load a file from disk and parse it
const customResponse = mindeeClient
    .docFromPath("/path/to/the/wsnine.jpg")
    .parse(mindee.CustomV1, { endpointName: "wsnine" });

// Print a the parsed data
invoiceResponse.then((resp) => {
  // The document property can be undefined:
  // * TypeScript will throw an error without this guard clause
  //   (or consider using '?' notation)
  // * JavaScript will be very happy to produce subtle bugs
  //   without this guard clause  
  if (resp.document === undefined) return;

  // full object
  console.log(resp.document);

  // string summary
  console.log(resp.document.toString());
});

Complete details on the working of the library are available in the following guides:

You can view the source code on GitHub.

 

Questions?
Slack Logo Icon  Join our Slack