bwip-js icon indicating copy to clipboard operation
bwip-js copied to clipboard

parsefnc with iso-8859-15 seems not to work for pdf417

Open fradev1988 opened this issue 2 years ago • 11 comments

Hi,

I'm working on a project where is mandatory to use as encoding iso-8859-15 to generate a pdf417 barcode.

I'm calling the bwipjs.toCanvas with the following options: bcid: 'pdf417', text: myText, scaleX: 3, scaleY: 2, columns: 7, eclevel: 4, parsefnc: true

where "myText" is of this form: "^ECI000017" + valueString.

It seems that all the characters that contain a dieresis like ë are not encoding correcty

as example if I try to convert the following world Schaumbërg the result is Schaumbërg.

Moreover also other special chars like the euro symbol are not correctly rapresented. In this case the euro became €

fradev1988 avatar Oct 12 '23 13:10 fradev1988

Set the binarytext flag to true. By default, UTF-16 strings are assumed and converted to UTF-8.

metafloor avatar Oct 12 '23 17:10 metafloor

Hi @metafloor, thanks for the quick response.

Now I set the option as follow: bwipjs.toCanvas(canvas, { bcid: 'pdf417', text: myText, binarytext: true, scaleX: 3, scaleY: 2, columns: 7, eclevel: 4, parsefnc: true

where "myText" is always of this form: "^ECI000017" + valueString.

Unfortunatly nothing have changed. Same problems: world 'Schaumbërg' is read as 'Schaumbërg' and euro symbl is read as 'â ¬'

fradev1988 avatar Oct 13 '23 05:10 fradev1988

What version of bwip-js are you using? binarytext is a very new option, only available in 4.1+.

Also, please provide the output from this code for a failing myText string:

console.log(myText.replace(/[\x80-\xff]/g, ($) => {
  let cd = $.charCodeAt(0);
  if (cd < 128) {
      return $;
  } else {
    return '\\x' + cd.toString(16);
  }
}));

I need the output for my testing and to verify the 8859 encoding.

metafloor avatar Oct 13 '23 17:10 metafloor

Hi @metafloor, we used last version of 3.x. I just udated to 4.1.1 but we have a problem with the toCanvas method. Just to clarify we are developing in angular 14, using node.js and typescript. After the update we are no more able to find the toCanvas method inside bwipjs module.

"Property 'toCanvas' does not exist on type 'typeof BwipJs'."

fradev1988 avatar Oct 16 '23 14:10 fradev1988

Likely pulling in the node-js package. Does angular support the exports map in package.json?

metafloor avatar Oct 16 '23 17:10 metafloor

finally we were able to work with the version 4.1.1. adding binarytext to true we receive the following error: "Error: bwip-js: 16-bit chars not allowed with binarytext"

without we have as output from your console.log this: ^ECI00001710 13 Schaumb\xebrg-von-und-zu-Schaumburg-und-Rad\xebberg Fri\xebdrich-Wilhelm-Karl-Gustav-Justus-Gotfried 19510712 20341231 101308719 LKK Schlesw-Holst. und H 38 H030170228 1 00 02 398212400 776299002 20210704 Prof. habil. Dr. med Grossherzog von und zu der 53639 K\xf6nigswinter Pfaffenschlag bei Waidhofen an der Thaya Allee 155155133 D 20210704 1234 2 1 06151/1111111 J09 G, G00.0 V kBB €-Zeichensatztest Y/9/2107/36/001

fradev1988 avatar Oct 26 '23 18:10 fradev1988

If you look closely at the console output, you will see a euro character in €-Zeichensatztest. That is probably a utf-16 codepoint.

metafloor avatar Oct 26 '23 19:10 metafloor

Sure I can see the euro character =)

But that was the output before to pass the string inside the toCanvas method.

If we have a text without euro symbol (using binarytext = true) we don't have problem with any characters and also umlaut chars are displayed correctly in the barcode. (So this fix the first problem that we have). But, if we use a text that has a euro symbol with binarytext = true the ToCanvas method return an error at this point inside the library:

if (opts.binarytext) {
        // THE TEXT DOESN T PASS THIS .test
        if (/[\u0100-\uffff]/.test(text)) {                
            throw new Error('bwip-js: 16-bit chars not allowed with binarytext');  
        }
    } else if (/[\u0080-\uffff]/.test(text)) {
        text = unescape(encodeURIComponent(text));
    }

we tried to pass the text preprocessing it with a library that convert it to iso-8859-15, or pass it in utf-8 but in both ways we have the same error with euro symbol.

fradev1988 avatar Oct 27 '23 08:10 fradev1988

Moreover, if I was able to partially understand the code, if no 16-bit chars are allowed with binarytext option I think there is a problem with € symbol in any case. Is it right?

fradev1988 avatar Oct 27 '23 10:10 fradev1988

The issue is that you are not passing in a iso-8859-15 encoded string. The euro symbol is being passed in as unicode U+20AC. You need to convert it to \xa4 per iso-8859-15.

metafloor avatar Oct 27 '23 14:10 metafloor

Ok I understand the situation.

We investigate a little bit and it seems that both the libraries that we tried to convert to iso 8859-15 effectively convert the euro as uncode U+20AC mainwhile all the other symbols in the form \x'something'.

I think there is all.

Thanks a lot for your support and really really thanks for your time!

fradev1988 avatar Oct 30 '23 08:10 fradev1988