Skip to main content

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:

NameTypeDescription
cnhStringCapture of physical CNH (closed), in two steps, FRONT and BACK
rgStringCapture of physical RG (closed), in two steps, FRONT and BACK
cin_digitalStringSubmission of digital CIN (pdf) issued by an official application
rg_digitalStringSubmission of digital RG (pdf) issued by an official application
rneStringCapture of physical RNE, in two steps, FRONT and BACK
crnmStringCapture of physical CRNM, in two steps, FRONT and BACK
othersStringShould 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.