+1 800 256 3608 (toll-free in North America) or +49 7531 90 60 10| service@combit.com

Encoding UTF-8 characters in a QR Code

barcodes
(combit Team) #1

The QR code itself has no fixed encoding. In order to make sure to UTF-8 encode the contents you should pass them byte-by-byte - this circumvents any problems between passing the content, rendering it as QR code and scanning it. A designer extension function that handles this job would be wired up like this:

image

The evaluation code would read:

private void designerFunction1_EvaluateFunction(object sender, EvaluateFunctionEventArgs e)
{
    string input = e.Parameter1.ToString();

    var utf8 = Encoding.UTF8;
    byte[] utfBytes = utf8.GetBytes(input);
    StringBuilder barcodeContent = new StringBuilder();
    foreach (byte b in utfBytes)
    {
        barcodeContent.AppendFormat("~d{0:000}", b);
    }
    e.ResultValue = barcodeContent.ToString();
    e.ResultType = LlParamType.String;
}

Then use EncodeAsUTF8(<actual content>) for your barcode’s content. The same procedure would work for the DataMatrix barcode as well.