Search code examples
c#utf-8itextdatamatrix

itext DataMatrix barcode with UTF-8 chars


What properties need to be set on an itextsharp Data-Matrix barcode to enable me to pass UTF-8 chars into the content?

var matrix = new BarcodeDatamatrix();
iTextSharp.text.Image img = null;

//matrix.Options = BarcodeDatamatrix.DM_ASCII;
matrix.Options = BarcodeDatamatrix.DM_AUTO;
//matrix.Options = BarcodeDatamatrix.DM_B256;
//matrix.Options = BarcodeDatamatrix.DM_TEXT;

matrix.Generate("!\"#$%&\'()*+,-./:;< => ?@[\\]^_`{|}~¡¢£¤¥¦§¨©ª«¬ ®¯°±²³´µ¶·¸¹º»¼½¾¿0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ");

img = matrix.CreateImage();

This c# code creates the barcode, but the contents are invalid. I've tried the other listed matrix.Options too.


Solution

  • The problem was with the scanner I was using and not the code.

    @AlexeySubach posted an example of an online scanner that works. I was using a scanner on Android that did not work.

    In the end I have switched apps to Barcode Scanner by Zxing and this is now working well.

    (I have no affiliation to this app nor the developers)