Search code examples
qr-codelistlabel

Printing UTF-8 QR-Codes shows special characters for Umlauts


I am trying to use List & Label in my C# application to output a QR code in UTF-8 encoding. This is exactly what my customer needs.

Unfortunately, the customer's scanner only displays special characters. I can't find an option to set the charset for output. LL_OPTION_SAVE_PROJECT_IN_UTF8 seems to have no effect. I also tried to set LL_OPTION_CODEPAGE to no avail.

How can the QR code be output as UTF-8?


Solution

  • The QR code itself has no fixed encoding. You may try to set the ECI using

    LL.Core.LlXSetParameter(LlExtensionType.Barcode, "QRCode", "ECI", "0000026");
    

    Depending on the scanner type this might help or not. In order to make sure to UTF-8 encode the contents you should pass them byte-by-byte - this circumvents any problems between the passing and rendering. A designer extension function that handles this job would be wired up like this:

    Designer Function

    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 for your barcode's content and your should be fine.