KA.Barcode for .NET Suite
How to Generate PDF-417 in C# Application
How to Generate 2D PDF-417 Barcode Images Using Visual C# in .NET Applications

C# PDF 417 barcode generator library: generate, create PDF417 2d barcode with free c# example source code









  • Completely written in C#.NET with full integration into .NET development environments
  • Generate PDF-417 barcode in ASP.NET, WinForms, Class & Console, Crystal Reports & RDLC Reports
  • Generate PDF-417 images in stream & graphics object and support png, jpeg, gif, tiff & bmp image formats
  • Offer flexible PDF-417 barcode dimension options to select, like width, height, color, orientation, resolution, etc
  • Support PDF-417 Column Count, PDF-417 Row Count, PDF-417 Truncation and Error Correction Level properties
  • Create PDF-417 barcode images with C# sample code compatible with latest PDF-417 encoding specifications
C# PDF-417 Barcode Control Summary
KA.Barcode for .NET Suite is a mature and reliable barcoding encoder control SDK for generating two-dimensional Data Matrix images in .NET development environment. Developers can easily create and display Data Matrix in ASP.NET web pages, Windows Forms & Crystal Reports with C# programming. Flexible barcode settings are also available for users to customize generated images.
KeepAutomation barcode encoder for .NET is a versatile barcoding component SDK API for developers to easily generate & integrate PDF-417 and other linear & 2D barcode symbologies in .NET projects with C# progamming. What's more, a variety of barcoding features are available for users to adjust the generated barcode images, such as row count, column count, width, height, orientation, etc.
What Is A PDF-417 Barcode
PDF417, also named Portable Data File 417, PDF 417, PDF417 Truncated, is a stacked bi-dimensional barcode symbol used mainly in transport, inventory management and identification cards.
PDF-417 Valid Data Sets
  • All 128 characters of ASCII

  • Extended ASCII. Values 128-255 in accordance with ISO 8859-1.




Encode Non-printable Chars in PDF-417
  • Set TildeEnabled to true

  • Use '~ddd' for non-printable chars. For example, ASCII char [GS] is non-printable, and its decimal value is 29. In barcode data, you need use ~029 for char [GS].




Encode byte[] in PDF-417 Barcode
The following C# source codes demo how to encode byte[] object in PDF-417
//  Byte array to encode
byte[] dataBytes = new byte[] { 0x41, 0x42, 0x43, 0x44, 0x45 };

//  Convert byte array to the input (property CodeToEncode)
String inputMsg = "";
foreach (byte b in dataBytes)
    inputMsg += "~" + b.ToString().PadLeft(3, '0');

//  Create barcode
BarCode barcode = new BarCode();
barcode.Symbology = Symbology.PDF417;
barcode.PDF417DataMode = PDF417DataMode.Byte;
//  enable '~' in the input message
barcode.TildeEnabled = true;
barcode.CodeToEncode = inputMsg;

//  set module size
barcode.BarcodeUnit = BarcodeUnit.Pixel;
barcode.X = 3;
barcode.PDF417XtoYRatio = 0.6F;
barcode.PDF417ColumnCount = 5;
barcode.PDF417RowCount = 10;

barcode.generateBarcodeToBitmap().Save(@"C:\PDF417_Bytes.png");




Encode non-English text in PDF-417 Barcode
The following C# source codes demo how to encode non English text (such as Japanese text) in PDF-417
//  Message in Japanese
String unicodeMsg = @"おはようございます";

//  Convert Unicode string to data bytes
byte[] dataBytes = Encoding.Unicode.GetBytes(unicodeMsg);
//  Convert byte array to the input (property CodeToEncode)
String inputMsg = "";
foreach (byte b in dataBytes)
    inputMsg += "~" + b.ToString().PadLeft(3, '0');

//  Create barcode
BarCode barcode = new BarCode();
barcode.Symbology = Symbology.PDF417;
barcode.PDF417DataMode = PDF417DataMode.Byte;
//  enable '~' in the input message
barcode.TildeEnabled = true;
barcode.CodeToEncode = inputMsg;

//  set module size
barcode.BarcodeUnit = BarcodeUnit.Pixel;
barcode.X = 3;
barcode.PDF417XtoYRatio = 0.6F;
barcode.PDF417ColumnCount = 5;
barcode.PDF417RowCount = 10;

barcode.generateBarcodeToBitmap().Save(@"C:\PDF417_Japanese.png");




Generate Barcode Image in Specified Width and Height
  • Set property AutoSizeAdjust to true

  • Set property DPI to be the same or higher as your printer's resolution

  • Set property BarcodeUnit to inch or cm

  • Set property BarCodeWidth and BarCodeHeight to your required image width and height
PDF-417 Property Settings
Class Attribute HTTP Attribute Default Value Note
Basic
Symbology symbology Code128Auto Barcode symoblogy type
CodeToEncode code-to-encode "128" Barcode value to encode.
ChecksumEnabled checksum-enabled false It is not applied for PDF-417
ImageFormat image-format ImageFormat.Png Barcode encoded image format.
Barcode Size
AutoSizeAdjust auto-size-adjust false If true, barcode X, Y module will be auto-adjusted.
BarcodeUnit barcode-unit BarcodeUnit.Pixel Unit of measure for all size related settings. 0: pixel; 1: inch; 2: cm.
X x 1 Barcode module width (narrow bar).
Y y 50 Linear barcode bar height / 2D barcode module height.
LeftMargin left-margin 0 Barcode image left margin.
RightMargin right-margin 0 Barcode image right margin.
TopMargin top-margin 0 Barcode image top margin.
BottomMargin bottom-margin 0 Barcode image bottom margin.
DPI dpi 72 Barcode image resolution in dpi.
Orientation orientation Orientation.Degree0 Barcode rotation angle.
BarCodeWidth barcode-width 0 Whole barcode width.
BarCodeHeight barcode-height 0 Whole barcode height.
2D / Matrix Group Barcode Properties
GroupEnabled group-enabled false Set to enable Data Matrix, PDF417, or QR Code group function.
GroupItemCount group-item-count 0 Data Matrix, PDF417, or QR Code group count.
GroupItemId group-item-id 0 Data Matrix, PDF417, or QR Code group item id.
GroupId group-item-id 0 Data Matrix, PDF417, or QR Code group item.
PDF-417 Specific Settings
PDF417DataMode pdf417-data-mode PDF417DataMode.Text Set PDF417 data encoding mode.
  • PDF417DataMode.Binary: It allows encoding all 256 possible 8-bit byte values. This includes all ASCII characters value from 0 to 127 inclusive and provides for international character set support.

  • PDF417DataMode.Text: It allows encoding all printable ASCII characters, i.e. values from 32 to 126 inclusive in accordance with ISO/IEC 646, as well as selected control characters such as TAB (horizontal tab ASCII 9), LF (NL line feed, new line ASCII 10) and CR (carriage return ASCII 13).

  • PDF417DataMode.Numeric: It allows encoding numeric data.
PDF417ECL pdf417-ecl PDF417ECL.ECL_2 Set PDF417 error correction level, from L0 to L8.
PDF417RowCount pdf417-row-count 3 Set PDF417 row count, from 3 to 90.
PDF417ColumnCount pdf417-column-count 5 Set PDF417 column count, from 1 to 30.
PDF417Truncated pdf417-truncated false Apply to encode Truncated PDF417.

Truncated PDF417 barcode is area efficient.

Truncated PDF417 may be used where space considerations are a primary concern and symbol damage is unlikely.
PDF417TXtoYRatio pdf417-x-y-ratio 0.33333f PDF 417, bar width vs bar height ratio.

X (bar cell width) = Y (bar cell height) * PDF417TXtoYRatio.
TildeEnabled tilde-enabled false Set TildeEnabled to true, specifying special characters in barcode data.

Support escape '~' for data message
  • 1-byte character: ~ddd (character value from 0 ~ 255)
    ASCII (with EXT): from ~000 to ~255

    For example, ASCII char [GS] is non-printable, and its decimal value is 29. In barcode data, you need use ~029 for char [GS].

  • 2-byte character: ~6ddddd (character value from 0 ~ 65535)

  • Unicode: from ~600000 to ~665535

  • ECI: from ~7000000 to ~7999999

  • SJIS: from ~9ddddd (Shift JIS 0x8140 ~ 0x9FFC and 0xE040 ~ 0xEBBF)
PDF-417 Barcode Creation in ASP.NET Using C#
This barcode encoder control SDK library provides three methods to stream PDF-417 in ASP.NET: barcode control drag-and-drop in ASP.NET websites, Visual C# Class Library and Microsoft IIS. Installation is quite simple as you only need to add this library to reference or Toolbox. For detailed guide, click here: How to print barcode in Visual C# with ASP.NET web control.
PDF-417 Barcode Generation in .NET WinForms Using C#
To paint and draw PDf-417 barcode images in .NET Windows Forms applications, you can add control to Toolbox and drag & drop it for direct PDF-417 image generation. Or you can add the barcode library to reference and generate PDF-417 with Visual C# Class Library / Console Application. Here is a detailed guide: How to create barcode in .NET WinForms with Visual C#.
PDF-417 Barcode Making in Crystal Reports Using C#
This barcode generator for .NET Suite can also support PDF-417 2D barcode generation in Crystal Report. Users can convert columns of data into multiple PDF-417 barcode images with just a few clicks. Detailed tutorial are given with C#.NET sample code. Click here to view more: How to create barcode in Crystal Reports with Visual C#.
PDF-417 Barcode Adding in RDLC Reports Using C#
.NET Barcode Generator SDK Library supports creating PDF-417 barcode images in Visual Studio 2005 / 2008 / 2010 Report Viewer RDL reports (RDLC Local Report), which can accurately convert columns of data into multiple PDf-417 barcode images with simple steps. Refer to: How to create barcode in RDLC Reports with C# code.
PDF-417 Barcode Generation in .NET Applications with C#
Below is Visual C# demo code for you to generate PDF-417 barcode images in C# Class Library. You may make necessary adjustment according to your target barcode properties. Make sure you have added reference to this barcode control at first.
C# Sample code
     BarCode pdf417 = new BarCode();
pdf417.Symbology = KeepAutomation.Barcode.Symbology.PDF417;

pdf417.PDF417RowCount = 3;
pdf417.PDF417ColumnCount = 5;
// Set PDF 417 encoding valid input: All ASCII characters. Length: variable.
pdf417.CodeToEncode = "PDF417";

//Select a data format for PDF-417 according to your data:
//Auto: automatic data format selection according to your data
//Text: each codeword represents one or two characters.
//Byte: each group of 5 codewords represents 6 bytes.
//Numeric: groups of up to 15 codewords represent as many as 44 decimal digits.
pdf417.PDF417DataMode = PDF417DataMode.Auto;
// Set PDF 417 image size

// Unit of measure, pixel, cm and inch supported.
pdf417.BarcodeUnit = BarcodeUnit.Pixel;
// PDF 417 image resolution in dpi
pdf417.DPI = 72;
// PDF 417 bar module width (X Dimension)
pdf417.X = 3;
// PDF 417 bar width vs bar height
pdf417.PDF417XtoYRatio = 0.3f;

// PDF 417 image left margin size, minimum value is 2X.
pdf417.LeftMargin = 6;
pdf417.RightMargin = 6;
pdf417.TopMargin = 6;
pdf417.BottomMargin = 6;
// PDF417 image orientation, 90, 180, 270 degrees supported.
pdf417.Orientation = KeepAutomation.Barcode.Orientation.Degree0;

// PDF417 image format, support png, jpeg, gif, tiff, bmp, etc.
pdf417.ImageFormat = ImageFormat.Png;

// PDF417 Error Correction Level, 0-8 supported..
pdf417.PDF417ECL = PDF417ECL.ECL_1;

// Generate PDF 417 barcodes in image format BMP
pdf417.generateBarcodeToImageFile("C://barcode-pdf417-csharp.bmp");


/* Create PDF-417 barcodes in Stream object
pdf417.generateBarcodeToStream(".NET System.IO.Stream Object");

Draw & Print PDF-417 barcodes to Graphics object
pdf417.generateBarcodeToGraphics(".NET System.Drawing.Graphics Object");

Generate PDF-417 barcodes & write to byte[]
byte[] barcodeInBytes = pdf417.generateBarcodeToByteArray();

Generate PDF-417 barcodes & encode to System.Drawing.Bitmap object
Bitmap barcodeInBitmap = pdf417.generateBarcodeToBitmap();
*/