Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.7.0+

QR Code with Non-English Text (UTF-8 and ECI)

See more QR Code Examples

Demonstrates text outside ASCII. QrCode always stores text as UTF-8 bytes, which is what phones expect. A QR code can also say so explicitly with an ECI header: setting encoding.eci to 26 declares the bytes to be UTF-8, for readers that would otherwise assume another character set. The header costs a little space, and a few older readers do not understand it, so it is off by default.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

// The text is "Gruesse aus Muenchen" written with u-umlaut and sharp s.  It is given here with
// JSON escapes only so that this source is plain ASCII.  Decode turns the escapes into characters.
let sb_text = chilkat::StringBuilder::new();
let _ = sb_text.append("Gr\u{00fc}\u{00df}e aus M\u{00fc}nchen");
let _ = sb_text.decode("json", "utf-8");

let json = chilkat::JsonObject::new();
let _ = json.update_sb("payload.text", &sb_text);
let _ = json.update_string("output.path", "qa_output/qr_utf8.png");
let _ = json.update_bool("output.overwrite", true);
let _ = json.update_string("output.return", "none");

let fmt = chilkat::Formats::new();
let json_out = chilkat::JsonObject::new();
if fmt.qr_code("generate", &json, &json_out).is_err() {
    println!("{}", fmt.last_error_text());
    return;
}

// 17 characters, three of which take two bytes in UTF-8.
println!("characters: {}", sb_text.length());
println!("bytes encoded: {}", json_out.int_of("symbols[0].payloadBytes"));
println!("ECI header: {}", json_out.has_member("symbols[0].selectedEncoding.eci"));

// Without an ECI header (qa_output/qr_utf8.png):

// image

// The same text with an ECI header declaring UTF-8.
let _ = json.update_int("encoding.eci", 26);
let _ = json.update_string("output.path", "qa_output/qr_utf8_eci.png");
if fmt.qr_code("generate", &json, &json_out).is_err() {
    println!("{}", fmt.last_error_text());
    return;
}

println!("with encoding.eci = 26, ECI header: {}, value {}", json_out.has_member("symbols[0].selectedEncoding.eci"), json_out.int_of("symbols[0].selectedEncoding.eci"));

// With the ECI header (qa_output/qr_utf8_eci.png).  Both scan as the same text:

// image

// Sample output:

// characters: 17
// bytes encoded: 20
// ECI header: False
// with encoding.eci = 26, ECI header: True, value 26