JavaScript Requires Chilkat v11.7.0+
JavaScript
Generate a QR Code with the Barcode Method
See more QR Code Examples
Demonstrates the Barcode method, which is the general form of QrCode: the request names the symbology, and everything else is the same. QrCode is Barcode with the symbology already set to qr, and identical requests to the two methods give identical results. A program that will produce more than one kind of barcode can use Barcode for all of them.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var json = new CkJsonObject();
json.UpdateString("symbology","qr");
json.UpdateString("payload.text","https://www.chilkatsoft.com/");
json.UpdateString("output.path","qa_output/qr_from_barcode.png");
json.UpdateBool("output.overwrite",true);
json.UpdateString("output.return","none");
var fmt = new CkFormats();
var jsonOut = new CkJsonObject();
success = fmt.Barcode("generate",json,jsonOut);
if (success == false) {
console.log(fmt.LastErrorText);
return;
}
console.log("symbology: " + jsonOut.StringOf("symbols[0].symbology"));
console.log("QR version: " + jsonOut.IntOf("symbols[0].selectedEncoding.version"));
console.log("image: " + jsonOut.IntOf("outputs[0].width") + " x " + jsonOut.IntOf("outputs[0].height") + " pixels");
// The image written to qa_output/qr_from_barcode.png:
//
// Barcode requires the symbology. QrCode does not.
var json2 = new CkJsonObject();
json2.UpdateString("payload.text","https://www.chilkatsoft.com/");
success = fmt.Barcode("generate",json2,jsonOut);
if (success == false) {
console.log("without a symbology: " + jsonOut.StringOf("errors[0].code") + " at " + jsonOut.StringOf("errors[0].path"));
}
// Sample output:
// symbology: qr
// QR version: 3
// image: 148 x 148 pixels
// without a symbology: missingOption at /symbology