metafloor / bwip-js

Barcode Writer in Pure JavaScript
Other
2.03k stars 295 forks source link

Generating swissqrcode #210

Closed varan-raj closed 1 year ago

varan-raj commented 3 years ago

Hi,

I am using the latest version of bwip-js (3.0.0), while trying to generate the swissqrcode using the function(bwipp_swissqrcode()), I faced an issue stating that the clip($$.clip()) and setrgbcolor( $$.setrgbcolor(0, 0, 0)) is not a function in the console as error, due to which i am unable to generate the expected QR code. Request you to help me on this. Thanks in Advance

Regards, Varan

metafloor commented 3 years ago

At present, swissqrcode is not supported. I did not foresee the need for clipping functionality when generating barcodes,

varan-raj commented 3 years ago

Hi,

Thanks for the Information, Could you please suggest any Node js which supports the swiss QR code Type(not Swiss bill only QR code)

metafloor commented 3 years ago

I am not aware of any package that does so.

vpetrovych commented 3 years ago

@metafloor do you have plans on supporting Swiss QR code?

metafloor commented 2 years ago

Version 3.0.4 has experimental support for swissqrcode. If you use it, test thoroughly for your use cases. The clipping and drawing of the swiss cross uses a scaling factor that is not related to module width, so the drawing code has to make special accommodations.

A sample usage:

const fs = require('fs');
const bwipjs = require('bwip-js');

// Per section 4.1.4, EOL should be <CRLF>, omitted on last line.
function swissqr(string) {
    return string.replace(/\r\n|[\r\n]/g, '\r\n')
                        .replace(/(\r\n)+$/,'')
                        .replace(/(^|\r\n)[ \t]+/g, '$1');
}
bwipjs.toBuffer({
            // text from section 4.4 QR-bill "DO NOT USE FOR PAYMENT"
            bcid: 'swissqrcode',
            text: swissqr(`SPC
                   0200
                   1
                   CH4431999123000889012
                   S
                   Max Muster & Söhne
                   Musterstrasse
                   123
                   8000
                   Seldwyla
                   CH

                   0.00
                   CHF
                   S
                   Simon Muster
                   Musterstrasse
                   1
                   8000
                   Seldwyla
                   CH
                   QRR
                   210000000003139471430009017
                   DO NOT USE FOR PAYMENT
                   EPD`),
        }).then((buf) => {
            fs.writeFileSync('swissqr.png', buf);
        }).catch((err) => {
            console.log(err.stack || err);
        });
ZeroVector518 commented 1 year ago

What is the status on this, is Swiss QR code support in a more advanced state now than "experimental"?

metafloor commented 1 year ago

Swiss QR Code is now fully supported in v3.2.0.