New User? Sign Up  |  Sign In  |  Help
Barcode support and
tutorials from IDAutomation
and the community.
Click for the BBB Business Review of this Computers Hardware, Software & Services in Tampa FL
Resolved Questions

Problems encoding UTF8 in Aztec Code (non-latin characters)


We are trying to encode UTF8 in the Aztec Barcode Type with the .NET Barcode Generator. We have this function:

[Function(IsVisible = true, Category = "ProLogis", Namespace = "BarcodeFunctions", Description = "GetAztec")]
public static string GetAztec(string data, int errorCorrectionLevel = 1, int numberOfSymbols = 1, decimal xDimensionCm = 0.03m)
{
try
{
if (string.IsNullOrEmpty(data)) return BitmapToBase64(new Bitmap(1, 1));
foreach (var chr in data)
if (chr > 255)
data = data.Replace(chr.ToString(), "~d" + (int)chr);

using AztecBarcode aztecCode = new AztecBarcode();
aztecCode.ErrorCorrectionLevel = errorCorrectionLevel;
aztecCode.NumberOfSymbols = numberOfSymbols;
aztecCode.DataToEncode = data;
aztecCode.ApplyTilde = true;
aztecCode.XDimensionCM = (float)xDimensionCm;
aztecCode.Resolution = IDAutomation.Windows.Forms.AztecBarcode.Resolutions.Custom;
aztecCode.ResolutionCustomDPI = 400;
return BitmapToBase64(aztecCode.BMPPicture);
}
catch (Exception e)
{
string message = $"Error creating Aztec as Image for value {data} Exception: {e.Message}";
throw new Exception(message);
}
}

We tried to build the same as here (previous version of the software):
[Function(IsVisible = true, Category = "ProLogis", Namespace = "BarcodeFunctions", Description = "GetAztec")]
public static string GetAztec(string data, int errorCorrectionLevel = 1, int numberOfSymbols = 1, decimal xDimensionCm = 0.03m)
{
try
{
if (string.IsNullOrEmpty(data)) return BitmapToBase64(new Bitmap(1, 1));
foreach (var chr in data)
if (chr > 255)
data = data.Replace(chr.ToString(), "~d" + (int)chr);

using AztecBarcode aztecCode = new AztecBarcode();
aztecCode.ErrorCorrectionLevel = errorCorrectionLevel;
aztecCode.NumberOfSymbols = numberOfSymbols;
aztecCode.DataToEncode = data;
aztecCode.ApplyTilde = true;
aztecCode.XDimensionCM = (float)xDimensionCm;
aztecCode.Resolution = IDAutomation.Windows.Forms.AztecBarcode.Resolutions.Custom;
aztecCode.ResolutionCustomDPI = 400;
return BitmapToBase64(aztecCode.BMPPicture);
}
catch (Exception e)
{
string message = $"Error creating Aztec as Image for value {data} Exception: {e.Message}";
throw new Exception(message);
}
}

Here is our test:
[DataRow("NonLatinCharacters", "日本語テスト Español Français", 10, 1, 0.03)]
public void Aztec(string testName, string testData, int errorCorectionLevel, int numberOfSymbols,
double xDimensionCm)
{
// Error Correction Levels: Aztec supports levels 1 (low) to 23 (max). Higher levels increase redundancy but reduce data capacity.
// numberOfSymbols: Typically 1 for most use cases. Use >1 for large datasets split across linked Aztec symbols.
// xDimensionCm: Must be ≥ 0.01 cm (practical minimum for scanners). Larger values improve readability but increase symbol size.
var decimalxDimensionCm = (decimal)xDimensionCm;
// todo: use apply tilde or not?? quietzone: TE thinks 0, but maybe 1 or 2? Testdata ok?
testName = $"{nameof(Aztec)}_{testName}_";
var originalData = BarcodeFunctions.GetAztec(testData, errorCorectionLevel, numberOfSymbols, decimalxDimensionCm);
File.WriteAllBytes($"{testName}Test.png", Convert.FromBase64String(originalData));
var data = NET.BarcodeFunctions.GetAztec(testData, errorCorectionLevel, numberOfSymbols, decimalxDimensionCm);
File.WriteAllBytes($"{testName}Test_NET.png", Convert.FromBase64String(data));
Assert.AreEqual(originalData, data);
}
Previous version output: ÿ85ÿ12ÿ86|86|73|88 Español Français

Newer version output: ÿ85ÿ12ÿ86|86|73|88 Español Français

We would like to have at least the old functionality: that the Español Français is displayed correctly.

Can you tell us what we need to change to achieve this?


04-17-25     18 day(s) ago    

  Report Abuse

 

Brant

Best Answer

Within the .NET Generator download, we used the Visual Studio example
"Aztec - BarcodeGenerationExample C#.NET - bin - Release - signed - BarcodeGenerationExample.exe"
for testing, and when this is used, the data scans correctly. I recommend doing a process of elimination, comparing your code to the code in the example application to find the solution. Most importantly, UTF-8 data needs to be encoded directly in the function of the barcode generator.

Posted 18 day(s) ago

(0)
(1)
  Report Abuse
 
Find Interesting
 
Email to Others
 
Bookmark
 
Subscribe to Answer Alert
No comments yet.     Be the first to comment.

Email this question link to friends
You must enter an email address, if name is entered or vice-versa for each friend.
Friend #1 -
Friend #2 -
Friend #3 -
Friend #4 -
Friend #5 -
  Your comment on this question
  |         |  
bold  italic  underline  strike       big  small       superscript  subscript 
  Allows to add a link. Added links would only be converted to actual clickable link, when the domain of the link is white-listed by administrator.
Caption :
Link URL :
(Must starts with "http://")
Add  |   Cancel
  Allow to insert an image. Must be among the following file types - *.jpg, *.gif, *.png & *.bmp.
Image Url :   Upload New
(Image url must always starts with " http:// ")
Width : pixels
(Must not be greater than 450px. Enter 0px for no resize)
Add  |   Cancel
  Allow to insert YouTube video. Insert the video embed code.
Embed Code :
Add  |   Cancel
Up to 5000 Characters are allowed. Current Count: 0
  Your comment on this answer
  |         |  
bold  italic  underline  strike       big  small       superscript  subscript 
  Allow you to add a link. Added links would only be converted to actual clickable link, when the domain of the link is white-listed by administrator.
Caption :
Link URL :
(Must start with "http://" or "https://")
Add  |   Cancel
  Allow to insert an image. Must be among the following file types - *.jpg, *.gif, *.png & *.bmp.
Image Url :   Upload New
(Image url must always start with "http://" or "https://")
Width : pixels
(Must not be greater than 450px. Enter 0px for no resize)
Add  |   Cancel
  Allow to insert YouTube video. Insert the video embed code.
Embed Code :
Add  |   Cancel
Up to 5000 characters are allowed. Current Count: 0

You may answer and comment on any thread according to the Terms and Conditions.

 © Copyright 2021 IDAutomation.com, Inc., All Rights Reserved. Legal Notices.

 Barcode Fonts | Components | Scanners | Support | Contact Us
Training Videos on YouTube Join us on Google Plus Join us on LinkedIn Follow us on Twitter Like us on Facebook