GithubHelp home page GithubHelp logo

Comments (11)

metafloor avatar metafloor commented on May 27, 2024

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

from bwip-js.

fradev1988 avatar fradev1988 commented on May 27, 2024

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 'â ¬'

from bwip-js.

metafloor avatar metafloor commented on May 27, 2024

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.

from bwip-js.

fradev1988 avatar fradev1988 commented on May 27, 2024

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'."

from bwip-js.

metafloor avatar metafloor commented on May 27, 2024

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

from bwip-js.

fradev1988 avatar fradev1988 commented on May 27, 2024

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

from bwip-js.

metafloor avatar metafloor commented on May 27, 2024

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

from bwip-js.

fradev1988 avatar fradev1988 commented on May 27, 2024

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.

from bwip-js.

fradev1988 avatar fradev1988 commented on May 27, 2024

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?

from bwip-js.

metafloor avatar metafloor commented on May 27, 2024

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.

from bwip-js.

fradev1988 avatar fradev1988 commented on May 27, 2024

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!

from bwip-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.