Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Generate Barcode using UTF-8 in C#
// Create a barcode generator
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Pdf417);
// Set barcode text
generator.CodeText = "منحة";
// Set resolution
generator.Parameters.Resolution = 400;
// Set encoding type
generator.Parameters.Barcode.Pdf417.CodeTextEncoding = Encoding.UTF8;
// Generate barcode
Bitmap imgBarcode = generator.GenerateBarCodeImage();
// Save barcode image
// Recognize the above barcode
using (BarCodeReader reader = new BarCodeReader("generate-barcode.png"))
// Read barcodes
foreach (BarCodeResult result in reader.ReadBarCodes())
// Set encoding
Encoding unicode = Encoding.UTF8;
// Get the characters array from the bytes
char[] unicodeChars = new char[unicode.GetCharCount(result.CodeBytes, 0, result.CodeBytes.Length)];
unicode.GetChars(result.CodeBytes, 0, result.CodeBytes.Length, unicodeChars, 0);
// Build unicode string
string strCodeText = new string(unicodeChars);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment