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
bwip-js is a translation to native JavaScript of the amazing code provided in [Barcode Writer in Pure PostScript](https://github.com/bwipp/postscriptbarcode). The translated code can run on any modern browser or JavaScript-based server framework.
6
6
7
-
The software has encoding modules for over 100 different barcode types and standards.
7
+
The library has encoding modules for over 100 different barcode types and standards.
8
8
All linear and two-dimensional barcodes in common use (and many uncommon
9
9
ones) are available. An exhaustive list of supported barcode types can be
10
-
found at the end of this document. Barcode images are generated as png (node-js) or to a canvas (browser)
11
-
or as SVG (all platforms).
10
+
found at the end of this document. Barcodes are generated as PNG images (node-js and react-native)
11
+
or to a canvas (browser) or as SVG (all platforms).
12
12
13
-
> Version 4 has been released. The primary enhancement is built-in support for generating barcodes in SVG. You can read about the changes here: https://github.com/metafloor/bwip-js/discussions/299
13
+
> As of version 4.5, bwip-js has been partitioned into four platform-specific packages plus the cross-platform main package. The sub-packages are currently experimental but are the solution to current build chains not properly supporting the `exports` map in `package.json`. Please use them and report any issues you find.
14
14
15
15
## Status
16
16
17
-
* Current bwip-js version is 4.4.0 (2024-06-18)
17
+
* Current bwip-js version is 4.5.0 (2024-07-03)
18
18
* Current BWIPP version is 2024-06-18
19
-
* Node.js compatibility: 0.12+
19
+
* Node.js compatibility: 6.0
20
20
* Browser compatibility: Edge, Firefox, Chrome
21
21
22
22
## Supported Platforms
@@ -46,17 +46,33 @@ or as SVG (all platforms).
46
46
47
47
## Installation
48
48
49
-
You can download the latest npm module using:
49
+
The bwip-js package has been partitioned into four platform-specific packages plus the main cross-platform package. If you install the main package and cannot get its exports to work with your build stack, try installing a platform-specific package. The platform-specific packages are ES modules only, so you will need a modern build environment. The exception is the node package, which also contains a `require()` compatible export.
50
+
51
+
52
+
You can download the main package using:
50
53
51
54
```
52
55
npm install bwip-js
53
56
```
54
57
55
-
Or the latest code from github:
58
+
Or one of the platform-specific packages using:
59
+
60
+
```
61
+
npm install @bwip-js/node
62
+
npm install @bwip-js/browser
63
+
npm install @bwip-js/react-native
64
+
npm install @bwip-js/generic
65
+
```
66
+
67
+
The node, browser and react-native packages include both an image rending interface (`toCanvas()` on the browser, `toBuffer()` on node, `toDataURL()` on react-native), plus the SVG and custom drawing context interfaces.
68
+
69
+
The generic package contains only exports that run on any platform, namely the SVG and custom drawing context interfaces.
70
+
71
+
The latest code can be obtained from github:
56
72
57
73
https://github.com/metafloor/bwip-js
58
74
59
-
(The bwip-js master branch and the npm version are kept sync'd.)
75
+
The bwip-js branches and the npm versions are automatically sync'd with each release. The main package is located under the master branch; the platform-specific packages are maintained under their like-named branches.
60
76
61
77
## Online Barcode Generator
62
78
@@ -116,7 +132,7 @@ to determine what options are available for each barcode type.
116
132
117
133
All of the BWIPP color options (e.g. `barcolor`, `textcolor`, `bordercolor`) can be specified using either RGB, RRGGBB or CCMMYYKK formats or the CSS-style #RGB and #RRGGBB formats.
118
134
119
-
Note that bwip-js normalizes the BWIPP `width` and `height` options to always be in millimeters.
135
+
Note that bwip-js normalizes the BWIPP `width` and `height` options to be in millimeters.
120
136
The resulting images are rendered at 72 dpi. To convert to pixels, use a factor of 2.835 px/mm
121
137
(72 dpi / 25.4 mm/in). The bwip-js scale options multiply the `width`, `height`, and `padding`.
122
138
@@ -157,10 +173,10 @@ module width (scale) of the rendered barcode.
157
173
<aname="browser-usage"></a>
158
174
## Browser Usage
159
175
160
-
To use within a browser, add the following to the head of your page:
176
+
To use in a browser without a bundler, add the following to the head of your page:
@@ -457,15 +485,7 @@ See the ES6 Browser Module Usage section for details on importing encoders direc
457
485
<aname="react-native"></a>
458
486
## React Native
459
487
460
-
> Note: The react-native module requires an external dependency to polyfill
461
-
> missing nodejs built-ins `zlib` and `Buffer`.
462
-
>
463
-
> You _must_ manually add it to your project. The dependency will not
464
-
> be included in bwip-js as it is only needed for react-native. To install:
465
-
466
-
```
467
-
npm install react-zlib-js --save
468
-
```
488
+
React-native has considerable legacy build environments that are not compatible with the modern `exports` map in `package.json`. For this reason, it is recommended to install the react-native package `@bwip-js/react-native`.
469
489
470
490
The react-native module provides a specialized version of the `toBuffer()` method,
471
491
called `toDataURL()`. The return value is an object with the following properties:
@@ -478,8 +498,7 @@ The returned object is designed to be used with the `<Image>` component:
478
498
479
499
```javascript
480
500
importReactfrom'react';
481
-
import'react-zlib-js'; // side effects only
482
-
importbwipjsfrom'bwip-js';
501
+
importbwipjsfrom'@bwip-js/react-native';
483
502
484
503
constBarCode= (options) => {
485
504
let img =null;
@@ -502,7 +521,7 @@ The bwip-js exports also facilitate bundler tree-shaking by providing the indivi
502
521
The exported names are the same as the `bcid` names, with the caveat that dashes `-` are replaced with underscores `_`. For example, to import the `gs1-128` encoder, you would use:
503
522
504
523
```javascript
505
-
import { gs1_128 } from'bwip-js';
524
+
import { gs1_128 } from'@bwip-js/react-native';
506
525
507
526
try {
508
527
let buf =awaitgs1_128(options);
@@ -516,15 +535,9 @@ When named encoders are called, the `bcid` value in the options object is ignore
516
535
<aname="electron-example"></a>
517
536
## Electron Example
518
537
519
-
There have been some changes to the Electron bundler, and it may pull in either the
520
-
nodejs or browser module, depending on your version of Electron. The example below
521
-
assumes the nodejs module.
522
-
523
-
If you try this example and get the error `bwipjs.toBuffer is not a function`, the
524
-
Electron bundler grabbed the browser module. See the [Browser Usage](#browser-usage)
525
-
section above and draw to a canvas instead.
538
+
With electron, you have the choice to use either the node-specific or browser-specific package. It is not recommended to use the main bwip-js package as developers have reported issues with how the bundler interacts with the package exports.
526
539
527
-
This is an example `index.html` file for a basic, single window app:
540
+
This is an example `index.html` file for a basic, single window app, using the node-js package:
528
541
529
542
```html
530
543
<!DOCTYPE html>
@@ -544,7 +557,7 @@ This is an example `index.html` file for a basic, single window app:
544
557
</body>
545
558
546
559
<script>
547
-
var bwipjs =require('bwip-js');
560
+
var bwipjs =require('@bwip-js/node');
548
561
bwipjs.toBuffer({ bcid:'qrcode', text:'0123456789' }, function (err, png) {
0 commit comments