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

QR Code with Non-English Text (UTF-8 and ECI)

See more QR Code Examples

Demonstrates text outside ASCII. QrCode always stores text as UTF-8 bytes, which is what phones expect. A QR code can also say so explicitly with an ECI header: setting encoding.eci to 26 declares the bytes to be UTF-8, for readers that would otherwise assume another character set. The header costs a little space, and a few older readers do not understand it, so it is off by default.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkFormatsW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkStringBuilderW sbText;
    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 text is "Gruesse aus Muenchen" written with u-umlaut and sharp s.  It is given here with
    //  JSON escapes only so that this source is plain ASCII.  Decode turns the escapes into characters.
    sbText = CkStringBuilderW_Create();
    CkStringBuilderW_Append(sbText,L"Gr\u00fc\u00dfe aus M\u00fcnchen");
    CkStringBuilderW_Decode(sbText,L"json",L"utf-8");

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateSb(json,L"payload.text",sbText);
    CkJsonObjectW_UpdateString(json,L"output.path",L"qa_output/qr_utf8.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(sbText);
        CkJsonObjectW_Dispose(json);
        CkFormatsW_Dispose(fmt);
        CkJsonObjectW_Dispose(jsonOut);
        return;
    }

    //  17 characters, three of which take two bytes in UTF-8.
    wprintf(L"characters: %d\n",CkStringBuilderW_getLength(sbText));
    wprintf(L"bytes encoded: %d\n",CkJsonObjectW_IntOf(jsonOut,L"symbols[0].payloadBytes"));
    wprintf(L"ECI header: %d\n",CkJsonObjectW_HasMember(jsonOut,L"symbols[0].selectedEncoding.eci"));

    //  Without an ECI header (qa_output/qr_utf8.png):

    //  image

    //  The same text with an ECI header declaring UTF-8.
    CkJsonObjectW_UpdateInt(json,L"encoding.eci",26);
    CkJsonObjectW_UpdateString(json,L"output.path",L"qa_output/qr_utf8_eci.png");
    success = CkFormatsW_QrCode(fmt,L"generate",json,jsonOut);
    if (success == FALSE) {
        wprintf(L"%s\n",CkFormatsW_lastErrorText(fmt));
        CkStringBuilderW_Dispose(sbText);
        CkJsonObjectW_Dispose(json);
        CkFormatsW_Dispose(fmt);
        CkJsonObjectW_Dispose(jsonOut);
        return;
    }

    wprintf(L"with encoding.eci = 26, ECI header: %d, value %d\n",CkJsonObjectW_HasMember(jsonOut,L"symbols[0].selectedEncoding.eci"),CkJsonObjectW_IntOf(jsonOut,L"symbols[0].selectedEncoding.eci"));

    //  With the ECI header (qa_output/qr_utf8_eci.png).  Both scan as the same text:

    //  image

    //  Sample output:

    //  characters: 17
    //  bytes encoded: 20
    //  ECI header: False
    //  with encoding.eci = 26, ECI header: True, value 26


    CkStringBuilderW_Dispose(sbText);
    CkJsonObjectW_Dispose(json);
    CkFormatsW_Dispose(fmt);
    CkJsonObjectW_Dispose(jsonOut);

    }