lindell /JsBarcode
Barcode generation library written in JavaScript that works in both the browser and on Node.js
★ 5,901⑂ 1,112👁 131⑃ 97● 371▤ 82
+0
日增长
5,901
stars
1,112
forks
131
watchers
97
prs
371
issues
82
releases
README
Introduction
----
JsBarcode is a barcode generator written in JavaScript. It supports multiple barcode formats and works in browsers and with Node.js. It has no dependencies when it is used for the web but works with jQuery if you are into that.
Demo
----
Barcode Generator
Simple CodePen Demo
Settings CodePen Demo
Supported barcodes:
----
CODE128
CODE128 (automatic mode switching)
CODE128 A/B/C (force mode)
EAN
EAN-13
EAN-8
EAN-5
EAN-2
UPC (A)
UPC (E)
CODE39
ITF
ITF
ITF-14
MSI
MSI10
MSI11
MSI1010
MSI1110
Pharmacode
Codabar
CODE93
Examples for browsers:
----
First create a canvas (or image)
html
Simple example:
javascript
JsBarcode("barcode", "Hi!");
// or with jQuery
$("barcode").JsBarcode("Hi!");
Result:
!Result
Example with options:
javascript
JsBarcode("barcode", "1234", {
format: "pharmacode",
lineColor: "0aa",
width:4,
height:40,
displayValue: false
});
Result:
!Result
More advanced use case:
javascript
JsBarcode("barcode")
.options({font: "OCR-B"}) // Will affect all barcodes
.EAN13("1234567890128", {fontSize: 18, textMargin: 0})
.blank(20) // Create space between the barcodes
.EAN5("12345", {height: 85, textPosition: "top", fontSize: 16, marginTop: 15})
.render();
Result:
!Result
Or define the value and options in the HTML element:
Use any jsbarcode- or data- as attributes where is any option.
html
And then initialize it with:
javascript
JsBarcode(".barcode").init();
Result:
!Result
Retrieve the barcode values so you can render it any way you'd like
Pass in an object which will be filled with data.
javascript
const data = {};
JsBarcode(data, 'text', {...options});
data will be filled with a encodings property which has all the needed values.
See wiki for an example of what data looks like.
Setup for browsers:
----
Step 1:
Download or get the CDN link to the script:
| Name | Supported barcodes | Size (gzip) | CDN / Download |
|------|--------------------|:-----------:|---------------:|
| All | All the barcodes! | 11.1 kB | [JsBarcode.all.min.js][1] |
| CODE128 | CODE128 (auto and force mode) | 6.3 kB | [JsBarcode.code128.min.js][2] |
| CODE39 | CODE39 | 5.1 kB | [JsBarcode.code39.min.js][3] |
| EAN / UPC | EAN-13, EAN-8, EAN-5, EAN-2, UPC (A) | 6.7 kB | [JsBarcode.ean-upc.min.js][4] |
| ITF | ITF, ITF-14 | 5.1 kB | [JsBarcode.itf.min.js][5] |
| MSI | MSI, MSI10, MSI11, MSI1010, MSI1110 | 5 kB | [JsBarcode.msi.min.js][6] |
| Pharmacode | Pharmacode | 4.8 kB | [JsBarcode.pharmacode.min.js][7] |
| Codabar | Codabar | 4.9 kB | [JsBarcode.codabar.min.js][8] |
| CODE93 | CODE93 | | JsBarcode.code93.min.js |
Step 2:
Include the script in your code:
html
Step 3:
You are done! Go generate some barcodes :smile:
Bower and npm:
----
You can also use Bower or npm to install and manage the library.
bash
bower install jsbarcode --save
bash
npm instaTop issues
#263New major version (4.0) discussion42 comments · 2018-09-02#130Support RM4SCC and KIX15 comments · 2017-02-26#200The size in webpack8 comments · 2017-11-07#137Can we show barcode text position both top and bottom?8 comments · 2017-03-25#134Generate barcode on Angular2 project7 comments · 2017-03-14#81Fix coveralls coverage6 comments · 2016-07-13#347Font options should not be written as shorthand5 comments · 2020-10-05#337Use with React PDF 5 comments · 2020-07-08
Discussions
#473Add a Post text0 comments · 2025-07-31#464CMYK black?0 comments · 2025-01-27#460Set default options value to use them without inserting the same options in each JsBarcode call1 comments · 2024-10-05#459Built-in label function0 comments · 2024-08-20#456JsBarcode and inline syling0 comments · 2024-07-04#453About the "flat" option on EAN and UPC1 comments · 2024-05-13#441Checksum information0 comments · 2023-12-04#435BarCode Generator doesn't work for me0 comments · 2023-08-19