The initialize() function
To start the Web OCR SDK, after instantiating the WebOCR class, call the initialize() function passing a list of allowed documents as a parameter.
Below is the detail of each of the possible document types:
| Name | Type | Description |
|---|---|---|
| cnh | String | Capture of physical CNH (closed), in two steps, FRONT and BACK |
| rg | String | Capture of physical RG (closed), in two steps, FRONT and BACK |
| cin_digital | String | Submission of digital CIN (pdf) issued by an official application |
| rg_digital | String | Submission of digital RG (pdf) issued by an official application |
| rne | String | Capture of physical RNE, in two steps, FRONT and BACK |
| crnm | String | Capture of physical CRNM, in two steps, FRONT and BACK |
| others | String | Should be used to allow sending other documents besides those listed above |
Attention
Adding the others type to the allowed templates causes every document sent to be accepted. Thus, even non-official documents will be accepted.
Implementation Example
An implementation example of the Web OCR SDK can be seen below:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web OCR</title>
<script src="https://ocr.caas.qitech.app/4-0-0/ocr.js"></script>
</head>
<body>
<div class="demo-app-container">
<button onclick="initOCR(['rg', 'cnh', 'rg_digital'])">
Start document collection
</button>
</div>
</body>
<script>
var webOCR = new QiTechWebOCR.WebOCR(
"<WEB_TOKEN>",
"<SESSION_ID>"
)
.setThemeConfiguration({
"companyLogo": "https://my_company/logo.png",
"primaryColor": "#FF9900",
"fontFamily": "Verdana"
})
.setShowInstructionScreen(true)
.setShowSuccessScreen(true)
.setShowAllowedTemplatesScreen(true)
.setSandboxEnvironment()
.build()
function initOCR(allowed_templates) {
webOCR.initialize(allowed_templates)
.then((ocr_results) => {
console.log(ocr_results)
})
.catch((error) => {
console.log(error)
})
}
</script>
</html>
Return Handling
The initialize() method returns a Promise:
-
Success: The Promise is resolved with an array of objects, where each object represents a captured document side. See the Collecting Returns page for details on the format.
-
Error: The Promise is rejected. You can catch these errors using the
.catch()method.