Guide for C#
Core Document Formats
Additional Features
Code 39

C# Imaging - C# Code 39 Barcoding Tutorial

Draw Code 39 Barcode on Raster Images, TIFF, PDF, Word, Excel and PowerPoint

Visual C#
Home > .NET Imaging SDK > C# > Generate Code 39 Barcode
If this is your first time to use our DocImageSDK, we strongly suggest you reading How to Start first!

C# Imaging Code 39 Barcode Add-on Overview
RasterEdge DocImage SDK for .NET includes this RasterEdge.Imaging.Barcode.Creator.dll for C# developers to generate and create Code 39 on TIFF, PDF, Word, Excel and PowerPoint documents and raster image files using C# class codes. With the sample codes demonstrated below, users can freely create and print Code 39 bar codes on any page within TIFF, PDF, Excel, PowerPoint or Word file, and at any location on a Jpeg, Gif, Png, or Bmp image. And below are the main features.
  • Create Code 39, Code 39 Extension encoding alphanumeric data in .NET
  • C# Code 39 component DLL designed for Visual Studio 2005 or above
  • Resize Code 39 linear bar code image by controlling barcode width & barcode height
  • Include algorithm to automatically add Code 39 check digit character / checksum
  • Adjust Code 39 image resolution for high-quality output suitable for all printers
This tutorial will show you Visual C# examples on how to create Code 39 barcode images in .NET programs.
  • How to draw Code 39 barcode on image
  • How to generate Code 39 on certain document page
  • Code 39 dimension settings and C# sample codes
  • Code 39 (barcode 3 of 9) FAQs
Written in C# managed code, this .NET barcode writing library is compatible with multiple development environments such as VB.NET class library (Generating Code 39 in VB.NET), ASP.NET (Generating Barcode in ASP.NET aspx page) & .NET WinForms (Generating Barcode in .NET Windows Forms).
Draw Code 39 on Raster Image in C# Project
With the following Visual C# demo code, you are able to generate Code 39 on raster image files, including BMP, PNG, GIF, and JPEG formats. Below are some basic settings for Code 39. For more dimension settings, please refer to the complete property table below. You will be able to adjust barcode location on image, and control Code 39 size, resolution, checksum, orientation, color, and text, etc.
// invoke this only once at the beginning of your code
WorkRegistry.Reset();

// create REImage on which you want to draw the barcode
REImage reImage = new REImage("c:/Sample.png");

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE39;// select barcode type
barcode.Data = "0123456ABCD";// set barcode data
barcode.X = 1.0F;// set x
barcode.Y = 60.0F;// set y
barcode.Resolution = 96;// set resolution
barcode.Rotate = Rotate.Rotate0;// set rotation

barcode.DrawBarcode(reImage, 0, 0);// draw barcode on REImage with location x and y

reImage.Save(ImageType.PNG, @"c:/barcode.png");
Generate Code 39 on Certain Document Page
This section will demonstrate how to generate & embed Code 39 on PDF, multi-page TIFF, Microsoft Office Word document (.docx), Excel sheet (.xlsx) and PowerPoint (.pptx). Visual C# users can draw it at any location of document page, and adjust Code 39 parameters freely.

Write C# Code 39 on Defined Area in PDF Document

PDFDocument doc = new PDFDocument("c:/Sample.pdf");
PDFPage page = (PDFPage)doc.GetPage(0);

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE39;// select barcode type
barcode.Data = "0123456ABCD";// set barcode data
barcode.X = 1.0F;// set x
barcode.Y = 60.0F;// set y
barcode.Resolution = 96;// set resolution

// add this barcode image to this page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save the changes
doc.Save(@"c:/barcode.pdf");

Create C# Code 39 on Multi-page TIFF Document

// load TIFF document. You can also load document like PDF, Word, Excel & PPT
TIFFDocument tiff = new TIFFDocument(@"c:\sample.tiff");

// get the first page
BasePage page = tiff.GetPage(0);

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE39;// select barcode type
barcode.Data = "0123456ABCD";// set barcode data
barcode.X = 1.0F;// set x
barcode.Y = 60.0F;// set y
barcode.Resolution = 96;// set resolution
barcode.Rotate = Rotate.Rotate0;// set rotation

// add barcode image to the first page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save changes to TIFF document
tiff.Save(@"c:\barcode.tiff");

Draw C# Code 39 on Office Word Document

// construct an DOCXDocument
DOCXDocument doc = new DOCXDocument(@"c:/Sample.docx");

// get the first page
BasePage page = doc.GetPage(0);

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE39;// select barcode type
barcode.Data = "0123456ABCD";// set barcode data
barcode.X = 1.0F;// set x
barcode.Y = 60.0F;// set y
barcode.Resolution = 96;// set resolution
barcode.Rotate = Rotate.Rotate0;// set rotation

// add barcode image to the first page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save changes to the file
doc.Save(@"c:\barcode.docx");

Write C# Code 39 Image on Excel Sheet

// construct an XLSXDocument
XLSXDocument doc = new XLSXDocument(@"c:/Sample.xlsx");

// get the first page
BasePage page = doc.GetPage(0);

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE39;// select barcode type
barcode.Data = "0123456ABCD";// set barcode data
barcode.X = 3.0F;
barcode.Resolution = 90;
barcode.Rotate = Rotate.Rotate90;

// add barcode image to the first page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save changes to the file
doc.Save(@"c:\barcode.xlsx");

Create C# Code 39 Barcode on PowerPoint Slide

// construct an PPTXDocument
PPTXDocument doc = new PPTXDocument(@"c:/Sample.pptx");

// get the first page
BasePage page = doc.GetPage(0);

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE39;// select barcode type
barcode.Data = "0123456ABCD";// set barcode data
barcode.X = 4.0F;
barcode.Resolution = 72;

// add barcode image to the first page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save changes to the file
doc.Save(@"c:\barcode.pptx");
Code 39 Settings and C# Sample Codes
Code 39 parameters listed below can ensure you to create a high-quality, scannable Code 39 in C#.NET program with customized settings.
CODE 39 SETTING+
CODE 39 SETTING-
Type CODE39
Data Format
UOM(Unit of Measure)
Rotate
I N(2.0 - 3.0 inclusive)
ShowStarStopInText ProcessTilde
BarAlignment Resolution(DPI)
AutoResize AddCheckSum
X(Bar Width) ShowText
Y(Bar Height) TextFontSize
BarcodeWidth TextMargin
BarcodeHeight TextFontName
TextColor TextFontStyle
TopMargin BackColor
BottomMargin ForeColor
  • ShowStarStopInText: As specified by ISO/IEC 16388 standard, Code 39 encodes an obligatory start character and stop character, graphically represented in human readable text as "*", i.e. the star sign. You can set this Boolean value false to hide them in the text below barcode bars.
  • N: Code 39 barcode is composed of narrow bars and wide bars. N dimension regulates the width ratio of wide bar to narrow bar.
  • I: Each one of the Code 39 data character is represented by 9 bars in the symbol image. I dimension, the inter-character space, specifies the space between each of these 9-bar groups in image.
  • AddChecksum: Code 39 is a self-checking linear barcode. But you can also choose to add checkum for better reading security.

Generate Code 39 with C# Code

RasterEdge offers free and accurate C# example code to create customized Code 39 on image and document files, by adjusting the properties listed above.
// invoke this only once at the beginning of your code
WorkRegistry.Reset();

// create REImage on which you want to draw the barcode
REImage reImage = new REImage("c:/Sample.png");

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE39;// select barcode type
barcode.Data = "0123456ABCD";// set barcode data

// Code 39 barcode size related
barcode.X = 1.0F;// set x
barcode.Y = 60.0F;// set y
barcode.BarcodeHeight = 60;
barcode.BarcodeWidth = 0;
barcode.BottomMargin = 0;
barcode.LeftMargin = 0;
barcode.RightMargin = 0;
barcode.BarAlignment = AlignmentHori.Left;
barcode.Resolution = 72;// set resolution
barcode.Rotate = Rotate.Rotate0;// set rotation
barcode.AddCheckSum = false;
barcode.UOM = RasterEdge.Imaging.Barcode.Creator.UnitOfMeasure.PIXEL;

// Code 39 colors
barcode.BackColor = System.Drawing.Color.White;
barcode.ForeColor = System.Drawing.Color.Black;

// Code 39 font style
barcode.TextFont = new Font("Arial", 9f, FontStyle.Regular);
barcode.TextColor = System.Drawing.Color.Black;
barcode.TextMargin = 6;
barcode.ShowText = true;

// Code 39 special
barcode.I = 1.0f;
barcode.N = 2.0f;
barcode.ShowStartStopInText = true;
barcode.ProcessTilde = false;

barcode.DrawBarcode(reImage, 0, 0);// draw barcode on REImage with location x and y

reImage.Save(ImageType.PNG, @"c:/barcode.png");
Code 39 Barcode FAQs

You barcode DLL supports Code 39 and Code 39 Extension. Any difference?

A typical Code 39 can encode only: alphanumeric A to Z and 0 to 9, and several special characters. (You can view from the table above.) But a Code 39 Extension can also encode lower-case letters from a to z, apart from those mentioned in the former. Thus it is advised to use Code 39 Extension if lower-case letter is involved for your data encoding.

Why are there star signs in my Code 39 text from the generated image?

The star signs are actually the start and stop characters compulsorily encoded in Code 39 as specified by corresponding standard. You can hide them by setting ShowStarStopInText to false.


Recommend this to Google+