Generate Barcode in C# – Add Barcode to Documents and Images

Barcode is a way to present the data in a machine-readable format. Barcodes are normally used for the quick identification of a large number of items. In this article, you will learn how to generate barcodes within .NET applications. Further, you will see, how the generated barcodes can be applied to any of your documents and images using C#.

The following topics are covered below:

.NET API for Generating Barcodes

GroupDocs.Signature has the .NET API that allows you to sign your documents, images, or files of different file formats. Using this API, you can easily apply different types of signatures like QR Codes, barcodes, text, image, metadata, digital signatures, stamps, electronic signatures. Further, you can customize the appearance of the signature in many ways.

You can download the DLLs or MSI installer from the downloads section or install the API for your .NET application via NuGet. You may also use the following command from the Package Manager.

PM> Install-Package GroupDocs.Signature

Barcodes for Documents and Images using C#

Barcodes can be programmatically generated with the customized text, appearance, and different encoding types. Some of the supported barcode types include Code 32, Code 128, DotCode, GS1, ISBN, PDF417, Pharmacode, Postnet, UPCA, and many more. These barcodes can be applied to a large list of supported document and image formats.

The following are the main step to apply barcodes on any document or image.

  • Load the document or image.
  • Generate the barcode along with text, appearance, encoding and other properties.
  • Apply it on the loaded file.
Generate Barcode in C#

Generate Barcode & Apply to Documents in C#

The following are the step to generate barcodes and apply these to any document. Whether the target documents are an MS Word document, PDF file, Excel Spreadsheet, or Presentation, the steps to add barcode would be the same for all the different formats.

  • Load the document (PDF, Word Doc, Spreadsheet, PPT, …) using Signature class.
  • Setup barcode options using BarcodeSignOptions class.
  • Set barcode properties like encoding type, position, size, etc.
  • Call the Sign method to apply barcode and sign the loaded document.

The following source code generates a barcode and attaches it to a PDF document using C#.

Generate Barcode & Apply to Images in C#

Similarly, the way to apply barcodes on images is not different. Just load the right image, the rest of the steps and code will remain the same as used for applying barcodes to the documents above.

The following are the step to generate barcodes and apply these to any image.

  • Load the image (JPG, PNG, WebP, …) using Signature.
  • Prepare barcode options using BarcodeSignOptions.
  • Customize the barcode by setting text, encoding type, position, size, appearance, etc.
  • Apply barcode to sign the image using Sign method.

The following source code generates a barcode and attaches it to a JPG image using C#.

Get a Free API License

You can get a free temporary license in order to use the API without the evaluation limitations.

Conclusion

To conclude, you learned how to generate the barcode in C#. Further, you have seen how to add these generated barcodes to your images and documents. Now you can develop your own barcode generator .NET application.

You can learn more about the .NET Signature API using the documentation, or by examples available on GitHub. Get in touch with us at the forum.

See Also