JsBarcode icon indicating copy to clipboard operation
JsBarcode copied to clipboard

How can I generate a brazilian bank slip ("boleto bancário")

Open ghashi opened this issue 4 years ago • 1 comments

Which format should I use (CODE128; EAN / UPC; CODE39; ITF-14; MSI; Pharmacode; Codabar;) to generate a brazilian "Boleto bancário" or bank slip? Or is it possible to do this using this lib? This thread says I should use 'itf' but it doesn't seem to be working.

I tested using this number "03399.33335 33886.349134 88111.901026 6 79580000014289", but the generated barcode isn't recognized by any bank app barcode scanner.

ghashi avatar Jul 19 '19 18:07 ghashi

Actually, in order to make a valid barcode for Brazilian bank slips, the code you need to transform is not the direct billet number - instead, it is a combination of a rearrangement of the digits, and some checksum digits. Simply put - after you generate the 47-digit billet number, you can do something like:

getBarcode(billetNumber: string) {
    return billetNumber.replace(/^(\d{4})(\d{5})\d{1}(\d{10})\d{1}(\d{10})\d{1}(\d{15})$/, '$1$5$2$3$4');
}

Then you can input such value using the itf encoding and it should return a valid barcode to be scanned by Brazilian banking systems.

See references at the Febraban site (current Brazilian bank slips standards) and at this repo (a nice lib from a Brazilian developer which explains in further detail how it works, js-wise).

alexandrefugita avatar Jul 19 '19 18:07 alexandrefugita