This package contains an isomorphic SDK for FormRecognizerClient.
- Node.js version 6.x.x or higher
- Browser JavaScript
npm install @azure/cognitiveservices-formrecognizer
npm install @azure/ms-rest-azure-js
The following sample reads the scanned copy of a sample receipt. To know more, refer to the Azure Documentation on Form Recognizer
import { FormRecognizerClient } from "@azure/cognitiveservices-formrecognizer";
import { CognitiveServicesCredentials } from "@azure/ms-rest-azure-js";
async function main(): Promise<void> {
const formRecognizerKey = process.env["formRecognizerKey"] || "<formRecognizerKey>";
const endPoint = process.env["endPoint"] || "<endPoint>";
const cognitiveServiceCredentials = new CognitiveServicesCredentials(formRecognizerKey);
const client = new FormRecognizerClient(cognitiveServiceCredentials, endPoint);
client
.batchReadReceipt(
"https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/contoso-receipt.png"
)
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log("An error occurred:");
console.error(err);
});
}
main();
- index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>@azure/cognitiveservices-formrecognizer sample</title>
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
<script src="node_modules/@azure/cognitiveservices-formrecognizer/dist/cognitiveservices-formrecognizer.js"></script>
<script type="text/javascript">
const formRecognizerKey = "<YOUR_FORM_RECOGNIZER_KEY>";
const endPoint = "<YOUR_FORM_RECOGNIZER_ENDPOINT>";
const cognitiveServiceCredentials = new msRest.ApiKeyCredentials({
inHeader: {
"Ocp-Apim-Subscription-Key": formRecognizerKey
}
});
const client = new Azure.CognitiveservicesFormrecognizer.FormRecognizerClient(
cognitiveServiceCredentials,
endPoint
);
client
.batchReadReceipt(
"https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/contoso-receipt.png"
)
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log("An error occurred:");
console.error(err);
});
</script>
</head>
<body></body>
</html>