Node.js Requires Chilkat v11.7.0+
Node.js
QR Code with Binary Data
See more QR Code Examples
Demonstrates a QR code that holds arbitrary bytes rather than text. The payload type is binary and the bytes are given as base64 in payload.base64. Any byte value may be used, including zero. Keep in mind that many phone camera apps expect text, so binary payloads are for readers that you control.Chilkat Node.js Downloads
NODEJS_PRELUDE
function chilkatExample() {
var success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The bytes to encode. Here they come from hex, but they could be loaded from a file with LoadFile.
var bd = new chilkat.BinData();
success = bd.AppendEncoded("000102030405FF00FE4368696C6B6174","hex");
if (success == false) {
console.log(bd.LastErrorText);
return;
}
var json = new chilkat.JsonObject();
json.UpdateString("payload.type","binary");
json.UpdateString("payload.base64",bd.GetEncoded("base64"));
json.UpdateString("output.path","qa_output/qr_binary.png");
json.UpdateBool("output.overwrite",true);
json.UpdateString("output.return","none");
var fmt = new chilkat.Formats();
var jsonOut = new chilkat.JsonObject();
success = fmt.QrCode("generate",json,jsonOut);
if (success == false) {
console.log(fmt.LastErrorText);
return;
}
console.log("bytes given: " + bd.NumBytes);
console.log("bytes encoded: " + jsonOut.IntOf("symbols[0].payloadBytes"));
console.log("mode: " + jsonOut.StringOf("symbols[0].selectedEncoding.mode"));
console.log("QR version: " + jsonOut.IntOf("symbols[0].selectedEncoding.version"));
// The image written to qa_output/qr_binary.png:
//
// Sample output:
// bytes given: 16
// bytes encoded: 16
// mode: byte
// QR version: 2
}
chilkatExample();