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

Generate a QR Code as SVG

See more QR Code Examples

Demonstrates SVG output. An SVG is a vector image, so it stays sharp at any size, which suits print and responsive web pages. Setting output.format to svg and output.return to text returns the SVG document as a string in outputs[0].text. The SVG can also be written straight to a file with output.path, the same as a PNG.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkJsonObjectW.h>
#include <CkFormatsW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    CkJsonObjectW json;
    json.UpdateString(L"payload.text",L"https://www.chilkatsoft.com/");
    json.UpdateString(L"output.format",L"svg");

    //  An SVG is text, so it can be returned as text rather than as base64.
    json.UpdateString(L"output.return",L"text");

    CkFormatsW fmt;
    CkJsonObjectW jsonOut;
    success = fmt.QrCode(L"generate",json,jsonOut);
    if (success == false) {
        wprintf(L"%s\n",fmt.lastErrorText());
        return;
    }

    CkStringBuilderW sbSvg;
    jsonOut.StringOfSb(L"outputs[0].text",sbSvg);

    wprintf(L"MIME type: %s\n",jsonOut.stringOf(L"outputs[0].mimeType"));
    wprintf(L"size: %d x %d %s\n",jsonOut.IntOf(L"outputs[0].width"),jsonOut.IntOf(L"outputs[0].height"),jsonOut.stringOf(L"outputs[0].units"));
    wprintf(L"SVG length: %d characters\n",sbSvg.get_Length());

    //  The SVG is a complete document that can be saved, or placed inline in an HTML page.
    success = sbSvg.WriteFile(L"qa_output/qr_chilkat.svg",L"utf-8",false);
    if (success == false) {
        wprintf(L"%s\n",sbSvg.lastErrorText());
        return;
    }

    //  The SVG:

    //  image

    //  Sample output:

    //  MIME type: image/svg+xml
    //  size: 148 x 148 px
    //  SVG length: 12500 characters
    }