I am using http://davidshimjs.github.io/qrcodejs/ to generate a QR Code for an event, but when I try to make code from a string shown below I get this error Error: code length overflow. (1716>1056). I found out that when I change correctLevel : QRCode.CorrectLevel.H
to the medium it works. It also works when I remove DESCRIPTION or some other part of the string.
Can you explain to me how the limits work, and how should I set so when the code is generated from the user's input (it can have really long description) it won't crash?
qrkod(){
this.qrCodeText = "BEGIN:VCALENDAR"+"%0D%0A"+
"VERSION:1.0"+"%0D%0A"+
"BEGIN:VEVENT"+"%0D%0A"+
"DTSTART:" + "19960401T090000" +"%0D%0A"+
"DTEND:" + "19960401T043000" +"%0D%0A"+
"SUMMARY:" + "Your Proposal Review"+"%0D%0A"+
"DESCRIPTION:" + "Steve and John to review newest proposal material"+"%0D%0A"+
"END:VEVENT"+"%0D%0A"+
"END:VCALENDAR"+"%0D%0A";
this.qrCodeText = decodeURIComponent(this.qrCodeText);
this.qrcode0 = new QRCode("qrcode", {
text: this.qrCodeText,
width: 363,
height: 385,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
}
I have hit this same error myself using the library, it appears there is a bug in the library where if you use CorrectLevel.H and have a string between 192 and 220 character it will fail (Note that the length specified in the error message is not the same as the length of the string). It doesn't allocate the correct number of space/blocks for the QR code and then catches that error.
This can be resolved by either increasing/decreasing the string length to be outside of that range.
As sugested by Archit Jain in a comment on the previous answer, doing this fixed my problem:
qrCodeText = qrCodeText.padEnd(220);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With