|
| 1 | +--- |
| 2 | +layout: default-layout |
| 3 | +title: How to Scan EAN/UPC with Addon Codes? |
| 4 | +keywords: Dynamsoft Barcode Reader, FAQ, tech basic, EAN-2, EAN-5, UPC–A, Add-On, supplement |
| 5 | +description: How to Scan EAN/UPC with Addon Codes? |
| 6 | +needAutoGenerateSidebar: false |
| 7 | +permalink: /faq/general/how-to-scan-ean-upc-with-addon.html |
| 8 | +--- |
| 9 | + |
| 10 | +# How to Scan EAN/UPC with Addon Codes? |
| 11 | + |
| 12 | +[<< Back to FAQ index](index.md) |
| 13 | + |
| 14 | +UPC and EAN are barcode formats commonly used for product identification. These formats can include supplemental 2-digit or 5-digit barcodes (known as AddOn Codes), typically found on the right side of the main barcode. These AddOn Codes are often used for magazines, books, or other products to encode additional information like pricing or issue numbers. |
| 15 | + |
| 16 | +Dynamsoft Barcode Reader (DBR) does not enable reading such AddOn Codes by default. |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +To enable AddOn Code scanning, the property `EnableAddOnCode` in the `BarcodeFormatSpecificationOptions` array must be set to 1. |
| 22 | + |
| 23 | +If you want to limit the Dynamsoft Barcode Reader to only decode UPC and EAN codes with AddOn Codes, consider the following additional configurations: |
| 24 | +1. **Regular Expression Filtering:** Use `BarcodeTextRegExPattern` to exclude results without AddOn Codes. |
| 25 | +2. **Barcode Format Restriction:** Restrict the barcode formats to EAN and UPC only by setting `BarcodeFormatIds`. |
| 26 | + |
| 27 | +### Using JSON Templates |
| 28 | + |
| 29 | +Modify all of the `EnableAddOnCode` property in your template file by setting its value to `1`: |
| 30 | +```json |
| 31 | +{ |
| 32 | + "BarcodeFormatSpecificationOptions": |
| 33 | + [ |
| 34 | + { |
| 35 | + "EnableAddOnCode": 1, // Enable AddOn Codes |
| 36 | + "Name": "bfs1", |
| 37 | + // (OPTIONAL) Apply Regular Expression Filtering |
| 38 | + // Exclude All Other Results Without Addon Codes |
| 39 | + "BarcodeTextRegExPattern" : "\\d+-\\d+", |
| 40 | + ... |
| 41 | + }, |
| 42 | + ... |
| 43 | + ], |
| 44 | + "BarcodeReaderTaskSettingOptions" : |
| 45 | + [ |
| 46 | + { // (OPTIONAL) Restrict Formats to EAN and UPC Only |
| 47 | + "BarcodeFormatIds" : |
| 48 | + [ "BF_EAN_8", "BF_EAN_13", "BF_UPC_A", "BF_UPC_E" ], |
| 49 | + } |
| 50 | + ], |
| 51 | + ... |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +### Using JavaScript Code |
| 56 | + |
| 57 | +```javascript |
| 58 | +let settings = await cvRouter.outputSettings(); // Retrieve the runtime settings |
| 59 | +let formatOptionsArray = settings.BarcodeFormatSpecificationOptions; |
| 60 | +for (let index = 0; index < formatOptionsArray.length; index++) { |
| 61 | + const options = formatOptionsArray[index]; |
| 62 | + // Enable AddOn Codes |
| 63 | + options["EnableAddOnCode"] = 1; |
| 64 | + // (OPTIONAL) Apply Regular Expression Filtering |
| 65 | + // Exclude Results Without AddOn Codes |
| 66 | + options["BarcodeTextRegExPattern"] = "\\d+-\\d+"; |
| 67 | +} |
| 68 | + |
| 69 | +// -------------------- (OPTIONAL) ------------------------------------------- |
| 70 | +// Restrict Expected Barcode Formats to EAN and UPC Only |
| 71 | +let barcodeOptionsArray = settings.BarcodeReaderTaskSettingOptions; |
| 72 | +for (let index = 0; index < barcodeOptionsArray.length; index++) { |
| 73 | + const options = barcodeOptionsArray[index]; |
| 74 | + options["BarcodeFormatIds"] = ["BF_EAN_8", "BF_EAN_13", "BF_UPC_A", "BF_UPC_E"]; |
| 75 | +} |
| 76 | +// --------------------------------------------------------------------------- |
| 77 | + |
| 78 | +await cvRouter.initSettings(settings); // Apply the modified settings |
| 79 | +``` |
| 80 | + |
| 81 | +### Sample Code |
| 82 | + |
| 83 | +You may also find it helpful to explore our [blog post on scanning EAN/UPC and AddOn codes with JavaScript](https://www.dynamsoft.com/codepool/scan-ean-upc-and-its-add-on-javascript.html). |
0 commit comments