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

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 Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  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.
set sbCard [new_CkStringBuilder]

CkStringBuilder_AppendLine $sbCard "BEGIN:VCARD" 1
CkStringBuilder_AppendLine $sbCard "VERSION:3.0" 1
CkStringBuilder_AppendLine $sbCard "N:Smith;Alex;;;" 1
CkStringBuilder_AppendLine $sbCard "FN:Alex Smith" 1
CkStringBuilder_AppendLine $sbCard "ORG:Example Company" 1
CkStringBuilder_AppendLine $sbCard "TITLE:Sales Manager" 1
CkStringBuilder_AppendLine $sbCard "TEL;TYPE=CELL:+1-555-0100" 1
CkStringBuilder_AppendLine $sbCard "EMAIL:alex.smith@example.com" 1
CkStringBuilder_AppendLine $sbCard "URL:https://www.example.com" 1
CkStringBuilder_AppendLine $sbCard "END:VCARD" 1

set json [new_CkJsonObject]

CkJsonObject_UpdateSb $json "payload.text" $sbCard
CkJsonObject_UpdateInt $json "render.moduleSize" 6
CkJsonObject_UpdateString $json "output.path" "qa_output/qr_vcard.png"
CkJsonObject_UpdateBool $json "output.overwrite" 1
CkJsonObject_UpdateString $json "output.return" "none"

set fmt [new_CkFormats]

set jsonOut [new_CkJsonObject]

set success [CkFormats_QrCode $fmt "generate" $json $jsonOut]
if {$success == 0} then {
    puts [CkFormats_lastErrorText $fmt]
    delete_CkStringBuilder $sbCard
    delete_CkJsonObject $json
    delete_CkFormats $fmt
    delete_CkJsonObject $jsonOut
    exit
}

puts "vCard length: [CkStringBuilder_get_Length $sbCard]"
puts "QR version: [CkJsonObject_IntOf $jsonOut {symbols[0].selectedEncoding.version}]"
puts "modules: [CkJsonObject_IntOf $jsonOut {symbols[0].dimensions.modulesWide}] x [CkJsonObject_IntOf $jsonOut {symbols[0].dimensions.modulesHigh}]"
puts "image: [CkJsonObject_IntOf $jsonOut {outputs[0].width}] x [CkJsonObject_IntOf $jsonOut {outputs[0].height}] pixels"

#  The image written to qa_output/qr_vcard.png:

#  image

#  Sample output:

#  vCard length: 197
#  QR version: 10
#  modules: 57 x 57
#  image: 390 x 390 pixels

delete_CkStringBuilder $sbCard
delete_CkJsonObject $json
delete_CkFormats $fmt
delete_CkJsonObject $jsonOut