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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vSbCard
    Handle hoSbCard
    Variant vJson
    Handle hoJson
    Handle hoFmt
    Variant vJsonOut
    Handle hoJsonOut
    String sTemp1
    Integer iTemp1
    Integer iTemp2

    Move False To iSuccess

    //  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.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbCard
    If (Not(IsComObjectCreated(hoSbCard))) Begin
        Send CreateComObject of hoSbCard
    End
    Get ComAppendLine Of hoSbCard "BEGIN:VCARD" True To iSuccess
    Get ComAppendLine Of hoSbCard "VERSION:3.0" True To iSuccess
    Get ComAppendLine Of hoSbCard "N:Smith;Alex;;;" True To iSuccess
    Get ComAppendLine Of hoSbCard "FN:Alex Smith" True To iSuccess
    Get ComAppendLine Of hoSbCard "ORG:Example Company" True To iSuccess
    Get ComAppendLine Of hoSbCard "TITLE:Sales Manager" True To iSuccess
    Get ComAppendLine Of hoSbCard "TEL;TYPE=CELL:+1-555-0100" True To iSuccess
    Get ComAppendLine Of hoSbCard "EMAIL:alex.smith@example.com" True To iSuccess
    Get ComAppendLine Of hoSbCard "URL:https://www.example.com" True To iSuccess
    Get ComAppendLine Of hoSbCard "END:VCARD" True To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get pvComObject of hoSbCard to vSbCard
    Get ComUpdateSb Of hoJson "payload.text" vSbCard To iSuccess
    Get ComUpdateInt Of hoJson "render.moduleSize" 6 To iSuccess
    Get ComUpdateString Of hoJson "output.path" "qa_output/qr_vcard.png" To iSuccess
    Get ComUpdateBool Of hoJson "output.overwrite" True To iSuccess
    Get ComUpdateString Of hoJson "output.return" "none" To iSuccess

    Get Create (RefClass(cComChilkatFormats)) To hoFmt
    If (Not(IsComObjectCreated(hoFmt))) Begin
        Send CreateComObject of hoFmt
    End
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
    If (Not(IsComObjectCreated(hoJsonOut))) Begin
        Send CreateComObject of hoJsonOut
    End
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoJsonOut to vJsonOut
    Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFmt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComLength Of hoSbCard To iTemp1
    Showln "vCard length: " iTemp1
    Get ComIntOf Of hoJsonOut "symbols[0].selectedEncoding.version" To iTemp1
    Showln "QR version: " iTemp1
    Get ComIntOf Of hoJsonOut "symbols[0].dimensions.modulesWide" To iTemp1
    Get ComIntOf Of hoJsonOut "symbols[0].dimensions.modulesHigh" To iTemp2
    Showln "modules: " iTemp1 " x " iTemp2
    Get ComIntOf Of hoJsonOut "outputs[0].width" To iTemp1
    Get ComIntOf Of hoJsonOut "outputs[0].height" To iTemp2
    Showln "image: " iTemp1 " x " iTemp2 " 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


End_Procedure