Generate and Read Royal Mail QR code using C#

The Royal Mail Mailmark 2D barcode is a machine-readable complex 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 the Royal Mail Mailmark 2D barcode using C#.

The following topics shall be covered in this article:

  1. C# API to Generate and Read Royal Mail QR Codes
  2. What is a Royal Barcode?
  3. Types of Royal Mail QR Codes
  4. Generate a Royal Mail QR Code
  5. Read the Royal Mail QR Code
  6. Free Learning Resources

C# API to Generate and Read Royal Mail QR Code

For generating and reading Royal Mail QR code, we will be using the Aspose.BarCode for .NET API. Using the API, we can generate and recognize a wide range of 1D and 2D barcode types.

Please either download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.BarCode

What is a Royal Barcode?

The Royal Mail barcode is a Complex Mail Data Mark (CMDM) barcode. It was developed by the UK Postal System to automate mail sorting and tracking. It has the specified format of a Data Matrix type ECC200 code, complying with the international standard. It is also called the Royal Mail 4-State Customer Code (RM4SCC).

Types of Royal Mail QR Codes

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 a maximum 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: We need 6–25 customer characters.
Mailmark2DType29

Generate Royal Mail Barcode Stamp in C#

We can generate a Royal Mail barcode stamp by following the steps below:

  1. Firstly, create an instance of the Mailmark2DCodetext class.
  2. Next, set various properties such as UPUCountryID, VersionID, Class, ItemID, etc.
  3. Then, specify the Mailmark2DType as Type_7, Type_9, or Type_29.
  4. Next, create an instance of the ComplexBarcodeGenerator class with the 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 QR Code using C#

We can read the Royal Mail QR code 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 the decoded properties of the Mailmark2DCodetext object.

The following code example demonstrates how to read a Mailmark QR code 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.

Mailmark 2D Barcode Library - Learning Resources

Besides generating and reading Royal Mail QR codes, you can learn more about various other features of Aspose.BarCode using the resources given below:

Conclusion

In this article, we have learned how to generate a Royal Mail QR code and save barcode images on the disk. We have also seen how to read the generated Mailmark 2D barcode 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 our free support forum.

See Also