The Code 39 barcode generator for Crystal Reports is a component of the comprehensive .NET barcode library. It is designed for straightforward integration into .NET Crystal Report projects, enabling the dynamic generation of high-quality Code 39 symbols.
BarcodeLib provides not only the Code 39 Barcode Control for Crystal Reports but also a full range of linear and 2D barcode generators for Crystal Reports.
This developer guide provides a detailed, step-by-step C# demo code for printing Code 39 (a discrete, variable length linear barcode symbology) in Crystal Reports for .NET within ASP.NET, Windows Forms, and WPF applications.
It explains how to insert Code 39 in the report designer, customize its appearance, and print it in the report viewer. Topics covered include Code 39 data encoding modes, check digit configuration, dimension settings, and advanced customization to ensure seamless integration with Crystal Reports components and compliance with industry standards.
Code 39 Barcodes & Other Supported Barcode Images
Code 39 Barcode: Code 39 is a discrete and variable-length barcode type, also mentioned as the "Code 3/9", "Code 3 of 9", "USS Code 39", "USD-3", "Alpha39", "Type 39". Besides, Code 39 is the standard barcode used by United States Department of Defense and Health Industry Bar Code Council (HIBCC).
Crystal Reports Linear Barcodes: Code 39, Code 128, EAN-8, EAN-13, GS1-128, ITF-14, Interleaved 2 of 5, UPC-A, UPC-E, Planet, Postnet, OneCode, Code 93, Codabar, Code 11, Code 2 of 5, etc.
Crystal Reports 2D Barcodes: Data Matrix, PDF 417, QR Code.
Code 39 Crystal Reports Barcode Creation for ASP.NET Web Services, Website
Create a new ASP.NET website.
Choose "ASP.NET Crystal Reports Web Site" as the template and named the project as "BarcodeforCrystalReportsWebSite".
Add a new item "Crystal Report" to your project.
Add a new item "Crystal Report" to the project and name it as "CustomerReport.rpt". view image
Select "Mail Label" in the pop-up window and click "OK". view image
In "Mailing Labels Report Creation Wizard", click "Create New Connection", and expand "ADO.NET". view image
In "ADO.NET" form, choose "CustomerDataSet.xsd" file in your downloaded package, and click "Finish". view image
In "Mailing Labels Report Creation Wizard", add table "Customer" under "ADO.NET" to selected table. And click "Next". view image
Add all three fields "ID", "CustomerId", "CustomerName" to "Fields to Display:", then click "Next". view image
Select default label "Return Address (Avery 5267)", and click "Finish".
Now you can view the report template and find that field "Barcode" not in the report template. view image
Now, please re-arrange the report template. view image
Drag field "Barcode" to the report template, right click "Barcode" object and choose "Format Object" menu. view image
In "Format Editor" form, check "Can Grow" property. view image
Drag a "Crystal Report Viewer" to the "Default.aspx".
Add a reference to BarcodeLib.Barcode.CrystalReports.dll.
Copy the following C# code to the "Default.aspx.cs" file.
using System.Data.OleDb; using System.Drawing.Imaging; using BarcodeLib.Barcode.CrystalReports; using BarcodeLib.Barcode;
protectedvoid Page_Load(object sender, EventArgs e) { // Create the database connection. Please change to correct data file (BarcodeDemoData.mdb) path. OleDbConnection aConnection = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:/BarcodeLib_NETBarcode_Trial/ReportingData/BarcodeDemoData.mdb"); aConnection.Open();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter("SELECT * FROM Customer", aConnection); DataSet ds = new DataSet(); dataAdapter.Fill(ds);
// Add the Barcode column to the DataSet ds.Tables[0].Columns.Add(new DataColumn("Barcode", typeof(byte[])));
// Create an instance of Linear Barcode LinearCrystal barcode = new LinearCrystal(); // Barcode settings barcode.Type = BarcodeType.CODE39; barcode.BarHeight = 50; //50 pixel barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
Code 39 Barcode Data Characters Encoding in Crystal Reports for .NET
This section describes the character sets that Code 39 can encode.
Code 39 Standard Mode
Code 39 standard mode (supported in Crystal Reports for .NET) encodes the following 43 characters:
Numeric digits: 0 - 9
Uppercase letters: A - Z
Special characters: -, $, %, space, ., /, +
The start and stop character (*) is automatically added by the library and must not be included in the Data property.
To use standard mode in Crystal Reports, enter the desired characters into the Data property.
Note: Standard mode supports only uppercase letters. Lowercase input will not encode correctly; use Code 39 Full ASCII mode to encode lowercase characters.
Code 39 Full ASCII Mode (Extension Mode)
Code 39 Full ASCII mode encodes the full 128 character ASCII set (per ISO 646 IRV), including lowercase letters. To enable this mode, change the barcode type to BarcodeType.CODE39EX.
Code 39 Check Digit Configuration
Code 39 does not include a check digit by default, which is suitable for low risk Crystal Reports use cases. For enhanced data security, such as in inventory reports, enable the MOD43 check digit via the AddCheckSum property.
In the generated Code 39 barcode, the check character appears as an additional character (e.g., $ in the example image).
Hide Check Digit in Human Readable Interpretation (HRI)
The check character can be enabled but hidden in the human readable text label (HRI) displayed below the barcode. To achieve this:
Set AddCheckSum to true to enable the check digit.
Set ShowCheckSumChar to false to hide it in the HRI.
Code 39 Start/Stop Characters
Code 39 uses the asterisk (*) as the start and stop characters; these are automatically added by the library. To hide these characters in the human readable text, use the following property: ShowStartStopInText.
Note: The * character must not be included in the Data property, as doing so will corrupt the barcode. This constraint should be enforced through Crystal Reports filtering logic if necessary.
Code 39 Barcode Dimension Settings for Crystal Reports
A Code 39 barcode can be generated with specified image width and height directly in the Crystal Reports report template.
UOM: Unit of measure (PIXEL, CM, or INCH), which should match the units used in the Crystal Reports report.
BarcodeWidth and BarcodeHeight: Set the desired barcode image dimensions.
Further dimension customization is possible to fit the Crystal Reports layout (header, footer, or details sections) using the following properties:
AutoResize: When true, the library automatically selects the maximum bar module width and height. When false, the library uses the developer specified X and Y values.
X: Narrow element width; the minimum value should be defined by application specifications.
Y: Bar module height; ensure it fits within the bounds of the Crystal Reports picture control.
N: Wide/narrow ratio (valid range 2.0–3.0; default is 2.0).
I: Inter character gap; the minimum equals X; the maximum depends on X.
LeftMargin / RightMargin: Quiet zone margins; a minimum of 10X is recommended to avoid scanning errors.
Wide/Narrow Ratio (N)
The wide/narrow bar ratio can be adjusted to optimize scannability in Crystal Reports. The N property accepts a value between 2.0f and 3.0f; the default is 2.0f.
Note: Values outside the 2.0 - 3.0 range may produce unreadable barcodes. Validate in the development environment before deploying to a Crystal Reports Server.
Inter character Gap (I)
The gap between characters can be modified using the I property, which is expressed as a multiple of X (the narrow bar module width).
Minimum gap equals X.
Maximum: for X < 0.287 mm, the maximum is 5.3X; for X ≥ 0.287 mm, the maximum is either 1.52 mm or 3X, whichever is larger.
Default value is 1.0f.
Note: An excessively large I value can produce unreadable Code 39 barcodes. Always test printed barcodes with a scanner before deployment to a Crystal Reports Server.
Summary
This guide has provided a comprehensive walkthrough for generating and customizing Code 39 linear barcodes in Crystal Reports using the BarcodeLib .NET library.
Integration: Code 39 barcodes can be generated in C# or VB.NET and bound to Crystal Reports via ReportDocument, CrystalReportViewer, and .rpt templates. The approach is compatible with ASP.NET Web Forms, WinForms, and WPF (via WindowsFormsHost).
Data Encoding: Standard and Full ASCII modes support a wide range of characters, including uppercase letters, digits, special symbols, and the full ASCII set. Check digit configuration and HRI customization provide flexibility for data validation and presentation.
Layout Control: Barcode dimensions, wide/narrow ratio, and inter character gap can be precisely adjusted to fit Crystal Reports headers, footers, and details sections, ensuring consistent print quality and scannability.
Crystal Reports Linear & 2D Barcode Creation Using C# or VB Code
We provide online developer guide for C# and VB.NET Crystal Reports barcode generating & inserting, as well as Crystal Reporing bar coding for ASP.NET and Windows Forms applications.