We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Unpredictable "The codetext is too big" errors generating Datamatrix

I’m having unpredictable errors generating datamatrix barcodes in .NET.

About 10% of the time, I get the error. The error appears to be randome, and depends on the characters in the Guid.

Aspose.BarCode.InvalidCodeException: The codetext is too big. Max available length - 32 for this barcode size.

My codes are all similar. They are all the same size - 39 characters long.

Constant prefix ‘em1:’ (4 chars) + Guid (32 chars) + and page number ‘001’ (3 char).

This one FAILS - CodeText: ‘em1:a9db1d6e129c460f8cb0efd3927d5d70001’, length: 39

This one SUCCEEDS - CodeText: ‘em1:f331409d6fce405a99ab778bc6c63dff001’, length: 39

The attached file, from the datamatrix example shows the problem.

Question 1 - Why does one string succeed, but another sting of the same length fail?

Question 2 - Why does the error say the max length is 32 when it usually succeeds with the 39 character string?

Question 3 - How do I fix this? I must match the output from an older barcode system based on iTextSharp. The older system has NO PROBLEM generating these barcodes.

CreateDatamatrixBarcode.zip (1.1 KB)

We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

BARCODENET-37493 – Unpredictable “The codetext is too big” errors generating Datamatrix


This error message indeed can be confusing. “Max available length - 32” - 32 in this message refers to encoded codewords, not to original string length. The first string encodes into 25 codewords. The second one encodes into 33 codewords (cause it contains more letters and so compressed less).

If you need to get rectangular DataMatrix you can set bigger Rows and Columns settings:

    generator.Parameters.Barcode.DataMatrix.Columns = 48;
    generator.Parameters.Barcode.DataMatrix.Rows = 16;

or alternatively you can use better encoding mode that compresses your input string into less than 33 codewords, e.g.:

    generator.Parameters.Barcode.DataMatrix.Columns = 36;
    generator.Parameters.Barcode.DataMatrix.Rows = 16;
    generator.Parameters.Barcode.DataMatrix.DataMatrixEncodeMode = DataMatrixEncodeMode.Text;