Mailmark 2D Barcodes


The Royal Mail Mailmark symbology has been developed to encode postal and shipping information in the format defined in the DataMatrix standard. The Mailmark 2D symbology includes three types denoted as 7, 9, and 29; they differ from each other in terms of customer data capacity. Customer information is encoded in addition to the main barcode data in special predefined barcode fields. The amount of space to store customer data depends on the barcode type and the used encoding. This information can serve to describe print and scanning operations, identify items, or enable barcode scanning with smartphones.

To perform data encoding, the Mailmark 2D standard uses the basic C40 character set (numerical digits, uppercase English letters, and the space character). All fields of information to be encoded in a Mailmark 2D barcode except customer data must be entered in the format compatible with the mentioned encoding standard. The customer information field does not require to comply with this encoding; however, using alternative encodings may affect the overall barcode data capacity.

To work with Mailmark 2D barcodes in Aspose.BarCode for .NET, it is necessary to use class Mailmark2DCodetext.

How to Generate Mailmark 2D Barcode

To generate Mailmark 2D barcodes, Aspose.BarCode for .NET provides class Mailmark2DCodetext to specify barcode fields and class ComplexBarcodeGenerator to generate barcodes. The Mailmark2DType enumeration is used to select the type of a Mailmark 2D barcode to be generated.

Sample Mailmark 2D barcodes demonstrated below have been created setting different Mailmark 2D types.

Mailmark 2D

Type 7

Type 9

Type 29

The following code snippet illustrates how to generate Mailmark 2D barcodes of types 7, 9, and 29.

ComplexBarcodeGenerator generator = null;

//create Mailmark 2D Code
Mailmark2DCodetext mailmark2D = new Mailmark2DCodetext();
mailmark2D.UPUCountryID = "JGB ";
mailmark2D.InformationTypeID = "0";
mailmark2D.VersionID = "1";
mailmark2D.Class = "1";
mailmark2D.SupplyChainID = 123;
mailmark2D.ItemID = 1234;
mailmark2D.DestinationPostCodeAndDPS = "QWE1";
mailmark2D.RTSFlag = "0";
mailmark2D.ReturnToSenderPostCode = "QWE2";

//encode Mailmark 2D Type 7 Code
mailmark2D.DataMatrixType = Mailmark2DType.Type_7;
mailmark2D.CustomerContent = "CUSTOM";
generator = new ComplexBarcodeGenerator(mailmark2D);
generator.Parameters.Barcode.XDimension.Pixels = 4;

//encode Mailmark 2D Type 9 Code
mailmark2D.DataMatrixType = Mailmark2DType.Type_9;
mailmark2D.CustomerContent = "CUSTOM DATA";
generator = new ComplexBarcodeGenerator(mailmark2D);
generator.Parameters.Barcode.XDimension.Pixels = 4;

//encode Mailmark 2D Type 29 Code
mailmark2D.DataMatrixType = Mailmark2DType.Type_29;
mailmark2D.CustomerContent = "CUSTOM DATA";
generator = new ComplexBarcodeGenerator(mailmark2D);
generator.Parameters.Barcode.XDimension.Pixels = 4;

How to Read Mailmark 2D Barcode

To read and parse Royal Mail Mailmark 2D barcodes in Aspose.BarCode for .NET, first, it is required to create an instance of class BarCodeReader and set it to the value DecodeType.DataMatrix. Then, the obtained information can be parsed further in class ComplexCodetextReader by calling the TryDecodeMailmark2D method that returns an instance of Mailmark2DCodetext with the decoded barcode data.

The following code snippet explains how to read Mailmark 2D barcodes.

Console.OutputEncoding = Encoding.Unicode;
//recognize Mailmark 2D Code
BarCodeReader reader = new BarCodeReader($"{path}Mailmark2DType9.png", DecodeType.DataMatrix);
foreach (BarCodeResult result in reader.ReadBarCodes())
    Mailmark2DCodetext mailmarkResult = ComplexCodetextReader.TryDecodeMailmark2D(result.CodeText);
    if (null == mailmarkResult) continue;