Sample code for 30+ languages & platforms
Xbase++ 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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oSbCard
LOCAL oJson
LOCAL oFmt
LOCAL oJsonOut

nSuccess := 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.
oSbCard := CreateObject("Chilkat.StringBuilder")
oSbCard:AppendLine("BEGIN:VCARD", 1)
oSbCard:AppendLine("VERSION:3.0", 1)
oSbCard:AppendLine("N:Smith;Alex;;;", 1)
oSbCard:AppendLine("FN:Alex Smith", 1)
oSbCard:AppendLine("ORG:Example Company", 1)
oSbCard:AppendLine("TITLE:Sales Manager", 1)
oSbCard:AppendLine("TEL;TYPE=CELL:+1-555-0100", 1)
oSbCard:AppendLine("EMAIL:alex.smith@example.com", 1)
oSbCard:AppendLine("URL:https://www.example.com", 1)
oSbCard:AppendLine("END:VCARD", 1)

oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateSb("payload.text", oSbCard)
oJson:UpdateInt("render.moduleSize", 6)
oJson:UpdateString("output.path", "qa_output/qr_vcard.png")
oJson:UpdateBool("output.overwrite", 1)
oJson:UpdateString("output.return", "none")

oFmt := CreateObject("Chilkat.Formats")
oJsonOut := CreateObject("Chilkat.JsonObject")
nSuccess := oFmt:QrCode("generate", oJson, oJsonOut)
IF (nSuccess == 0)
    ? oFmt:LastErrorText
    oSbCard:destroy()
    oJson:destroy()
    oFmt:destroy()
    oJsonOut:destroy()
    RETURN
ENDIF

? "vCard length: " + Str(oSbCard:Length)
? "QR version: " + Str(oJsonOut:IntOf("symbols[0].selectedEncoding.version"))
? "modules: " + Str(oJsonOut:IntOf("symbols[0].dimensions.modulesWide")) + " x " + Str(oJsonOut:IntOf("symbols[0].dimensions.modulesHigh"))
? "image: " + Str(oJsonOut:IntOf("outputs[0].width")) + " x " + Str(oJsonOut:IntOf("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

oSbCard:destroy()
oJson:destroy()
oFmt:destroy()
oJsonOut:destroy()