Rust Requires Chilkat v11.7.0+
Rust
Create a vCard (Contact) QR Code
See more QR Code Examples
Demonstrates a QR code that adds a contact to a phone when scanned. The text is a vCard, the standard format for contact details: lines between BEGIN:VCARD and END:VCARD, each ending with CRLF. A vCard is fairly long, so the symbol is larger than one holding a web address. Leave out the fields that are not needed to keep it small.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The second argument of AppendLine is cktrue to end each line with CRLF.
let sb_card = chilkat::StringBuilder::new();
let _ = sb_card.append_line("BEGIN:VCARD", true);
let _ = sb_card.append_line("VERSION:3.0", true);
let _ = sb_card.append_line("N:Smith;Alex;;;", true);
let _ = sb_card.append_line("FN:Alex Smith", true);
let _ = sb_card.append_line("ORG:Example Company", true);
let _ = sb_card.append_line("TITLE:Sales Manager", true);
let _ = sb_card.append_line("TEL;TYPE=CELL:+1-555-0100", true);
let _ = sb_card.append_line("EMAIL:alex.smith@example.com", true);
let _ = sb_card.append_line("URL:https://www.example.com", true);
let _ = sb_card.append_line("END:VCARD", true);
let json = chilkat::JsonObject::new();
let _ = json.update_sb("payload.text", &sb_card);
let _ = json.update_int("render.moduleSize", 6);
let _ = json.update_string("output.path", "qa_output/qr_vcard.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;
}
println!("vCard length: {}", sb_card.length());
println!("QR version: {}", json_out.int_of("symbols[0].selectedEncoding.version"));
println!("modules: {} x {}", json_out.int_of("symbols[0].dimensions.modulesWide"), json_out.int_of("symbols[0].dimensions.modulesHigh"));
println!("image: {} x {} pixels", json_out.int_of("outputs[0].width"), json_out.int_of("outputs[0].height"));
// The image written to qa_output/qr_vcard.png:
//
// Sample output:
// vCard length: 197
// QR version: 10
// modules: 57 x 57
// image: 390 x 390 pixels