|
| 1 | +--- |
| 2 | +layout: default-layout |
| 3 | +title: Customize MRZ Scanner - Dynamsoft MRZ Scanner MAUI Edition |
| 4 | +description: Customize the MRZ scan settings via MRZScannerConfig class when using MRZ Scanner MAUI Edition |
| 5 | +keywords: Customize, config, MRZScannerConfig, MAUI |
| 6 | +breadcrumbText: Customize MRZ Scanner |
| 7 | +noTitleIndex: true |
| 8 | +needGenerateH3Content: true |
| 9 | +needAutoGenerateSidebar: true |
| 10 | +--- |
| 11 | + |
| 12 | +# Customizing the MRZ Scanner |
| 13 | + |
| 14 | +When developing with `MRZScanner` component (see the [User Guide](index.md)), you can add extra configurations via the `MRZScannerConfig` class. Before diving into the different ways in which you can customize the MRZ Scanner, let's first break down the different properties of the `MRZScannerConfig` class. |
| 15 | + |
| 16 | +## `MRZScannerConfig` Overview |
| 17 | + |
| 18 | +The [**`MRZScannerConfig`**](../api-reference/mrz-scanner-config.md) class is capable of configuring almost all customization options applicable to MRZ scanning use cases with the MRZ Scanner. The MRZ Scanner uses passes an `MRZScannerConfig` object to the constructor when creating an MRZ Scanner instance. `MRZScannerConfig` contains the following properties: |
| 19 | + |
| 20 | +1. **`License`** - the license key is the only property whose ***value must be specified when instantiating the MRZ Scanner instance***. If the license is undefined, invalid, or expired, the MRZ Scanner cannot proceed with scanning, and instead displays a pop-up error message instructing the user to contact the app administrator to resolve this license issue. |
| 21 | + |
| 22 | +2. **`DocumentType`** - specifies the type of document that the MRZ Scanner will recognize. This property accepts values defined in the EnumDocumentType such as `EnumDocumentType.All`, `EnumDocumentType.Id`, or `EnumDocumentType.Passport`. It helps the scanner to optimize its processing based on the expected document type. To learn more about the different document types that are supported, please refer to the [Supported Document Types](index.md#supported-machine-readable-travel-document-types) section of the user guide. |
| 23 | + |
| 24 | +3. **`TemplateFile`** - a template file is a JSON file or JSON string that contains a series of algorithm parameter settings (called Capture Vision templates) that is usually used for very specific and customized scanning and parsing scenarios. The `templateFile` points to the location of the JSON file. The MRZ Scanner comes with a default template file, but you may choose to use a custom template to target specialized use cases. We recommend contacting the [Dynamsoft Technical Support Team](https://www.dynamsoft.com/company/contact/) for assistance with template customization. |
| 25 | + |
| 26 | +4. **`IsBeepEnabled`** (default value `false`) - a boolean that determines whether a beep sound is triggered upon a successful MRZ scan. When enabled (true), the scanner will play a sound to provide audible feedback. |
| 27 | + |
| 28 | +5. **`IsCameraToggleButtonVisible`** (default value `false`) - a boolean that specifies whether the camera toggle button is displayed. This button lets users switch between available cameras (e.g., front and rear). |
| 29 | + |
| 30 | +6. **`IsCloseButtonVisible`** (default value `true`) - a boolean to control the visibility of the close button on the scanner's UI. If true, a close button will be displayed allowing users to exit the MRZ scanning interface. |
| 31 | + |
| 32 | +7. **`IsGuideFrameVisible`** (default value `true`) - serves as a toggle to show or hide the guide frame in the UI during scanning. The guide frame assists users in properly aligning the document for optimal MRZ detection. When set to true, a visual overlay is displayed on the scanning interface. |
| 33 | + |
| 34 | +8. **`IsTorchButtonVisible`** (default value `true`) - determines whether the torch (flashlight) toggle button is visible on the scanning interface. Set to true to allow users to switch the device's flashlight on or off during MRZ scanning. |
| 35 | + |
| 36 | +9. **`IsVibrateEnabled`** (default value `false`) - controls the scanner's ability to make the scanning device vibrate upon a successful MRZ scan. When enabled (true), the scanner will vibrate to provide haptic feedback if the device supports it. |
| 37 | + |
| 38 | +Next, we go over the different ways that these properties can be used to customize the scanner with a few examples. |
| 39 | + |
| 40 | + |
| 41 | +## Setting the MRZ Document Type |
| 42 | + |
| 43 | +The MRZ Scanner reads all three MRZ formats, but it can optionally restrict the MRZ format that it reads. For example, you may want to configure MRZ scanner to only read **TD1** and passport (**TD3**) document types, while **ignoring TD2** documents. Here is a simple edit to the `OnScanMRZ` function that we implemented in the [User Guide](index.md) that sets the specific MRZ formats to read using the `DocumentType` property: |
| 44 | + |
| 45 | +```c# |
| 46 | +private async void OnScanMRZ(object sender, EventArgs e) |
| 47 | +{ |
| 48 | + // The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here grants a time-limited free trial which requires network connection to work. |
| 49 | + // You can request a 30-day trial license via the Request a Trial License page https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=guide&package=maui. |
| 50 | + var config = new MRZScannerConfig("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"); |
| 51 | + config.DocumentType = EnumDocumentType.Passport; // configuring the scanner to just recognize passports |
| 52 | + var result = await MRZScanner.Start(config); |
| 53 | + if (result.ResultStatus == EnumResultStatus.Finished && result.Data is not null) |
| 54 | + { |
| 55 | + /* Do something with the MRZ Result */ |
| 56 | + } |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +## Customizing the UI Elements |
| 61 | + |
| 62 | +<div align="center"> |
| 63 | + <p><img src="../../assets/mrz-scanner-ui.png" width="70%" alt="mrz-scanner"></p> |
| 64 | + <p>MRZ Scanner UI</p> |
| 65 | +</div> |
| 66 | + |
| 67 | +The MRZ Scanner UI comes with three main elements that you can configure: |
| 68 | + |
| 69 | +- *Close button*: Stop MRZ scanning and go back to the previous activity. |
| 70 | +- *Torch button*: A clickable button that can turn on/off the torch. |
| 71 | +- *Guide Frame*: A visual overlap to assist users in lining up the MRZ document in the camera frame. |
| 72 | + |
| 73 | +```c# |
| 74 | +private async void OnScanMRZ(object sender, EventArgs e) |
| 75 | +{ |
| 76 | + // The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here grants a time-limited free trial which requires network connection to work. |
| 77 | + // You can request a 30-day trial license via the Request a Trial License page https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=guide&package=maui. |
| 78 | + var config = new MRZScannerConfig("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"); |
| 79 | + config.IsCloseButtonVisible = false; // hiding the close button |
| 80 | + config.IsTorchButtonVisible = false; // hiding the torch button |
| 81 | + config.IsGuideFrameVisible = false; // hiding the guide frame |
| 82 | + var result = await MRZScanner.Start(config); |
| 83 | + if (result.ResultStatus == EnumResultStatus.Finished && result.Data is not null) |
| 84 | + { |
| 85 | + /* Do something with the MRZ Result */ |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +## Enabling Audio and Haptic Feedback |
| 91 | + |
| 92 | +The MRZ Scanner library also offers the option to enable audio and haptic feedback upon a successful MRZ scan. Through the `IsBeepEnabled` and `IsVibrateEnabled` properties, you can choose to play a sound or make the device vibrate once the MRZ is recognized. |
| 93 | + |
| 94 | +```c# |
| 95 | +private async void OnScanMRZ(object sender, EventArgs e) |
| 96 | +{ |
| 97 | + // The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here grants a time-limited free trial which requires network connection to work. |
| 98 | + // You can request a 30-day trial license via the Request a Trial License page https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=guide&package=maui. |
| 99 | + var config = new MRZScannerConfig("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"); |
| 100 | + config.IsBeepEnabled = true; // play a beep upon a successful MRZ scan |
| 101 | + config.IsVibrateEnabled = true; // make the phone vibrate upon a successful MRZ scan |
| 102 | + var result = await MRZScanner.Start(config); |
| 103 | + if (result.ResultStatus == EnumResultStatus.Finished && result.Data is not null) |
| 104 | + { |
| 105 | + /* Do something with the MRZ Result */ |
| 106 | + } |
| 107 | +} |
| 108 | +``` |
0 commit comments