Skip to content

Commit 178a29c

Browse files
committed
feat: demo for v2.0.0
1 parent 533daa4 commit 178a29c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+17723
-2093
lines changed

.github/workflows/main.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# This is a basic workflow to help you get started with Actions
2-
31
name: CI
42

53
# Controls when the workflow will run
@@ -20,19 +18,30 @@ jobs:
2018

2119
# Steps represent a sequence of tasks that will be executed as part of the job
2220
steps:
23-
# Runs a set of commands using the runners shell
2421
- name: Get Source
2522
run: |
2623
cd /home/ubuntu
2724
[ -d mrz-scanner-javascript ] && rm -rf mrz-scanner-javascript
2825
git clone --depth 1 -b demo https://github.com/Dynamsoft/mrz-scanner-javascript.git
26+
27+
- name: Prepare Files
28+
run: |
29+
# Create a temporary directory for the files to be uploaded
30+
mkdir -p /home/ubuntu/mrz-scanner-javascript/deploy
2931
32+
# Copy the dist folder
33+
cp -r /home/ubuntu/mrz-scanner-javascript/dist /home/ubuntu/mrz-scanner-javascript/deploy
34+
35+
# Copy demo and hello world. On demo branch, be sure to update the pathing for the demo
36+
cp -r /home/ubuntu/mrz-scanner-javascript/samples/demo/* /home/ubuntu/mrz-scanner-javascript/deploy
37+
cp -r /home/ubuntu/mrz-scanner-javascript/samples/hello-world.html /home/ubuntu/mrz-scanner-javascript/deploy
38+
3039
- name: Sync files
3140
uses: SamKirkland/[email protected]
3241
with:
3342
server: ${{ secrets.FTP_DEMO_SERVER }}
3443
username: ${{ secrets.FTP_DEMO_USERNAME }}
3544
password: ${{ secrets.FTP_DEMO_PASSWORD }}
3645
port: 21
37-
local-dir: /home/ubuntu/mrz-scanner-javascript/
38-
server-dir: /Demo.dynamsoft.com/solutions/mrz-scanner/
46+
local-dir: /home/ubuntu/mrz-scanner-javascript/deploy/
47+
server-dir: /Demo.dynamsoft.com/mrz-scanner/

.github/workflows/preview.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Publish Package
2+
3+
on:
4+
release:
5+
types: [created]
6+
# Optionally enable manual workflow runs
7+
workflow_dispatch:
8+
9+
jobs:
10+
build-and-publish:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v3
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: '18'
20+
registry-url: 'https://registry.npmjs.org'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
# - name: Run tests
26+
# run: npm test
27+
28+
- name: Build package
29+
run: npm run build
30+
31+
- name: Publish to npm
32+
run: npm publish
33+
env:
34+
NODE_AUTH_TOKEN: ${{ secrets.NPM_PAT }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@scannerproxy:registry=https://npm.scannerproxy.com:802/
2+
@dynamsoft:registry=https://npm.scannerproxy.com:802/

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

LICENSE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
License Notice
2+
3+
The source code of Dynamsoft MRZ Scanner provided here is released under the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0.
4+
Dynamsoft Label Recognizer (DLR), Dynamsoft Code Parser (DCP) and Dynamsoft Camera Enhancer (DCE) SDKs, which are dependencies of Dynamsoft MRZ Scanner, are licensed under a commercial license: https://www.dynamsoft.com/company/license-agreement/.
5+
6+
This file is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7+
8+
Copyright © 2003–2025 Dynamsoft. All Rights Reserved.

README.md

Lines changed: 122 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,149 @@
1-
# Dynamsoft MRZ Scanner for Web
1+
# User Guide for the MRZ Scanner for Web
22

3-
The [Dynamsoft MRZ Scanner](https://www.dynamsoft.com/use-cases/mrz-scanner/?utm_source=mrzdemo&package=js) enables camera to scan the MRZ code of ID-cards and passports. It will extract all data like first name, last name, document number, nationality, date of birth, expiration date and more from the MRZ string, and converts the encoded string into human-readable fields.
3+
This user guide will walk you through the [Hello World](https://github.com/Dynamsoft/mrz-scanner-javascript/blob/main/README.md) sample app. When creating your own application, we recommend using this sample as a reference.
44

5-
## Web demo
5+
To learn about what an MRZ is, along with the makeup and system requirements of this solution, please visit the [MRZ Introduction](https://www.dynamsoft.com/mrz-scanner/docs/web/introduction/index.html) page on the Dynamsoft website.
66

7-
You can scan the QR code below with your phone to visit our online demo, or use a desktop browser to access [https://demo.dynamsoft.com/solutions/mrz-scanner/index.html](https://demo.dynamsoft.com/solutions/mrz-scanner/index.html) (no personal data will be uploaded).
7+
## License
88

9-
<img src="https://www.dynamsoft.com/webres/wwwroot/images/usecases/mrz-scanner/mrz-scanner-demo-qr-code.svg" alt="mrz-scanner-demo-qr-code" width="200"/>
9+
### Trial License
1010

11-
## Run this Solution
11+
When you are getting started with the MRZ Scanner solution, we recommend getting your own 30-day trial license through the [customer portal](https://www.dynamsoft.com/customer/license/trialLicense/?product=mrz&utm_source=guide&package=js). The trial license can be renewed via the same customer portal twice, each time for another 15 days, giving you a total of 60 days to develop your own application using the solution. If more time is needed for a full evaluation, please contact the [Dynamsoft Support Team](https://www.dynamsoft.com/company/contact/).
1212

13-
1. Clone the repository to a working directory or download the code as a ZIP file:
13+
> Note:
14+
>
15+
> Please note that the **MRZ Scanner** license contains a license for the **Dynamsoft Label Recognizer**, **Dynamsoft Code Parser**, and the **Dynamsoft Camera Enhancer** as those are the three functional products that are central to the operation of the MRZ Scanner.
16+
17+
### Full License
18+
19+
If you are fully satisfied with the solution and would like to move forward with a full license, please contact the [Dynamsoft Sales Team](https://www.dynamsoft.com/company/contact/).
20+
21+
## Quick Start - Including the SDK and creating Hello World
22+
23+
As mentioned previously, the purpose of this guide is to help you implement a Hello World application using the MRZ Scanner solution. To showcase this, we will be using vanilla JS. You can find the full code in the [Github repository](https://github.com/Dynamsoft/mrz-scanner-javascript/blob/main/README.md).
24+
25+
The first step before you venture into writing the code is to include the SDK in your application. The simplest way to include the SDK would be to use the precompiled script - but you can also build it from source yourself.
26+
27+
### Building the Library from Source
28+
29+
In this guide, we will show the developer how to build the scanner themselves from the source files. The advantage of doing this is that it allows the developer to do some deep customization of the scanner if they are familiar with using the foundational products **Dynamsoft Label Recognizer**, **Dynamsoft Code Parser**, and the **Dynamsoft Camera Enhancer**.
30+
31+
Please note that we also offer a pre-compiled script reference to make the inclusion of the library even easier. To learn how to use that, please visit the full User Guide for the MRZ Scanner.
32+
33+
This method requires retrieving the **MRZ Scanner for Web** source files from its [Github repository](https://github.com/Dynamsoft/mrz-scanner-javascript), compiles them into a distributable package, and then runs a *ready-made* Hello World sample page that is already included in the repo.
34+
35+
Please follow these steps in order to build from the source:
36+
37+
1. Download the **MRZ Scanner for Web** source files from [Github](https://github.com/Dynamsoft/mrz-scanner-javascript) as a compressed folder ("Download ZIP" option).
38+
39+
2. Extract the contents of the compressed folder.
40+
41+
3. Open the *Hello World* sample included with the source files located at `samples/hello-world.html`
42+
43+
4. Search for 'YOUR_LICENSE_KEY_HERE' and replace that with your own license key, whether it is trial or full.
44+
45+
5. Install project dependencies - in the terminal, navigate to the project root directory and run the following:
46+
```bash
47+
npm install
48+
```
49+
50+
6. Build the project - once the dependencies are installed, build the project by running:
51+
```bash
52+
npm run build
53+
```
1454

15-
```sh
16-
git clone https://github.com/Dynamsoft/mrz-scanner-javascript
55+
7. Serve the project via localhost:
56+
```bash
57+
npm run serve
58+
```
59+
Once the server is running, open the application in a browser using the address provided in the terminal output after running `npm run serve`.
60+
61+
## Breaking down Hello World
62+
63+
Let's now go through the code of the Hello World sample and understand the purpose of each section and how they all work together to bring the app to life.
64+
65+
### Step 1: Setting up the HTML and Including the MRZ Scanner
66+
67+
```html
68+
<!DOCTYPE html>
69+
<html lang="en">
70+
<head>
71+
<meta charset="utf-8" />
72+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
73+
<title>Dynamsoft MRZ Scanner - Hello World</title>
74+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mrz-scanner.bundle.js"></script>
75+
</head>
76+
77+
<body>
78+
<h1 style="font-size: large">Dynamsoft MRZ Scanner</h1>
79+
</body>
80+
81+
</html>
1782
```
1883
19-
2. Deploy the files to a directory hosted on an HTTPS server.
84+
The first step in setting up the HTML in a Hello World implementation is to include the SDK. The ways to include the SDK has already been addressed in the [Quick Start](#quick-start---including-the-sdk-and-creating-hello-world) section, so please refer to that if you have not already. In this example, we are including the MRZ Scanner via the precompiled script as that is the easiest way to get started.
2085
21-
3. Open the "index.html" file in your browser.
86+
Since this is a Hello World implementation, the HTML body will be kept quite simple. Since the MRZ Scanner comes with a **Ready-to-Use UI**, it is not necessary to place any `<div>` placeholder elements or anything like. Once the scanner is launched, the **Ready-to-Use UI** will come up and occupy the page.
2287
23-
> Basic Requirements
24-
>
25-
> * Internet connection
26-
> * [A supported browser](#system-requirements)
27-
> * An accessible Camera
28-
29-
-----
30-
31-
## Request a Trial License
32-
33-
The key "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" used in this solution (found in the js/init.js file) is a test license valid for 24 hours for any newly authorized browser. If you wish to test the SDK further, you can request a 30-day free trial license through the <a href="https://www.dynamsoft.com/customer/license/trialLicense?product=mrz&utm_source=samples&package=js" target="_blank">Request a Trial License</a> link. For more information, see [Specify the License](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/user-guide/mrz-scanner.html#specify-the-license) or contact [[email protected]](mailto:[email protected]).
34-
35-
## Project Structure
36-
37-
```text
38-
MRZ Scanner
39-
├── assets
40-
│ ├── ...
41-
│ ├── ...
42-
│ └── ...
43-
├── css
44-
│ └── index.css
45-
├── font
46-
│ ├── ...
47-
│ ├── ...
48-
│ └── ...
49-
├── js
50-
│ ├── const.js
51-
│ ├── index.js
52-
│ ├── init.js
53-
│ └── util.js
54-
├── index.html
55-
└── template.json
88+
<!-- The main DOM element that is required in the `<body>` is a `<div>` element where the MRZ result (or lack thereof) and the original image of the MRZ document will be displayed once the user clicks *Done* in the result view. Feel free to customize the styling of the `<div>` element to your liking. -->
89+
90+
Now let's move to the main script that will define the operation of the
91+
92+
### Step 2: Initialize the MRZ Scanner
93+
94+
```js
95+
// Initialize the Dynamsoft MRZ Scanner
96+
const mrzscanner = new Dynamsoft.MRZScanner({
97+
license: "YOUR_LICENSE_KEY_HERE",
98+
});
99+
```
100+
101+
Above you will see the **simplest** way that you can initialize the MRZ Scanner. The one that is **absolutely required** in this setup is the **license**. Without a valid license, the MRZ Scanner view will not launch and you will be met with an error message explaining that the license key is invalid or has expired. To learn how to get your own license, please refer to the [License](#license) section of the guide.
102+
103+
### Step 3: Launching the MRZ Scanner
104+
105+
```js
106+
(async () => {
107+
// Launch the scanner and wait for the result
108+
const result = await mrzscanner.launch({});
109+
console.log(result);
110+
})();
56111
```
57112

58-
* `/assets` : This directory contains all the static files such as images, icons, etc. that are used in the project.
59-
* `/css` : This directory contains the CSS file(s) used for styling the project.
60-
* `/font` : This directory contains the font files used in the project.
61-
* `/js` : This directory contains all the JavaScript files used in the project.
62-
* `const.js` : This file contains definitions of certain constants or variables used across the project.
63-
* `index.js`: This is the main JavaScript file where the core logic of the project is implemented.
64-
* `init.js` : This file is used for initialization purposes, such as initializing license, load resources, etc.
65-
* `util.js` : This file contains utility functions that are used across the project.
66-
* `index.html` : This is the main HTML file that represents the homepage of the project.
67-
* `template.json` : This file contains predefined templates used in the project.
113+
Now that the MRZ Scanner has been initialized and configured, it is ready to be launched! Once the MRZ Scanner is launched, the user will see the main **MRZScannerView**. Once a MRZ is scanned (via video or static image), the MRZ Scanner then switches to the **MRZResultView** to display a cropped image of the MRZ document as well as the parsed fields of the MRZ text. Let's break down these two views:
114+
115+
#### MRZScannerView
116+
117+
Here is a quick breakdown of the UI elements that make up the main view of the MRZ Scanner
118+
119+
1. **Camera View**: The majority of the space of the MRZScannerView is occupied by the camera view to give the user a complete picture of what is being seen by the camera.
68120
69-
## System Requirements
121+
2. **Scan Guide Frame**: By default, at the centre of the camera view you will find a frame that helps guide the user on where to place the MRZ document to get a fast and accurate result. Please note that if scan guide frame is shown, then anything outside of the frame will not be captured. This frame can be hidden via the **MRZScannerViewConfig** interface.
70122
71-
This project requires the following features to work:
123+
3. **Format Selector**: Below the scan guide frame, you will also notice a selector box that allows the user to choose which formats the MRZ Scanner should recognize. The formats that show up in the format selector are configurable via the **MRZScannerConfig** interface, while the visibility of the format selector itself is configurable via the **MRZScannerViewConfig** interface. To learn about MRZ formats, please refer to the [Introduction](https://www.dynamsoft.com/mrz-scanner/docs/web/introduction/index.html#supported-mrz-formats) page.
72124
73-
- Secure context (HTTPS deployment)
125+
4. **Resolution/Camera Select Dropdown**: This dropdown allows the user to switch cameras (should they have more than one available on the device), or select a different resolution for the camera that is currently selected.
74126
75-
When deploying your application / website for production, make sure to serve it via a secure HTTPS connection. This is required for two reasons
76-
77-
- Access to the camera video stream is only granted in a security context. Most browsers impose this restriction.
78-
> Some browsers like Chrome may grant the access for `http://127.0.0.1` and `http://localhost` or even for pages opened directly from the local disk (`file:///...`). This can be helpful for temporary development and test.
79-
80-
- Dynamsoft License requires a secure context to work.
127+
5. **Load Image Button**: When this button is clicked, the user can select a MRZ document image from the device's local storage to be recognized.
81128

82-
- `WebAssembly`, `Blob`, `URL`/`createObjectURL`, `Web Workers`
129+
6. **Sound Button**: By toggling this on, the MRZ Scanner will play a *beep* sound to signal that the MRZ has been successfully recognized.
83130

84-
The above four features are required for the SDK to work.
131+
7. **Flash Button**: This button is responsible for toggling the flash of the camera should it have one. If the device doesn't have the flash feature or if the browser being used doesn't support flash, this flash icon will not show up.
85132

86-
- `MediaDevices`/`getUserMedia`
133+
8. **Close Scanner Button**: Clicking this button will close the MRZ Scanner and take the user back to the landing page.
87134

88-
This API is required for in-browser video streaming.
135+
#### MRZResultView
89136

90-
- `getSettings`
137+
Here is a quick breakdown of the UI elements that make up the result view
91138

92-
This API inspects the video input which is a `MediaStreamTrack` object about its constrainable properties.
139+
1. **Original Image**: A cropped image of the MRZ document that was just scanned will be displayed at the top by default.
93140

94-
The following table is a list of supported browsers based on the above requirements:
141+
2. **Parsed Results**: The parsed results, along with their corresponding field names, are displayed in a form view underneath the original image. In addition to displaying these parsed results, the MRZ Scanner allows the user to edit any of the fields if they find that any of the parsed info is incorrect after cross referencing it with the info on the MRZ document.
95142

96-
| Browser Name | Version |
97-
| :----------: | :--------------: |
98-
| Chrome | v78+<sup>1</sup> |
99-
| Firefox | v68+<sup>1</sup> |
100-
| Edge | v79+ |
101-
| Safari | v14+ |
143+
3. **Re-take Button**: Clicking this button allows the user to go back to the **MRZScannerView** to scan another MRZ document.
102144

103-
<sup>1</sup> devices running iOS needs to be on iOS 14.3+ for camera video streaming to work in Chrome, Firefox or other Apps using webviews.
145+
4. **Done Button**: Clicking this button basically closes the scanner and destroys the **MRZScanner** instance. At that point, the application will go back to the landing page, but the developer can dictate the action to take once this button is clicked. These actions can include allowing the user to perform some extra actions with the MRZ result, or navigating to another page, or really anything that the developer would like to do once the scanning operation is done.
104146

105-
Apart from the browsers, the operating systems may impose some limitations of their own that could restrict the use of the SDK. Browser compatibility ultimately depends on whether the browser on that particular operating system supports the features listed above.
147+
>Note:
148+
>
149+
> In the Hello World sample, no action is taken once the Done button is clicked. The scanner closes and the user is met with an empty page. In order to open the scanner again, the user must refresh the page. However, this action can be changed according to the developer's wishes as indicated above.

assets/arrow-down.svg

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)