Generate and Read Mailmark 4-State Barcodes in C#

Overview

The Mailmark 4-state postal symbology has been introduced by Royal Mail of the United Kingdom to encode information about postal and shipping operations. It has a specification similar to the RM4SCC standard but implies using a strictly fixed data format and does not provide extra space for customer-specific information. The Mailmark 4-state barcode type allows encoding numerical digits, uppercase English letters, and space. Moreover, Mailmark 4-state barcodes include a checksum and specific information for Reed-Solomon error correction.

The Royal Mail Mailmark 4-state enables the following barcode types:

  • Type L - encodes 26 characters and is intended for machine-readable Low Sort and Unsorted Retail and Access 70 services
  • Type C - encodes 22 characters and is intended for consolidated machine-readable Low Sort and Unsorted Retail and Access 70 services

Aspose.BarCode for .NET defines class MailmarkCodetext to work with this symbology.

Generate Mailmark 4-State Barcode

To generate a Mailmark 4-state barcode in Aspose.BarCode for .NET, first, it is necessary to create an instance of class MailmarkCodetext and enter the information to be encoded. Then, class ComplexBarcodeGenerator is used to complete barcode generation.

The following code snippet explains how to generate Mailmark 4-state barcodes.

//create Mailmark 4-State Barcode
MailmarkCodetext mailmarkCode = new MailmarkCodetext();
mailmarkCode.Format = 4;
mailmarkCode.VersionID = 1;
mailmarkCode.Class = "0";
mailmarkCode.SupplychainID = 384224;
mailmarkCode.ItemID = 16563762;
mailmarkCode.DestinationPostCodePlusDPS = "EF61AH8T ";

//encode Mailmark 4-State Barcode
ComplexBarcodeGenerator generator = new ComplexBarcodeGenerator(mailmarkCode);
generator.Parameters.Barcode.XDimension.Pixels = 4;
generator.Save($"{path}Mailmark4State.png");

Read Mailmark 4-State Barcode

To read and parse Royal Mail Mailmark 4-state barcodes in Aspose.BarCode for .NET, it is necessary to create an instance of class BarCodeReader and set it to the value DecodeType.Mailmark. After that, the fetched data must be parsed further using class ComplexCodetextReader by calling the TryDecodeMailmark method that returns an instance of MailmarkCodetext with the decoded barcode contents.

The following code snippet is given to demonstrate how to read Mailmark 4-state barcodes.

// Initialize a BarCodeReader instance to read Mailmark barcodes
using (var reader = new BarCodeReader("Mailmark4State.png", DecodeType.Mailmark))
{
    // Read and recognize all barcodes present in the image
    var recognized = reader.ReadBarCodes();

    // Decode the CodeText into a MailmarkCodetext object representing the 4-state Royal Mailmark data
    MailmarkCodetext result = ComplexCodetextReader.TryDecodeMailmark(recognized[0].CodeText);
}