### Install NuGet Package Source: https://github.com/regulaforensics/documentreader-web-csharp-client/blob/develop/README.md Use the Package Manager Console to install the Regula Document Reader WebClient library. ```bash PM> Install-Package Regula.DocumentReader.WebClient -Version 5.2.0 ``` -------------------------------- ### Extract Document and Portrait Images Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Retrieves document images (front, back) and portraits from processed documents, with options to get images from specific sources. Requires `Regula.DocumentReader.WebClient.Model` and `Regula.DocumentReader.WebClient.Model.Ext` namespaces. ```csharp using Regula.DocumentReader.WebClient.Model; using Regula.DocumentReader.WebClient.Model.Ext; var response = await api.ProcessAsync(request); var images = response.Images(); // Get document front image var documentFrontField = images.GetField(GraphicFieldType.DOCUMENT_FRONT); byte[] documentImage = documentFrontField.GetValue(); File.WriteAllBytes("document_front.jpg", documentImage); // Get portrait image var portraitField = images.GetField(GraphicFieldType.PORTRAIT); byte[] portrait = portraitField.GetValue(); File.WriteAllBytes("portrait.jpg", portrait); // Get portrait from specific source byte[] portraitVisual = portraitField.GetValue(Source.VISUAL); byte[] portraitRfid = portraitField.GetValue(Source.RFID); // Get signature image var signatureField = images.GetField(GraphicFieldType.SIGNATURE); if (signatureField != null) { byte[] signature = signatureField.GetValue(); File.WriteAllBytes("signature.jpg", signature); } // Get all images of a specific type var allPortraits = images.GetFields(GraphicFieldType.PORTRAIT); for (int i = 0; i < allPortraits.Count; i++) { File.WriteAllBytes($"portrait_{i}.jpg", allPortraits[i].GetValue()); } ``` -------------------------------- ### Initialize DocumentReaderApi Client Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Configure the API client using base URLs, license files, environment variables, or custom HTTP headers. ```csharp using Regula.DocumentReader.WebClient.Api; using Regula.DocumentReader.WebClient.Client; // Simple initialization with base URL var api = new DocumentReaderApi("https://api.regulaforensics.com"); // Initialization with license from file var licenseBytes = File.ReadAllBytes("regula.license"); var api = new DocumentReaderApi("https://api.regulaforensics.com") .WithLicense(licenseBytes); // Initialization with license from environment variable var licenseBase64 = Environment.GetEnvironmentVariable("REGULA_LICENSE"); var api = new DocumentReaderApi("https://api.regulaforensics.com") .WithLicense(licenseBase64); // Advanced configuration with custom headers (e.g., authentication) var configuration = new Configuration { BasePath = "https://api.regulaforensics.com", DefaultHeaders = new Dictionary { { "Authorization", $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes("USER:PASSWORD"))}" } } }; var api = new DocumentReaderApi(configuration); ``` -------------------------------- ### Perform Document Recognition Request Source: https://github.com/regulaforensics/documentreader-web-csharp-client/blob/develop/README.md Initialize the API client with a license and process an image using specific recognition parameters. ```csharp var imageBytes = File.ReadAllBytes("australia_passport.jpg"); var image = new ProcessRequestImage(new ImageData(imageBytes), Light.WHITE); var requestParams = new RecognitionParams() .WithScenario(Scenario.FULL_PROCESS) .WithResultTypeOutput(new List { Result.STATUS, Result.TEXT, Result.IMAGES, Result.DOCUMENT_TYPE }); var request = new RecognitionRequest(requestParams, image); var api = licenseFromEnv != null ? new DocumentReaderApi(apiBaseUrl).WithLicense(licenseFromEnv) : new DocumentReaderApi(apiBaseUrl).WithLicense(licenseFromFile); var response = api.Process(request); ``` -------------------------------- ### Regenerate models from OpenAPI definition Source: https://github.com/regulaforensics/documentreader-web-csharp-client/blob/develop/dev.md Execute this command from the project root to update models based on the latest OpenAPI definitions. ```bash ./update-models.sh ``` -------------------------------- ### Perform Portrait Comparison with FaceAPI Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Compares a document portrait against an external image using the Regula FaceAPI. Requires the FaceAPI URL and appropriate authentication parameters. ```csharp using Regula.DocumentReader.WebClient.Api; using Regula.DocumentReader.WebClient.Model; using Regula.DocumentReader.WebClient.Model.Ext; var documentImage = File.ReadAllBytes("passport.jpg"); var externalPortrait = File.ReadAllBytes("selfie.png"); var requestParams = new RecognitionParams { AlreadyCropped = true } .WithScenario(Scenario.FULL_PROCESS) .WithFaceApi("https://faceapi.regulaforensics.com") .WithAuthParam(new AuthParams(checkPhotoComparison: true)) .WithLog(false); var request = new RecognitionRequest( requestParams, new List { new ProcessRequestImage(new ImageDataExt(documentImage), Light.WHITE) } ); // Set external portrait for comparison request.ExtPortrait = Convert.ToBase64String(externalPortrait); var api = new DocumentReaderApi("https://api.regulaforensics.com"); var response = api.Process(request); // Get portrait comparison result var comparison = response.PortraitComparison(); if (comparison?.AuthenticityCheckList?.List?.Count > 0) { var matchPercent = comparison.AuthenticityCheckList.List[0].List[0].PercentValue; Console.WriteLine($"Portrait Match: {matchPercent}%"); } ``` -------------------------------- ### Process Document with Multiple Light Sources Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Reads images captured under white, IR, and UV light conditions to enhance authenticity verification. Requires `Regula.DocumentReader.WebClient.Model` and `Regula.DocumentReader.WebClient.Model.Ext` namespaces. ```csharp using Regula.DocumentReader.WebClient.Model; using Regula.DocumentReader.WebClient.Model.Ext; // Read images captured under different light conditions var whiteImage = File.ReadAllBytes("document_white.jpg"); var irImage = File.ReadAllBytes("document_ir.jpg"); var uvImage = File.ReadAllBytes("document_uv.jpg"); var requestParams = new RecognitionParams { AlreadyCropped = true } .WithScenario(Scenario.FULL_AUTH) .WithLog(false); // Create request with multiple light sources var request = new RecognitionRequest(requestParams, new List { new ProcessRequestImage(new ImageDataExt(whiteImage), Light.WHITE), new ProcessRequestImage(new ImageDataExt(irImage), Light.IR), new ProcessRequestImage(new ImageDataExt(uvImage), Light.UV) }); var response = await api.ProcessAsync(request); // Check authenticity results var authenticity = response.Authenticity(); if (authenticity != null) { foreach (var check in authenticity.List) { Console.WriteLine($"Check Type: {check.Type}, Result: {check.Result}"); } } ``` -------------------------------- ### Configure Processing Scenarios Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Defines various processing scenarios for the RecognitionParams object to tailor document analysis. ```csharp using Regula.DocumentReader.WebClient.Model; using Regula.DocumentReader.WebClient.Model.Ext; // MRZ only - Fast MRZ reading from passports/ID cards var mrzParams = new RecognitionParams() .WithScenario(Scenario.MRZ); // Barcode only - Read PDF417, QR codes, etc. var barcodeParams = new RecognitionParams() .WithScenario(Scenario.BARCODE); // Full process - Complete document analysis var fullParams = new RecognitionParams() .WithScenario(Scenario.FULL_PROCESS); // Full authentication - Includes security feature checks var authParams = new RecognitionParams() .WithScenario(Scenario.FULL_AUTH); // OCR only - Text recognition without MRZ var ocrParams = new RecognitionParams() .WithScenario(Scenario.OCR); // Document type identification only var docTypeParams = new RecognitionParams() .WithScenario(Scenario.DOCTYPE); // MRZ or Barcode - Try MRZ first, fallback to barcode var mrzOrBarcodeParams = new RecognitionParams() .WithScenario(Scenario.MRZ_OR_BARCODE); // Credit card reading var creditCardParams = new RecognitionParams() .WithScenario(Scenario.CREDIT_CARD); // Mobile Driver's License (mDL) var mdlParams = new RecognitionParams() .WithScenario(Scenario.MDL); ``` -------------------------------- ### Query Supported Document Database Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Retrieves the list of supported documents from the server. Supports both synchronous and asynchronous execution. ```csharp using Regula.DocumentReader.WebClient.Api; var api = new DocumentReaderApi("https://api.regulaforensics.com"); // Get list of supported documents (synchronous) var docList = api.Doclist(); foreach (var doc in docList.List) { Console.WriteLine($"Document: {doc.Name}, Country: {doc.CountryName}"); } // Async version var docListAsync = await api.DoclistAsync(); ``` -------------------------------- ### Handle API Exceptions Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Implement try-catch blocks to handle ApiException and general exceptions. Check the OverallStatus of the response to verify document validation results. ```csharp using Regula.DocumentReader.WebClient.Api; using Regula.DocumentReader.WebClient.Client; var api = new DocumentReaderApi("https://api.regulaforensics.com"); try { var response = await api.ProcessAsync(request); if (response.Status()?.OverallStatus != CheckResult.OK) { Console.WriteLine("Document validation failed"); } } catch (ApiException ex) { Console.WriteLine($"API Error: {ex.ErrorCode} - {ex.Message}"); Console.WriteLine($"Response Body: {ex.ErrorContent}"); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } ``` -------------------------------- ### Retrieve Server Health and Version Info Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Checks the API server status and retrieves version information. The Ping method is provided for legacy support. ```csharp using Regula.DocumentReader.WebClient.Api; var api = new DocumentReaderApi("https://api.regulaforensics.com"); // Get server health and version info var healthInfo = api.Health(); Console.WriteLine($"API Version: {healthInfo.VarVersion}"); Console.WriteLine($"Status: {healthInfo.App.Ready}"); // Legacy ping endpoint (deprecated) var deviceInfo = api.Ping(); Console.WriteLine($"Version: {deviceInfo.VarVersion}"); ``` -------------------------------- ### POST /process Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Processes document images to extract text, images, and authenticity results. Supports both synchronous and asynchronous execution. ```APIDOC ## POST /process ### Description Processes document images to extract text, images, and authentication results. This is the primary method for document recognition. ### Method POST ### Endpoint /process ### Request Body - **request** (RecognitionRequest) - Required - The recognition request object containing parameters and image data. ### Request Example { "processParam": { "scenario": "FullProcess", "resultTypeOutput": ["Status", "Text", "Images", "DocumentType", "Authenticity"] }, "list": [ { "image": "", "light": 1 } ] } ### Response #### Success Response (200) - **response** (RecognitionResponse) - The structured recognition result containing status, document type, and extracted data. #### Response Example { "status": { "overallStatus": 0, "detailsOptical": { "text": 0 } }, "documentType": { "documentName": "Passport" } } ``` -------------------------------- ### Manage Transactions with TransactionApi Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Use the TransactionApi to retrieve, reprocess, or delete stored transactions. Ensure the base URL is correctly configured before initializing the API client. ```csharp using Regula.DocumentReader.WebClient.Api; using Regula.DocumentReader.WebClient.Model; var transactionApi = new TransactionApi("https://api.regulaforensics.com"); var transactionId = Guid.Parse("your-transaction-id"); // Get transaction data var transactionData = transactionApi.ApiV2TransactionTransactionIdGet(transactionId); // Get transaction results with images var results = transactionApi.ApiV2TransactionTransactionIdResultsGet(transactionId, withImages: true); // Get specific file from transaction var file = transactionApi.ApiV2TransactionTransactionIdFileGet(transactionId, "image.jpg"); // Reprocess transaction with new parameters var reprocessRequest = new TransactionProcessRequest(); var reprocessResult = transactionApi.ApiV2TransactionTransactionIdProcessPost( transactionId, reprocessRequest, useCache: false ); // Get transactions by tag var transactionsByTag = transactionApi.ApiV2TagTagIdTransactionsGet("my-tag"); // Delete transactions by tag transactionApi.ApiV2TagTagIdDelete(Guid.Parse("tag-id")); ``` -------------------------------- ### Error Handling Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Handle API exceptions and errors properly. ```APIDOC ## Error Handling ### Description Handle API exceptions and errors properly. ### Usage Wrap API calls in a try-catch block to handle `ApiException` for specific API errors or general `Exception` for other issues. ``` -------------------------------- ### Process Document Recognition Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Submit document images for recognition and extract text, images, and authenticity results using synchronous or asynchronous methods. ```csharp using Regula.DocumentReader.WebClient.Api; using Regula.DocumentReader.WebClient.Model; using Regula.DocumentReader.WebClient.Model.Ext; // Read document image var imageBytes = File.ReadAllBytes("passport.jpg"); // Configure recognition parameters var requestParams = new RecognitionParams() .WithScenario(Scenario.FULL_PROCESS) .WithResultTypeOutput(new List { Result.STATUS, Result.TEXT, Result.IMAGES, Result.DOCUMENT_TYPE, Result.AUTHENTICITY }) .WithLog(false); // Create request with image var image = new ProcessRequestImage(new ImageDataExt(imageBytes), Light.WHITE); var request = new RecognitionRequest(requestParams, image); // Process document (synchronous) var api = new DocumentReaderApi("https://api.regulaforensics.com"); var response = api.Process(request); // Process document (asynchronous) var response = await api.ProcessAsync(request); // Access overall document status var status = response.Status(); Console.WriteLine($"Overall Status: {(status.OverallStatus == CheckResult.OK ? "Valid" : "Invalid")}"); Console.WriteLine($"Optical Text Status: {(status.DetailsOptical.Text == CheckResult.OK ? "Valid" : "Invalid")}"); // Get document type var docType = response.DocumentType(); Console.WriteLine($"Document: {docType.DocumentName}"); ``` -------------------------------- ### Evaluate Image Quality Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Performs image quality checks on submitted documents. Requires configuring the output result type to include IMAGE_QUALITY. ```csharp using Regula.DocumentReader.WebClient.Model; using Regula.DocumentReader.WebClient.Model.Ext; var requestParams = new RecognitionParams() .WithScenario(Scenario.FULL_PROCESS) .WithResultTypeOutput(new List { Result.IMAGE_QUALITY }); var request = new RecognitionRequest(requestParams, imageBytes); var response = await api.ProcessAsync(request); var imageQuality = response.ImageQualityChecks(); if (imageQuality != null) { foreach (var check in imageQuality.List) { Console.WriteLine($"Check: {check.Type}, Result: {check.Result}"); } } ``` -------------------------------- ### Parse Recognition Results Source: https://github.com/regulaforensics/documentreader-web-csharp-client/blob/develop/README.md Extract status, text fields, and image data from the API response object. ```csharp var response = api.Process(request); // status examples var status = response.Status(); string docOverallStatus = status.OverallStatus == CheckResult.OK ? "valid" : "not valid"; string docOpticalTextStatus = status.DetailsOptical.Text == CheckResult.OK ? "valid" : "not valid"; // text fields examples var docNumberField = response.Text().GetField(TextFieldType.DOCUMENT_NUMBER); string docNumberVisual = docNumberField.GetValue(Source.VISUAL); string docNumberMrz = docNumberField.GetValue(Source.MRZ); int docNumberVisualValidity = docNumberField.SourceValidity(Source.VISUAL); int docNumberMrzValidity = docNumberField.SourceValidity(Source.MRZ); int docNumberMrzVisualMatching = docNumberField.CrossSourceComparison(Source.MRZ, Source.VISUAL); // images fields examples var documentImage = response.Images().GetField(GraphicFieldType.DOCUMENT_FRONT).GetValue(); var portraitField = response.Images().GetField(GraphicFieldType.PORTRAIT); var portraitFromVisual = portraitField.GetValue(Source.VISUAL); ``` -------------------------------- ### Extract and Validate Text Fields Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Extracts text fields from recognized documents, allowing access by type, source, and cross-source comparison. Requires `Regula.DocumentReader.WebClient.Model` and `Regula.DocumentReader.WebClient.Model.Ext` namespaces. ```csharp using Regula.DocumentReader.WebClient.Model; using Regula.DocumentReader.WebClient.Model.Ext; var response = await api.ProcessAsync(request); var text = response.Text(); // Get all text fields foreach (var field in text.FieldList) { Console.WriteLine($"{field.FieldName}: {field.Value}"); } // Get specific field by type var docNumberField = text.GetField(TextFieldType.DOCUMENT_NUMBER); var surnameField = text.GetField(TextFieldType.SURNAME); var givenNameField = text.GetField(TextFieldType.GIVEN_NAMES); var dateOfBirthField = text.GetField(TextFieldType.DATE_OF_BIRTH); var expiryField = text.GetField(TextFieldType.DATE_OF_EXPIRY); Console.WriteLine($"Document Number: {docNumberField?.Value}"); Console.WriteLine($"Name: {givenNameField?.Value} {surnameField?.Value}"); // Get field value from specific source (VISUAL, MRZ, BARCODE, RFID) string docNumberVisual = docNumberField.GetValue(Source.VISUAL); string docNumberMrz = docNumberField.GetValue(Source.MRZ); Console.WriteLine($"Doc Number (Visual): {docNumberVisual}"); Console.WriteLine($"Doc Number (MRZ): {docNumberMrz}"); // Validate field source CheckResult visualValidity = docNumberField.SourceValidity(Source.VISUAL); CheckResult mrzValidity = docNumberField.SourceValidity(Source.MRZ); // Cross-source comparison (check if MRZ matches visual) CheckResult mrzVisualMatch = docNumberField.CrossSourceComparison(Source.MRZ, Source.VISUAL); Console.WriteLine($"MRZ/Visual Match: {(mrzVisualMatch == CheckResult.OK ? "Match" : "Mismatch")}"); // Quick field value access string nationality = text.GetFieldValue(TextFieldType.NATIONALITY); string issuingState = text.GetFieldValue(TextFieldType.ISSUING_STATE_NAME); ``` -------------------------------- ### Transaction API Operations Source: https://context7.com/regulaforensics/documentreader-web-csharp-client/llms.txt Manage and reprocess stored transactions for batch processing scenarios. ```APIDOC ## Transaction API Operations ### Description Manage and reprocess stored transactions for batch processing scenarios. ### Methods #### GET /api/v2/transaction/{transactionId} Get transaction data. #### GET /api/v2/transaction/{transactionId}/results Get transaction results with images. #### GET /api/v2/transaction/{transactionId}/file Get a specific file from a transaction. #### POST /api/v2/transaction/{transactionId}/process Reprocess transaction with new parameters. #### GET /api/v2/tag/{tagId}/transactions Get transactions by tag. #### DELETE /api/v2/tag/{tagId} Delete transactions by tag. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.