Skip to main content

Overview

The Capture-id&R module provides document capture capabilities using Regula’s Document Reader SDK. This module enables high-quality ID capture with advanced validation features including OCR data extraction, face photo extraction, and document authenticity checks.

Key Features

  • Multiple Capture Modes: Camera snapshot or document reader
  • OCR Data Extraction: Automatically extract text data from ID documents
  • Face Photo Extraction: Capture the portrait photo from the ID
  • Quality Validation: Built-in checks for sharpness, glare, and document quality
  • Multi-side Capture: Support for front and back document capture
  • Customizable UI: Fully customizable legends, colors, and styles

Hardware Requirements

This module requires valid Regula credentials including license key and API base path.
  • Modern web browser with camera access
  • Device camera (mobile or desktop)
  • Stable internet connection for API communication
  • HTTPS protocol (required for camera access)

Installation

The Capture-id&R module is included in the FAD SDK package:
npm install @fad-producto/fad-sdk

Implementation

1

Import SDK and Configuration

Import the FAD SDK and set up your Regula credentials:
import FadSDK from '@fad-producto/fad-sdk';

const CREDENTIALS = {
  license: 'YOUR_REGULA_LICENSE_KEY',
  apiBasePath: 'YOUR_REGULA_API_BASE_PATH'
};

const TOKEN = 'YOUR_FAD_TOKEN';
2

Configure Module Options

Set up the module configuration with custom legends and settings:
const CONFIGURATION = {
  views: {
    instructions: true,
    preview: true,
  },
  disableDesktopView: false,
  capture: {
    cameraSnapshot: {
      changeCameraButton: false,
      closeButton: false,
    },
    documentReader: {
      changeCameraButton: false,
      closeButton: false,
      captureButton: false,
      timeout: 60000,
    },
  },
  idValidations: {
    cardMatch: false,
  },
  customization: {
    moduleCustomization: {
      legends: {
        cameraSnapshot: {
          front: {
            instruction: 'Captura el frente de tu identificación',
          },
          back: {
            instruction: 'Captura el reverso de tu identificación',
          },
        },
      },
    },
  },
};
3

Initialize SDK and Start Module

Create the SDK instance and start the Regula capture process:
async function initProcess() {
  const options = {
    environment: FadSDK.getFadEnvironments().UATHA
  };

  const FAD_SDK = new FadSDK(TOKEN, options);
  
  try {
    const idData = true;  // Enable OCR extraction
    const idPhoto = true; // Enable face photo extraction

    // Start Regula capture
    const regulaResponse = await FAD_SDK.startRegula(
      CREDENTIALS,
      FadSDK.Constants.Regula.CaptureType.CAMERA_SNAPSHOT,
      idData,
      idPhoto,
      CONFIGURATION
    );

    // Check if user closed the module
    if (regulaResponse.event === FadSDK.Constants.EventModule.MODULE_CLOSED) {
      console.log('Module closed by user');
      return;
    }

    // Process successful capture
    console.log('Process completed', regulaResponse);
    
    // Access captured data
    const frontImage = regulaResponse.data.id.front;
    const backImage = regulaResponse.data.id.back;
    const facePhoto = regulaResponse.data.idPhoto;
    const ocrData = regulaResponse.data.idData.ocr;

  } catch (ex) {
    console.error('Process error:', ex);
    handleError(ex);
  } finally {
    FAD_SDK.end();
  }
}

Response Structure

The startRegula method returns a response object with the following structure:
{
  event: string,  // 'PROCESS_COMPLETED' or 'MODULE_CLOSED'
  data: {
    id: {
      front: string,    // Base64 image of front side
      back?: string     // Base64 image of back side (if applicable)
    },
    idPhoto: string,    // Base64 image of face from ID
    idData: {
      ocr: {            // Extracted OCR data
        firstName: string,
        lastName: string,
        documentNumber: string,
        dateOfBirth: string,
        expirationDate: string,
        // ... additional fields based on document type
      }
    },
    documentInstance: object  // Regula validation data
  }
}

Error Handling

Handle common errors using the SDK error constants:
if (ex.code === FadSDK.Errors.Regula.CAMERA_PERMISSION_DENIED) {
  alert('Camera permission denied. Please enable camera access.');
}

Capture Types

The module supports different capture types:
TypeDescriptionUse Case
CAMERA_SNAPSHOTManual capture with cameraUser-controlled capture
DOCUMENT_READERAuto-capture with document detectionAutomatic capture when document is detected

Configuration Options

views: {
  instructions: true,  // Show instruction screen
  preview: true        // Show preview screen
}
capture: {
  cameraSnapshot: {
    changeCameraButton: false,  // Show/hide camera switch button
    closeButton: false          // Show/hide close button
  },
  documentReader: {
    timeout: 60000  // Auto-capture timeout in milliseconds
  }
}
idValidations: {
  cardMatch: false  // Validate that front and back belong to same document
}

Best Practices

Lighting Conditions

Ensure good lighting conditions to improve OCR accuracy and reduce glare on documents.

Document Position

Guide users to position the document flat and fully within the capture frame.

Error Recovery

Implement clear error messages and allow users to retry capture easily.

Preview Validation

Enable preview mode to let users verify captured images before proceeding.

Build docs developers (and LLMs) love