Generate and Read Royal Mail Mailmark 2D Barcode using C#

Generate and Read Royal Mail Mailmark 2D Barcode using C#

The Royal Mail Mailmark 2D barcode is a machine-readable Complex Mail Data Mark (CMDM) barcode used in letters. It provides information about mail tracking and delivery status. It may also include additional information, such as the delivery schedule and reporting statistics. In this article, we will learn how to generate and read Royal Mail Mailmark 2D barcodes using C#.

The following topics shall be covered in this article:

C# API to Generate and Read Royal Mail Mailmark 2D Barcodes

For generating and reading Royal Mail Mailmark 2D barcodes, we will be using the Aspose.BarCode for .NET API. It allows generating and recognizing a wide range of 1D & 2D barcode types. Please either download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.BarCode

Generate Royal Mail Mailmark 2D Barcode using C#

There are three types of 2D Complex Mail Data Mark barcodes:

  • Type 7:
    • Letters
    • Barcode Size: 24 × 24 modules
    • Physical Size: 12 × 12 mm
    • Total Character Count: 51 Characters
    • Customer Use: 6 spare spaces
Mailmark2DType7
  • Type 9:
    • Large Letters, including poly wrap
      letters.
    • Barcode Size: 32 × 32 modules
    • Physical Size: 16 × 16 mm
    • Total Character Count: 90 Characters
    • Customer Use: >25 but max of 45 spare spaces
Mailmark2DType9
  • Type 29:
    • Large Letters, including poly wrap letters.
    • Barcode Size: 16 × 48 modules
    • Physical Size: 8 × 24 mm
    • Total Character Count: 70 Characters
    • Total Character Count: need 6-25 customer characters
Mailmark2DType29

We can generate Royal Mail Mailmark 2D barcode by following the steps given below:

  1. Firstly, create an instance of the Mailmark2DCodetext class.
  2. Next, set various properties such as UPUCountryID, VersionID, Class, ItemID, etc.
  3. Then, set Mailmark2DType as Type_7, Type_9, or Type_29.
  4. Next, create an instance of the ComplexBarcodeGenerator class with Mailmark2DCodetext object as an argument.
  5. After that, set the barcode dimensions.
  6. Finally, call the Save method to save the barcode image on the local disk.

The following code example demonstrates how to generate a Mailmark 2D barcode of type 7 using C#.

Read Royal Mail Mailmark 2D Barcode using C#

We can read Royal Mail Mailmark 2D barcode by following the steps given below:

  1. Firstly, create an instance of the BarCodeReader class.
  2. Next, provide the input barcode image path and the DecodeType.
  3. Then, get the BarCodeResult by calling the ReadBarCodes() method.
  4. After that, decode the barcode using the TryDecodeMailmark2D() method.
  5. Finally, read decoded properties of the Mailmark2DCodetext object.

The following code example demonstrates how to read a Mailmark 2D barcode using C#.

UPUCountryID:JGB
InformationTypeID:0
VersionID:1
Class:1
SupplyChainID:123
ItemID:1234
DestinationPostCodeAndDPS:QWE1
RTSFlag:0
ReturnToSenderPostCode:QWE2
CustomerContent:CUSTOM DATA

Get a Free License

You can get a free temporary license to try the library without evaluation limitations.

Conclusion

In this article, we have learned how to generate Royal Mail Mailmark 2D barcodes and save barcode images on the disk. We have also seen how to read the generated Mailmark 2D barcodes programmatically. Besides, you can learn more about Aspose.BarCode for .NET API using the documentation. In case of any ambiguity, please feel free to contact us on the forum.

See Also