metafloor / bwip-js

Barcode Writer in Pure JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Datamatrix generation fo binary data after 3.4.0 has extra bytes

TalaatHarb opened this issue · comments

for 3.4.0+ versions of bwip-js, datamatrix generation if the data in the data matrix is binary data results on extra bytes when scanning the datamatrix,

my use case (Electronic Prescription in Romania) requires having binary data (zip file) in the datamatrix, and since after 3.4.0 the generation generates extra bytes.

compare https://github.com/TalaatHarb/react-sample/tree/feature/datamatrix-sample latest
to https://github.com/TalaatHarb/react-sample/tree/feature/datamatrix-sample-fixed 3.4.0
in both examples it is the same data (download link allows downloading the pure binary data) and I tried also with 3.4.5 instead of latest which still have the toCanvas method but it also has the same issue.

first 16 bytes of the right datamatrix
50 4b 03 04 14 00 08 08 08 00 52 7c 9f 57 00 00

first 16 bytes of the wrong datamatrix
50 4b 03 04 14 00 08 08 08 00 52 7c c2 9f 57 00

Since the 4.0 version, there is a new flag binarytext that disables the automatic utf-8 encoding. This was needed to discriminate between 8-bit text and actual binary bytes. Set the flag as binarytext:true in the options object.

I assumed that option got removed due to that commit
f2ee56f
and due to not having it at @types/bwip-js

but trying to force it to use that option seems to work. of course not with typescript types included.

I am not the maintainer of @types/bwip-js. There are now d.ts files in the dist/ directory that you can use. They will be kept up to date with each release.