
Passport OCR API
Passport OCR API
The Passport OCR API is an API client for the Passport OCR API that allows you to easily extract passport data from images/pdf.
Installation
Install the package using npm:
npm install passport-ocr-api
Usage
To use the library, you need to import the Api
class, create an instance with your API key, and then call the extractPassportData
method.
To get your API key, please create an account at omkar.cloud.
import Api from 'passport-ocr-api';
async function main() {
// Create an instance of the API with your API key
const api = new Api({
apiKey: 'YOUR_API_KEY',
createResponseFiles: true, // Optional: saves responses to files for debugging, remove this in production.
});
// Extract passport data from an image URL
const passportData = await api.extractPassportData('https://www.omkar.cloud/images/passport-sample.png');
console.log(passportData);
}
main();
Example Response
The API returns a structured response with extracted passport data:
{
"last_name": "QUEST",
"given_names": [
"Amelia",
"Mary"
],
"birth_place": "Utopia",
"birth_date": "1987-04-23",
"issuance_date": "2022-08-27",
"expire_date": "2032-08-26",
"document_id": "S01234567",
"issuing_state": "Upa",
"gender": "F",
"image_id": [],
"image_signature": [],
"mrz": "P<UTOQUEST<AMELIA<MARY <<<<<<<<<<<<<<<<<<<<<<\nS012345674UTO8704234F3208265 <<<<<<<<<<<<<<< 2",
"nationality": "Utopian"
}
Parameters
The Api
constructor accepts the following parameters:
apiKey
(string, required): Your API key for the service.createResponseFiles
(boolean, optional, default:false
): If set totrue
, the library will save the JSON response from the API to a file in theoutput/responses
directory. Useful for debugging. Remove this parameter in production.
The extractPassportData
method accepts the following parameter:
fileUrl
(string, required): The URL of the passport image or PDF file to process. Supported formats include JPG, PNG, PDF, and other common image formats.