Skip to content

Barcode generation library that works in both the browser and on Node.js

License

Notifications You must be signed in to change notification settings

revaret/JsBarcode

 
 

Repository files navigation

Build Status Coverage Status

Demo

Barcode Generator

Introduction

JsBarcode is a simple way to create different types of 1d barcodes. It works both in the browser with or without jQuery and also in Node.js

This is the list of supported barcodes:

  • CODE128
  • CODE128 B
  • CODE128 C
  • EAN 13
  • EAN 8
  • UPC-A
  • CODE39
  • ITF
  • ITF-14
  • MSI
  • MSI10
  • MSI11
  • MSI1010
  • MSI1110
  • Pharmacode

Examples for browsers:

First create an image (or canvas)

<img id="barcode">

Code:

$("#barcode").JsBarcode("Hi!");
Result:

Result

Code:

$("#barcode").JsBarcode("9780199532179", {
  format:"EAN",
  displayValue:true,
  fontSize:24,
  lineColor: "#0cc"
});
Result:

Result

Code (without jQuery):

JsBarcode("#barcode","JsBarcode is easy!",{width:1,height:25});
Result:

Result

Setup for browsers:

Step 1:

Step 2:

Include the script in your code:

<script src="JsBarcode.all.min.js"></script>

Bower:

You can also use Bower to install and manage the library.

bower install jsbarcode --save

Node.js:

Install with npm:

npm install jsbarcode
npm install canvas

Use:

var JsBarcode = require('jsbarcode');
var Canvas = require("canvas");

var canvas = new Canvas();
JsBarcode(canvas, "Hello");

// Do what you want with the canvas
// See https://github.com/Automattic/node-canvas for more information

The default options:

{
  width: 2,
  height: 100,
  format: "auto",
  displayValue: true,
  fontOptions: "",
  font: "monospace",
  textAlign: "center",
  textMargin: 2,
  fontSize: 14,
  background: "#fff",
  lineColor: "#000",
  margin: 10,
  marginTop: undefined,
  marginBottom: undefined,
  marginLeft: undefined,
  marginRight: undefined,
  valid: function(valid){}
}

About

Barcode generation library that works in both the browser and on Node.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 86.0%
  • HTML 14.0%