C# Code 39 Generator Library SDK

Integration & Developer Guide for Code 39 linear barcode image generation in C#

Generate barcode Code 39 images in Visual C# .NET with complete sample C# source code


In this C# tutorial, you will learn how to generate Code 39 barcode images in .NET Windows and ASP.NET applications using C#.

  • Fully support ISO/IEC 16388 standard
  • Easy to encode characters with Code 39 standard mode or full ASCII mode
  • Encode and draw high dpi Code 39 image on specific area for printing
  • Easy to enable Code 39 generation in ASP.NET Core, MVC, WinForms, WPF, web service.
  • Support .NET 10, 9, 8, 7, 6, 5, .NET Core 3.1, 2.1, and .NET Framework 4.x, 3.x, 2.x

How to create Code 39 barcodes in ASP.NET and Windows using C#

  1. Download .NET Code 39 Barcode Generator Suite
  2. Install C# library to create Code 39 barcodes in .NET projects
  3. Step by Step Tutorial










Code 39, also known as Alpha39, Code 3 of 9, Code 3/9, Type 39, USS Code 39, or USD-3, is the first alpha-numeric linear barcode symbology used world-wide.

C# Code 39 Generator is one of the linear barcodes generation in OnBarcode's C# Barcode Generation Controls, which generates & prints Code 39, Code 39 extension and other linear & 2D bar codes in C#.NET applications.



Quick to Create Code 39 Barcode Image in C#

Top
Using C# Barcode Generator library, you can easily generate Code 39 barcode image in your ASP.NET Core & Framework, MVC, WinForms, WPF .NET web and desktop applications.

Linear barcode = new Linear();
barcode.Data = "CODE-39";
barcode.Type = BarcodeType.CODE39;
barcode.drawBarcode("C://Output//barcode-code39-sample.png");


In the previous C# sample code, you will create a Code 39 barcode image file.
  • Create a Linear object with barcode data encode
  • Choose the barcode format as "BarcodeType.CODE39"
  • Call drawBarcode() method to create and print the Code 39 barcode to a PNG image file.




Code 39 barcode data characters encoding using C#

Top

Code 39 standard mode

Code 39 barcode standard mode supports 43 characters, including
  • Numeric digit: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • Uppercase letters (A - Z)
  • Special characters: - (Dash), $ (Dollar), % (Percentage), (Space), . (Point), / (Slash), + (Plus)
  • Start/Stop character
In C# code 39 barcode generator, you need choose barcode Type property value "BarcodeType.CODE39".

Linear code39 = new Linear();
code39.Type = BarcodeType.CODE39;
//Input your barcode encoding data:
code39.Data = "ABC-12345";




Code 39 Full ASCII mode

Code 39 supports encoding the full 128 character ASCII character set in accordance with ISO 646 IRV.
In C# code 39 barcode generator, you need choose barcode Type property value "BarcodeType.CODE39EX".

Linear code39 = new Linear();
code39.Type = BarcodeType.CODE39EX;
//Input your barcode encoding data:
code39.Data = "abc-12345";




Code 39 barcode check digit

Code 39 barcode does not include a checksum or check digit by default.

For applications requiring enhanced data security, the modulo 43 (MOD43) check character may be used as a check digit.

You can view the barcode Code 39 check digit calculator in details
In C#, to add checksum digit to Code 39 barcode, you need set property AddCheckSum to true.

code39.AddCheckSum = true;




Do not display Code 39 barcode check digit in HRI

You can also enable code 39 check digit, and hide it in the HRI (human readable interpretation).

In C# class, you need set property ShowCheckSumChar to false.

// Hide checksum digit at the end of barcode data.
code39.ShowCheckSumChar = false;






Code 39 barcode Start/stop characters

Code 39 barcode uses asterisk character (*) as Start and Stop characters, and it should not be part of the Code 39 barcode data.

In C# class, you can display or hide start/stop characters (asterisk *) through property ShowStartStopInText.

code39.ShowStartStopInText = false;






Code 39 Barcode Dimension Size in C#

Top
In C# Code 39 generator, you can use the following barcode dimension size settings:
  • UOM: Unit of measure. You can choose PIXEL, CM or INCH.
  • X: Width of narrow element. The mimumum bar width is defined by the application specification
  • Y: Bar module height.
  • N: Wide/narrow ratio. the valid value is from 2.0 to 3.0 inclusive.
  • I: Width of intercharacter gap
    • minimum gap is equal to X
    • maximum: for X < 0.287mm, is 5.3X; for X >= 0.287mm, is 1.52mm or 3X, whichever is greater.
  • LeftMargin, RightMargin: Quiet zone. the minimum width of quiet zone is 10X.
You can view the Code 39 Barcode Size Calculator here.

An example C# source code to set Code 39 barcode image size.

Linear code39 = new Linear();
code39.Type = BarcodeType.CODE39;
code39.Data = "ABC-123";
code39.AddCheckSum = true;

// Unit of measure, pixel, cm and inch supported.
code39.UOM = UnitOfMeasure.PIXEL;
code39.X = 3;
code39.Y = 120;
code39.N = 3.0f;
code39.I = 1.2f;
code39.LeftMargin = 30;
code39.RightMargin = 30;






Create and customize Code 39 barcode in C# ASP.NET, WinForms apps

Top
Using OnBarcode C# Barcode Generator library, you can apply the following two properties to customize the Code 39 bar and space width in C# application.
  • N: Wide bar width vs narrow bar width ratio, 2.0 - 3.0 inclusive, default is 2.
  • I: The space between 2 characters in code 39. This is a multiple of X (narrow bar width).

Here we will show how to customize the Code 39 barcode image below through properties N and I.




Code 39 Wide bar size vs Narrow bar size ratio (N)

You can apply the Code 39 wide bar vs narrow bar ratio through property N using C# Code 39 barcode generator library.

The property N valid value is from 2 to 3 (both inclusive). The default is 2.

barcode.N = 3;





Code 39 Intercharacter space (I)

You can apply the Code 39 inter characters space size through property I in C# class.

The property I is the space between 2 character bar modules, and it is a multiple of X (narrow bar module width). The default value is 1.0f.

barcode.I = 2;





Tutorial: Create Code 39 barcode in C# ASP.NET Core web application

Top
Now we will start with a new ASP.NET Core web application and enable Code 39 barcode generation in it. We will further add more Code 39 customizations printed on the webpage.

In this tutorial, you:
  • Enable Code 39 full ASCII mode
  • Show or hide Code 39 Start/Stop characters on the webpage
  • Add or without check sum character, Show or hide it in Code 39 text




Build a new ASP.NET Core app with Code 39 barcode generation

We have already provided a ASP.NET Core demo app with barcode generation enabled from scratch.

You can see details here: How to create barcode in ASP.NET Core web app using C#?.

We will update the project to support Code 39 generation and customization from this ASP.NET Core web application.

  1. Find and open file "Index.cshtml.cs" from previously built project "OnBarcode.BarcodeGenerator.ASPNETCoreDemo" in Visual Studio
  2. Go to "OnPost()" method, find the C# code "linear.Type = OnBarcode.Barcode.BarcodeType.CODE128;". Replace it with the new code : "linear.Type = OnBarcode.Barcode.BarcodeType.CODE39;"

            public Task<IActionResult> OnPost()
            {
                this.Message = Request.Form["tbMessage"].ToString();
    
                OnBarcode.Barcode.Linear linear = new OnBarcode.Barcode.Linear();
                linear.Type = OnBarcode.Barcode.BarcodeType.CODE39;
                linear.Data = this.Message;
                linear.OutputFileFormat = FileFormat.PNG;
    
                byte[] dataBytes = linear.drawBarcodeAsBytes();
                BarcodeImage = System.Convert.ToBase64String(dataBytes);
    
                return Task.FromResult<IActionResult>(Page());
            }
    
  3. Now you can generate Code 39 barcode images on the web page.




Create Code 39 with ASCII text encode in C# ASP.NET Core

Code 39 barcode supports 43 characters encoding, includes digits, Upper case letters, and other special characters. To encode text string from ASCII table, you need Code 39 extension mode.

Note: ASCII table includes 33 control characters which are non-printing ones. To create Code 39 barcode with control chars, you need convert chars to bytes first. See details here: How to Print Barcode with ASCII Non-printing Chars using C#?

Simply change barcode type to "CODE39EX", you can enable Code 39 extension mode generation in ASP.NET web app.

Add the C# code below to "OnPost()" method in the file "Index.cshtml.cs".
linear.Type = OnBarcode.Barcode.BarcodeType.CODE39EX;




Now you can create and print Code 39 with lower case letters encode in your ASP.NET Core web page.




Show/hide Code 39 start/stop characters in barcode text

Code 39 barcode will include two special characters (Start, Stop characters) in the beginning and ending of the barcode. By default, the two characters will be printed as "*" in the Code 39 barcode text.

You can hide the two characters by setting ShowStartStopInText to false.

Add the C# code below to "OnPost()" method in the file "Index.cshtml.cs".
linear.ShowStartStopInText = false;



Now the start/stop (*) labels have been removed from the Code 39 barcode text. Please note that the start/stop characters are still be encoded in the above Code 39 barcode moduels.




Add or without check sum character, Show or hide it in Code 39 text

According to the Code 39 ISO specification, the checksum character is optional for Code 39. You can create Code 39 with check sum character or without it. By default, the C# barcode library will not add check sum to Code 39. If you need it, you can enable it through the following C# code.

Add the C# code below to "OnPost()" method in the file "Index.cshtml.cs".
linear.AddCheckSum = true;



When AddCheckSum is true, the barcode generator library will calculate and print the Code 39 check sum character in the generated Code 39 barcode.




 

Code 39 Barcode Complete Property Settings with detailed C# sample source code

.NET Barcode Generator library has provided 20+ property settings to customize the created Code 39 barcode images. You view the complete list of Code 39 barcode property settings here.

And view the detailed C# source code at How to generate Code 39 barcode in C# application?












Common Asked Questions

What is Code 39 barcode used for?

Code 39, also known as Code 3 of 9, was the first barcode to encode both numbers and letters. It is most commonly used in the inventory, government, military and electronics industries. Using C# barcode generator library, you can need choose right barcode format in property Type to create Code 39 or Code 39 extension barcodes.

To create Code 39 regular barcodes in C#, apply the barcode Type as BarcodeType.CODE39.
To create Code 39 extended barcodes using C#, apply the barcode Type as BarcodeType.CODE39EX.

Can Code 39 barcode encode lowercase letters?

Code 39 barcode regular version does not support lowercase letters encoding. However Code 39 extended version supports. In C# class, set the barcode object property Type to BarcodeType.CODE39EX to create Code 39 barcodes with lowercase text encoded.

What is the minimum size for Code 39?

Code 39 barcodes need meet the following size requirements.
  • Width of narrow element (X): the mimumum bar width is defined by the application specification. In C# class, you can customize the Code 39 bar/space module width by barcode property X
  • BarCode height: the minimum height is 5.0mm or 15% of symbol width (excluding quiet zones), whichever is greater. Using C# barcode library, you can customize the Code 39 barcode height through property BarcodeHeight

What is the ratio of narrow to wide bars in Code 39 barcode?

The valid ratio of Code 39 narrow to wide bars is from 1:2 to 1:3. You can apply the Code 39 ratio configure through property N using C# barcode library.

What is the difference between Code 39 and Code 128 barcodes?

Code 128 requires a checksum. If the Code 128 barcode is damaged, it may still be scannable. Code 39 checksum is optional. If the Code 39 barcode without checksum is damaged, it won't be scannable. In C# class, you can generate Code 39 barcode with or without check sum applied using C# Barcode Generator library.

In C#, enable property AddCheckSum to append a checksum character to the end of Code 39 barcode. code39.AddCheckSum = true;.

What is the difference between barcode 39 and barcode 93?

Code 93 is an updated version of Code 39. Code 93 is a higher-density barcode type compared to Code 39. C# barcode library supports both Code 39 and Code 93 barcodes generation in C# applications.

Apply property Type to BarcodeType.CODE39 or BarcodeType.CODE39EX to generate Code 39 regular and extended barcodes.

Apply property Type to BarcodeType.CODE93 print Code 93 barcode images in C# project.




Summary

Top
OnBarcode C# Barcode Generator makes it easy to generate, create Code 39 and other linear & 2d barcodes in .NET projects.

OnBarcode offers several Code 39 Generator components and software, such as free Excel Code 39 barcode add-in, Code 39 in Java, Code 39 in VB.NET, Code 39 in ASP.NET, Code 39 Generator.





































Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.