Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Barcodes have become an integral part of modern business operations, facilitating efficient inventory management, point-of-sale transactions, and data tracking. Among the various barcode symbologies, Code 39 stands out as one of the most widely used and versatile options.
A checksum digit, also known as a check digit or validation digit, is a digit added to a sequence of numbers (or alphanumeric characters) to help detect errors in the data. The purpose of the checksum digit is to ensure the integrity of the data by providing a simple method of error detection during data transmission or processing. One common application of a checksum digit is in barcodes, where it is often used to verify the accuracy of the scanned data. One of the barcode symbologies that uses a checksum digit is Code 39.
Code 39 encodes alphanumeric characters, including uppercase letters, numeric digits, and a few special characters. It includes a start character, an optional checksum character, and a stop character, making it self-checking to ensure accurate data capture. Also, human-readable text can be displayed below the generated barcode image.
IronBarcode (produced by Iron Software) is the leading .NET C# Barcode library for reading and creating barcodes. The User-friendly API allows developers to add barcode functionality to .NET applications in minutes. Developers can generate a Code 39 barcoding project and barcoding test in minutes using this library.
In this article, we'll explore the process of building a Code 39 barcode generator using IronBarcode.
Create a new C# console application or use an existing project where you want to generate new barcode images. This library can also be used on a .NET Windows forms application. For the sake of this tutorial, let's consider a console application.
Select the console application template and click next.
In The Next Step, you can provide the solution and project names.
Select the .NET Version and click "Create".
IronBarcode can be installed from the NuGet Package Manager.
It can also be installed from the Visual Studio package manager. Search for IronBarcode in Package Manager and click install.
Now, let's write the code to generate Code 39 barcodes using the IronBarcode library. Below is a simple example:
// sample code
using IronBarCode;
Console.WriteLine("Code 39 Barcode Generator");
GeneratedBarcode code39Barcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code39); //c# class
code39Barcode.SaveAsImage("ironSoftwareBarcode.png"); // barcode image
// sample code
using IronBarCode;
Console.WriteLine("Code 39 Barcode Generator");
GeneratedBarcode code39Barcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code39); //c# class
code39Barcode.SaveAsImage("ironSoftwareBarcode.png"); // barcode image
' sample code
Imports IronBarCode
Console.WriteLine("Code 39 Barcode Generator")
Dim code39Barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code39) 'c# class
code39Barcode.SaveAsImage("ironSoftwareBarcode.png") ' barcode image
This simple program initializes a BarcodeWriter C# class, sets the encoding format to CODE_39, and generates a barcode PNG using the provided data. The barcode image is then saved as ironSoftwareBarcode.png.
Output:
Here we are using the BarcodeWriter class from the IronBarcode class library to create Code 39 barcodes with the URL data provided. Every time the code is run, a new barcode image is generated
Annotation text can be added to barcodes easily with IronBarcode. The BarcodeWriter (c# class) generates a barcode object. This generated barcode object has a Fluent API, which allows barcode text to be set in a single line of code, similar to Linq.
using IronBarCode;
// sample code
Console.WriteLine("Code 39 Barcode Generator");
GeneratedBarcode code39Barcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code39); //c# class
code39Barcode.AddAnnotationTextAboveBarcode("Product URL:");
code39Barcode.AddBarcodeValueTextBelowBarcode();
//human readable text of the barcode
code39Barcode.SaveAsImage("ironSoftwareBarcodeWithText.png"); // barcode image
using IronBarCode;
// sample code
Console.WriteLine("Code 39 Barcode Generator");
GeneratedBarcode code39Barcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code39); //c# class
code39Barcode.AddAnnotationTextAboveBarcode("Product URL:");
code39Barcode.AddBarcodeValueTextBelowBarcode();
//human readable text of the barcode
code39Barcode.SaveAsImage("ironSoftwareBarcodeWithText.png"); // barcode image
Imports IronBarCode
' sample code
Console.WriteLine("Code 39 Barcode Generator")
Dim code39Barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code39) 'c# class
code39Barcode.AddAnnotationTextAboveBarcode("Product URL:")
code39Barcode.AddBarcodeValueTextBelowBarcode()
'human readable text of the barcode
code39Barcode.SaveAsImage("ironSoftwareBarcodeWithText.png") ' barcode image
Output:
Here you can see the product URL human-readable text is added above the barcode and the value of the barcode in human-readable text is added below the barcode image.
IronBarcode allows the barcode and the human-readable text to be styled, usually styling barcodes includes resizing barcodes, setting margins, changing background colors, changing barcode colors, fonts and verifying that the output barcode is still readable. All these methods are available on the BarcodeWriter object. The width and height are set in pixels.
The BarcodeWriter object can also work with a Stream object as shown below. This is particularly helpful in web API applications to save memory. A graphics object can also take advantage of this.
IronBarcode. The key needs to be placed in appsettings.json.
{
"IronBarcode.LicenseKey":"MYLICENSE.KEY.TRIAL"
}
{
"IronBarcode.LicenseKey":"MYLICENSE.KEY.TRIAL"
}
If True Then
"IronBarcode.LicenseKey":"MYLICENSE.KEY.TRIAL"
End If
Provide user email to get a trial license. After submitting the email ID, the key will be delivered via email.
In this comprehensive guide, we have explored the process of building a Code 39 barcode generator using the C# programming language. Code 39 is versatile and widely used in barcode symbology, known for its simplicity and ability to encode alphanumeric characters. By leveraging the capabilities of the IronBarcode library, we have demonstrated a step-by-step approach to create a C# application capable of generating Code 39 barcodes with optional checksum digits.
As technology continues to advance, the importance of accurate and efficient data encoding and decoding becomes increasingly critical. Building a Code 39 barcode generator in C# not only provides a practical tool for businesses and developers but also serves as an educational exercise in understanding barcode symbologies, checksum algorithms, and the integration of third-party libraries in C# applications.
In conclusion, this guide equips developers with the knowledge and tools needed to create a robust Code 39 barcode generator, fostering the integration of reliable barcode solutions into their projects. Whether you are a seasoned developer or a newcomer to barcode generation, this article provides a solid foundation for further exploration and customization based on the specific requirements of your applications.
9 .NET API products for your office documents