You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-32Lines changed: 36 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,14 @@
1
1
# Build a Web-Based Barcode Scanner Using Just a Few Lines of JavaScript
2
2
3
+
<!-- Don't forget to add the TOC & update license section, which is useful for npm README.-->
4
+
-[Build a Web-Based Barcode Scanner Using Just a Few Lines of JavaScript](#build-a-web-based-barcode-scanner-using-just-a-few-lines-of-javascript)
5
+
-[License](#license)
6
+
-[Quick Start: Hello World Example](#quick-start-hello-world-example)
7
+
-[Step 1: Setting up the HTML and Including the Barcode Scanner](#step-1-setting-up-the-html-and-including-the-barcode-scanner)
8
+
-[Step 2: Initializing the Barcode Scanner](#step-2-initializing-the-barcode-scanner)
9
+
-[Step 3: Launching the Barcode Scanner](#step-3-launching-the-barcode-scanner)
10
+
-[Next Steps](#next-steps)
11
+
3
12
This user guide provides a step-by-step walkthrough of a "Hello World" web application using the `BarcodeScanner` JavaScript Edition.
4
13
5
14
The `BarcodeScanner` class offers the following features:
@@ -35,26 +44,19 @@ new Dynamsoft.BarcodeScanner().launch().then(result=>alert(result.barcodeResults
35
44
36
45
## License
37
46
38
-
<!-- When getting started with Barcode Scanner, we recommend getting your own 30-day trial license. -->
39
-
40
47
When getting started with Barcode Scanner, we recommend [getting your own 30-day trial license](https://www.dynamsoft.com/customer/license/trialLicense/?product=dbr&utm_source=github&package=js)
41
48
42
-
<!-- {% include trialLicense.html %} -->
43
-
44
-
> [!IMPORTANT]
45
-
> The trial license can be renewed via the [customer portal](https://www.dynamsoft.com/customer/license/trialLicense/?product=dbr&utm_source=github&package=js) twice, each time for another 15 days, giving you a total of 60 days to develop your own application using the solution. Please contact the [Dynamsoft Support Team](https://www.dynamsoft.com/company/contact/) if you need more time for a full evaluation.
49
+
<!-- When getting started with Barcode Scanner, we recommend getting your own 30-day trial license.
46
50
47
-
### Full License
48
-
49
-
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/).
<atarget="_blank"href="https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v11.0.60/barcode-scanner-api-samples/scan-single-barcode/hello-world.html"title="Code in Github"style="text-decoration:none;">
80
+
<atarget="_blank"href="https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v11.2.20/barcode-scanner-api-samples/scan-single-barcode/hello-world.html"title="Code in Github"style="text-decoration:none;">
79
81
<img src="https://cdn.jsdelivr.net/npm/[email protected]/icons/github.svg" alt="Code in Github" width="20" height="20" style="width:20px;height:20px;">
80
82
</a>
81
83
82
84
<atarget="_blank"href="https://jsfiddle.net/DynamsoftTeam/gcqjf5r7/"title="Run via JSFiddle"style="text-decoration:none;">
83
85
<img src="https://cdn.jsdelivr.net/npm/[email protected]/icons/jsfiddle.svg" alt="Run via JSFiddle" width="20" height="20" style="width:20px;height:20px;" >
84
86
</a>
85
87
86
-
<atarget="_blank"href="https://demo.dynamsoft.com/Samples/DBR/JS/barcode-scanner-api-samples/scan-single-barcode/hello-world.html?ver=11.0.60&utm_source=github"title="Run in Dynamsoft"style="text-decoration:none;">
88
+
<atarget="_blank"href="https://demo.dynamsoft.com/Samples/DBR/JS/barcode-scanner-api-samples/scan-single-barcode/hello-world.html?ver=11.2.20&utm_source=github"title="Run in Dynamsoft"style="text-decoration:none;">
87
89
<img src="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/svgs/solid/circle-play.svg" alt="Run in Dynamsoft" width="20" height="20" style="width:20px;height:20px;">
88
90
</a>
89
91
</p>
90
92
91
93
### Step 1: Setting up the HTML and Including the Barcode Scanner
92
94
93
-
As outlined earlier, this guide will help you create a simple Hello World barcode scanning application using vanilla JavaScript. The full sample code is also available in the [GitHub repository](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/v11.0.60).
95
+
As outlined earlier, this guide will help you create a simple Hello World barcode scanning application using vanilla JavaScript. The full sample code is also available in the [GitHub repository](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/v11.2.20).
94
96
95
97
The first step before writing the code is to include the SDK in your application. You can simply include the SDK by using the precompiled script.
When using a framework such as **React**, **Vue** or **Angular**, we recommend adding the package as a dependency using a package manager such as **npm** or **yarn**:
As for package managers like **npm** or **yarn**, you likely need to specify the location of the engine files as a link to a CDN. Please see the [BarcodeScannerConfig API](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/barcode-scanner.html#barcodescannerconfig) for a code snippet on how to set the `engineResourcePaths`.
137
+
When using package managers like **npm** or **yarn**, you likely need to specify the location of the engine files as a link to a CDN. Please see the [BarcodeScannerConfig API](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/barcode-scanner.html#barcodescannerconfig) for a code snippet on how to set the `engineResourcePaths`.
136
138
<divclass="multi-panel-end"></div>
137
139
138
140
<divclass="multi-panel-start"></div>
@@ -142,25 +144,25 @@ Alternatively, you may choose to download the SDK and host the files on your own
The resources are located in the `./dist/` directory.
148
150
149
151
- From npm
150
152
151
153
```sh
152
-
npm i dynamsoft-barcode-reader-bundle@11.0.6000
154
+
npm i dynamsoft-barcode-reader-bundle@11.2.2000
153
155
```
154
156
155
157
The resources are located at the path `node_modules/<pkg>`, without `@<version>`. You can copy it elsewhere and add `@<version>` tag.
156
158
157
159
> [!IMPORTANT]
158
160
> Since "node_modules" is reserved for Node.js dependencies, and in our case the package is used only as static resources, we recommend either renaming the "node_modules" folder or moving the "dynamsoft-" packages to a dedicated folder for static resources in your project to facilitate self-hosting.
@@ -172,9 +174,9 @@ Barcode Scanner comes with a **Ready-to-Use UI**. When the Barcode Scanner launc
172
174
173
175
```js
174
176
// Initialize the Dynamsoft Barcode Scanner
175
-
constbarcodescanner=newDynamsoft.BarcodeScanner({
177
+
constbarcodeScanner=newDynamsoft.BarcodeScanner({
176
178
// Please don't forget to replace YOUR_LICENSE_KEY_HERE
177
-
license:"YOUR_LICENSE_KEY_HERE",
179
+
license:"YOUR_LICENSE_KEY_HERE",
178
180
});
179
181
```
180
182
@@ -185,7 +187,7 @@ This is the **simplest** way to initialize the Barcode Scanner. The configuratio
185
187
186
188
```js
187
189
// Initialize the Dynamsoft Barcode Scanner in MULTI_UNIQUE mode
188
-
constbarcodescanner=newDynamsoft.BarcodeScanner({
190
+
constbarcodeScanner=newDynamsoft.BarcodeScanner({
189
191
license:"YOUR_LICENSE_KEY_HERE",
190
192
scanMode:Dynamsoft.EnumScanMode.SM_MULTI_UNIQUE,
191
193
});
@@ -196,7 +198,7 @@ const barcodescanner = new Dynamsoft.BarcodeScanner({
196
198
```js
197
199
(async () => {
198
200
// Launch the scanner and wait for the result
199
-
constresult=awaitbarcodescanner.launch();
201
+
constresult=awaitbarcodeScanner.launch();
200
202
// Display the first detected barcode's text in an alert
201
203
if (result.barcodeResults.length) {
202
204
alert(result.barcodeResults[0].text);
@@ -207,12 +209,14 @@ const barcodescanner = new Dynamsoft.BarcodeScanner({
207
209
Now that the Barcode Scanner has been initialized and configured, it is ready to be launched! Upon launch, the Barcode Scanner presents the main **`BarcodeScannerView`** UI in its container on the page, and is ready to start scanning. By default, we use the `SINGLE` scanning mode, which means only one decoding result will be included in the final result. In the code above, we directly alerted the successfully decoded barcode text on the page.
208
210
209
211
> [!NOTE]
210
-
> In the Hello World sample, after a successfully decoding process, 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. You may choose to implement a more user-friendly behavior in a production environment, such as presenting the user with an option to re-open the Barcode Scanner upon closing it.
212
+
> In the Hello World sample, after a successful decoding process, 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. You may choose to implement a more user-friendly behavior in a production environment, such as presenting the user with an option to re-open the Barcode Scanner upon closing it.
211
213
214
+
> [!TIP]
215
+
> When running performance benchmarks, make sure to disable the console, avoid using `console.log()`, and run in non-debug mode whenever possible. This ensures that your benchmark results reflect true performance without interference from logging or debugging overhead.
212
216
## Next Steps
213
217
214
-
Now that you've implemented the basic functionality, here are some recommended next steps to further explore the capabilities of the Barcode Scanner
218
+
Now that you've implemented the basic functionality, here are some recommended next steps to further explore the capabilities of the Barcode Scanner:
215
219
216
220
1. Learn how to [Customize the Barcode Scanner](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/user-guide/barcode-scanner-customization.html)
217
-
2. Check out the [Official Samples and Demo](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/samples-demos/index.html?ver=11.0.6000)
218
-
3. Learn about the [APIs of BarcodeScanner](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/barcode-scanner.html?ver=11.0.6000)
221
+
2. Check out the [Official Samples and Demo](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/samples-demos/index.html?ver=11.2.2000)
222
+
3. Learn about the [APIs of BarcodeScanner](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/barcode-scanner.html?ver=11.2.2000)
0 commit comments