Node.js OCR SDK

node.js logonode.js logo

📘

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:

import { Client, InvoiceResponse } from "mindee";

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

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

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

  // The document property can be undefined:
  // * TypeScript will throw an error without this guard clause
  //   (consider also using the '?' 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:

import { Client, CustomResponse } from "mindee";

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

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

// Print a the parsed data
invoiceResponse.then((resp) => {
  // The document property can be undefined:
  // * TypeScript will throw an error without this guard clause
  //   (consider also using the '?' 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 IconSlack Logo Icon  Join our Slack


Did this page help you?