Unicode C Requires Chilkat v11.7.0+
Unicode C
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 Unicode C Downloads
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkFormatsW.h>
void ChilkatSample(void)
{
BOOL success;
HCkStringBuilderW sbCard;
HCkJsonObjectW json;
HCkFormatsW fmt;
HCkJsonObjectW jsonOut;
success = FALSE;
// 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.
sbCard = CkStringBuilderW_Create();
CkStringBuilderW_AppendLine(sbCard,L"BEGIN:VCARD",TRUE);
CkStringBuilderW_AppendLine(sbCard,L"VERSION:3.0",TRUE);
CkStringBuilderW_AppendLine(sbCard,L"N:Smith;Alex;;;",TRUE);
CkStringBuilderW_AppendLine(sbCard,L"FN:Alex Smith",TRUE);
CkStringBuilderW_AppendLine(sbCard,L"ORG:Example Company",TRUE);
CkStringBuilderW_AppendLine(sbCard,L"TITLE:Sales Manager",TRUE);
CkStringBuilderW_AppendLine(sbCard,L"TEL;TYPE=CELL:+1-555-0100",TRUE);
CkStringBuilderW_AppendLine(sbCard,L"EMAIL:alex.smith@example.com",TRUE);
CkStringBuilderW_AppendLine(sbCard,L"URL:https://www.example.com",TRUE);
CkStringBuilderW_AppendLine(sbCard,L"END:VCARD",TRUE);
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateSb(json,L"payload.text",sbCard);
CkJsonObjectW_UpdateInt(json,L"render.moduleSize",6);
CkJsonObjectW_UpdateString(json,L"output.path",L"qa_output/qr_vcard.png");
CkJsonObjectW_UpdateBool(json,L"output.overwrite",TRUE);
CkJsonObjectW_UpdateString(json,L"output.return",L"none");
fmt = CkFormatsW_Create();
jsonOut = CkJsonObjectW_Create();
success = CkFormatsW_QrCode(fmt,L"generate",json,jsonOut);
if (success == FALSE) {
wprintf(L"%s\n",CkFormatsW_lastErrorText(fmt));
CkStringBuilderW_Dispose(sbCard);
CkJsonObjectW_Dispose(json);
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(jsonOut);
return;
}
wprintf(L"vCard length: %d\n",CkStringBuilderW_getLength(sbCard));
wprintf(L"QR version: %d\n",CkJsonObjectW_IntOf(jsonOut,L"symbols[0].selectedEncoding.version"));
wprintf(L"modules: %d x %d\n",CkJsonObjectW_IntOf(jsonOut,L"symbols[0].dimensions.modulesWide"),CkJsonObjectW_IntOf(jsonOut,L"symbols[0].dimensions.modulesHigh"));
wprintf(L"image: %d x %d pixels\n",CkJsonObjectW_IntOf(jsonOut,L"outputs[0].width"),CkJsonObjectW_IntOf(jsonOut,L"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
CkStringBuilderW_Dispose(sbCard);
CkJsonObjectW_Dispose(json);
CkFormatsW_Dispose(fmt);
CkJsonObjectW_Dispose(jsonOut);
}