C# PDF417 Barcode Generator Library

Integration & Developer Guide for PDF-417 2D barcode image generation in C#

Generate 2d barcode PDF-417 images in Visual C# .NET with complete sample C# source code





In this C# tutorial, you will learn how to create PDF-417 2d barcodes in .NET ASP.NET, Windows applications.

  • Easy to encode international text, special characters (such as non-printable chars) in PDF 417
  • Customizable properties for PDF417 color setting, image width and height settings
  • Support compact (Truncated) PDF417 for smaller printing area
  • Support Macro PDF417 to store large data message into mutliple PDF417 barcodes
  • Support .NET Core 8, 7, 6, 5 and .NET Framework 4.x, 3.x, 2.x
  • Build-in controller for ASP.NET web app and WinForms on .NET Framework

How to create 2d PDF417 barcodes using C#

  1. Download .NET PDF-417 Barcode Generator Suite
  2. Install C# library to create PDF417 barcodes in .NET projects
  3. Step by Step Tutorial









C# PDF-417 Generator Introduction
Top
PDF-417, also known as Portable Data File 417, PDF 417, PDF417 Truncated, is a stacked linear barcode symbol format used in a variety of applications.
C# PDF-417 Generator is one of the functions in OnBarcode's Barcode for .NET Generation Controls, which supports generating & printing PDF-417 and 20+ other linear & 2D bar codes for C# applications.
OnBarcode C# Barcode Generator makes it easy to generate, create PDF-417 and other linear & 2d barcodes in Microsoft Word.
OnBarcode provides several PDF-417 Generator components and software, including .NET PDF-417, Java PDF-417, VB.NET PDF-417, ASP.NET PDF-417, Android PDF-417, PDF-417 Generator.
This document is providing a detailed C# source code about generating PDF-417 barcodes in C# class using C# Barcode generation component. Complete PDF-417 custmoization settings is included in C# PDF-417 generation guide.




PDF417 Barcode Data Characters Encoding using C#

Top

PDF417 Valid character set

PDF417 barcode supports encoding the following character sets

  1. Full ASCII (128 characters)

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

  3. Up to 811 800 different character sets or data interpretations

  4. Various function codewords for control purposes


PDF417 data encoding mode

PDF417 format supports the following compact modes

  • Text Compaction mode permits all printable ASCII characters to be encoded, i.e. values 32 - 126 inclusive in accordance with ISO/IEC 646 (IRV), as well as selected control characters.

  • Byte Compaction mode permits all 256 possible 8-bit byte values to be encoded. This includes all ASCII characters value 0 to 127 inclusive and provides for international character set support.

  • Numeric Compaction mode permits efficient encoding of numeric data strings.


Using PDF417 barcode generator C# library, you can set the data encoding mode through property DataMode. You can also set DataMode to auto value, and the barcode library will choose the right encode mode for you.

            PDF417 barcode = new PDF417();
            
            barcode.Data = "PDF417";
            barcode.DataMode = PDF417DataMode.Auto;


PDF417 maximum data length

Maximum possible number of characters a PDF417 barcode (at error correction level 0).

  • Text Compaction mode: 1,850 characters

  • Byte Compaction mode: 1,108 characters

  • Numeric Compaction mode: 2,710 characters




PDF417 Barcode Symbol Size in C#?

Top
In C# PDF417 barcode generator, you can use the following barcode dimension size settings:

  • UOM: Unit of measure. You can choose PIXEL, CM or INCH.

  • X: Width of the bar module. The mimumum bar width is defined by the application specification

  • XtoYRatio: Bar width vs bar height ratio. Default value is 0.3333333f

  • RowCount: 3 to 90. Number of rows

  • ColumnCount: 1 to 30. Number of columns

  • LeftMargin, RightMargin, TopMargin, BottomMargin: Quiet zone. the minimum width of quiet zone is 2X.


C# sample code: PDF417 barcode symbol size setting.
            PDF417 barcode = new PDF417();

            barcode.Data = "PDF-417";
            barcode.ProcessTilde = true;

            barcode.DataMode = PDF417DataMode.Auto;

            // Barcode Size Related Settings
            barcode.UOM = UnitOfMeasure.PIXEL;
            barcode.X = 5;              //  Module Width 4 pixels
            barcode.XtoYRatio = 0.3333f;   //  Module Height 10 pixels
            barcode.Resolution = 300;

            barcode.ColumnCount = 5;    //  5 data columns per row
            barcode.RowCount = 12;      //  12 rows

            barcode.LeftMargin = 0;
            barcode.RightMargin = 0;
            barcode.TopMargin = 0;
            barcode.BottomMargin = 0;


            // Image format setting
            barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;

            barcode.drawBarcode("W://csharp-pdf417-symbol-size.png");






How to encode, create non-English text in PDF417 barcode using c#?

Top
PDF417 encodes characters in ISO 8859-1 by default. If you want to encode non-English text, such as Thai, Arabic, Greek, you can do it in one of the two methods.

  1. Convert non-English text characters to byte array using C# UTF8 encoding, and encode converted byte array in PDF417 using Byte compaction mode.

  2. Use Extended Channel Interpretation (ECI) to encode international text character set in PDF417 using C#
Sample C# source code to encode non-English text in PDF417 barcode using Byte compaction mode.

            PDF417 barcode = new PDF417();

            //  It may encode any Unicode characters after converting them to bytes in UTF-8 encode.
            //  And then, use Byte mode to encode these byte data.
            String message = "早上好";
            byte[] bytes = Encoding.UTF8.GetBytes(message);
            StringBuilder sb = new StringBuilder();
            foreach (byte b in bytes)
                sb.Append("~" + b.ToString().PadLeft(3, '0'));
            barcode.Data = sb.ToString();
            barcode.ProcessTilde = true;

            barcode.DataMode = PDF417DataMode.Byte;

            // Barcode Size Related Settings
            barcode.UOM = UnitOfMeasure.PIXEL;
            barcode.X = 4;              //  Module Width 4 pixels
            barcode.XtoYRatio = 0.4F;   //  Module Height 10 pixels

            barcode.ColumnCount = 5;    //  5 data columns per row
            barcode.RowCount = 12;      //  12 rows

            barcode.LeftMargin = 50;
            barcode.RightMargin = 50;
            barcode.TopMargin = 50;
            barcode.BottomMargin = 50;
            barcode.Resolution = 96;

            // Image format setting
            barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;

            barcode.drawBarcode("W://Projects//Test-Output//OnBarcode.com//csharp-pdf417-non-en-text.png");


How to encode, generate PDF417 barcode with non-printable chars using c#?

Top
            PDF417 barcode = new PDF417();

            // Encode non-printable character '[CR]' between 'a' and 'b'.
            barcode.Data = "a~013bc";
            barcode.ProcessTilde = true;

            barcode.DataMode = PDF417DataMode.Auto;

            // Barcode Size Related Settings
            barcode.UOM = UnitOfMeasure.PIXEL;
            barcode.X = 4;              //  Module Width 4 pixels
            barcode.XtoYRatio = 0.4F;   //  Module Height 10 pixels

            barcode.ColumnCount = 5;    //  5 data columns per row
            barcode.RowCount = 12;      //  12 rows

            barcode.LeftMargin = 50;
            barcode.RightMargin = 50;
            barcode.TopMargin = 50;
            barcode.BottomMargin = 50;
            barcode.Resolution = 96;

            // Image format setting
            barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;

            barcode.drawBarcode("C://Projects//Test-Output//OnBarcode.com//csharp-pdf417-non-print.png");


How to encode, generate byte array data in PDF417 barcode using c#?

Top
            PDF417 barcode = new PDF417();

            //  Byte mode is used to encode any 8-bit byte data.
            //  Each byte should be represented in format "~ddd", which "ddd" is a decimal number between 0 to 255.
            //  ProcessTilde must be enable to support this feature.
            barcode.Data = "~000~001~003~253~254~255";
            barcode.ProcessTilde = true;

            barcode.DataMode = PDF417DataMode.Byte;

            // Barcode Size Related Settings
            barcode.UOM = UnitOfMeasure.PIXEL;
            barcode.X = 4;              //  Module Width 4 pixels
            barcode.XtoYRatio = 0.4F;   //  Module Height 10 pixels

            barcode.ColumnCount = 5;    //  5 data columns per row
            barcode.RowCount = 12;      //  12 rows

            barcode.LeftMargin = 50;
            barcode.RightMargin = 50;
            barcode.TopMargin = 50;
            barcode.BottomMargin = 50;
            barcode.Resolution = 96;

            // Image format setting
            barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;

            barcode.drawBarcode("C://Projects//Test-Output//OnBarcode.com//csharp-pdf417-byte-array.png");


Extended Channel Interpretation (ECI) in PDF417 using C#

Top
Using PDF417 ECI feature, PDF417 supports up to 811 800 different data character sets.

In the following C# sample code, we will encode Thai text using ECI in PDF417 barcode.

Key Settings:

  • ProcessTilde: it should be enabled, and set to true.

  • ECI value for Thai: Use ECI 000013 (ISO/IEC 8859-11) for 8-bit data bytes. In OnBarcode ECI solution, the value should be "~7000013".

  • Each Thai text char value fromISO/IEC 8859-11: Eg. ก - 0xA1 - 161
            PDF417 barcode = new PDF417();

            //  Use ECI 000013 (ISO/IEC 8859-11) for 8-bit data bytes.
            String eci000013 = "~7000013";
            //  ISO/IEC 8859-11 Latin/Thai alphabet
            //  Byte values from 0xA0 to 0xFF are used for Thai characters.
            //  Eg. ก - 0xA1 - 161
            String bytesInISO8859_11 = "~161";

            //  Set flag to enable '~' in data message.
            barcode.ProcessTilde = true;
            barcode.Data = eci000013 + bytesInISO8859_11;

            barcode.DataMode = PDF417DataMode.Auto;




How to create Compact (Truncated) PDF417 barcodes using C#

Top
Compact PDF417 is also named as Truncated PDF417. In the original AIM USA (1994) and AIM Europe (1994) PDF417 specifications, the term Truncated PDF417 has been used in a technically synonymous manner.

Compact PDF417 may be used where space considerations are a primary concern and symbol damage is unlikely.

To create compact PDF417 using PDF417 generator C# library, you need set property Truncated to true;

            barcode.Truncated = true;




How to create Macro PDF417 barcodes using C#

Top
Macro PDF417 provides a mechanism for the data in a file to be split into blocks and be represented in more than one PDF417 symbol. This mechanism is similar to the Structured Append feature in other symbologies.

Each Macro PDF417 symbol shall contain additional control information to enable the original data file to be properly reconstructed, irrespective of the sequence in which the individual PDF417 symbols are scanned and decoded.

Up to 99 999 individual PDF417 symbols may be used to encode data in Macro PDF417.

            PDF417 barcode = new PDF417();

            barcode.Data = "MacroPDF";

            barcode.DataMode = PDF417DataMode.Auto;

            //  Macro PDF417 provides a mechanism to split a large data file into segaments and one PDF417 symbol for each segament.
            //  Enable Macro PDF417 feature and set additional properties.
            barcode.Macro = true;
            barcode.MacroFileIndex = 3;         //  File ID is 3. 
            barcode.MacroSegmentCount = 10;     //  Total 10 segements for the file.
            barcode.MacroSegmentIndex = 2;      //  This symbol is Segment 2. The first Segment Index is 0

            // Barcode Size Related Settings
            barcode.UOM = UnitOfMeasure.PIXEL;
            barcode.X = 4;              //  Module Width 4 pixels
            barcode.XtoYRatio = 0.4F;   //  Module Height 10 pixels

            barcode.ColumnCount = 5;    //  5 data columns per row
            barcode.RowCount = 12;      //  12 rows

            barcode.LeftMargin = 50;
            barcode.RightMargin = 50;
            barcode.TopMargin = 50;
            barcode.BottomMargin = 50;
            barcode.Resolution = 96;

            // Image format setting
            barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;

            barcode.drawBarcode("W://Projects//Test-Output//OnBarcode.com//csharp-pdf417-macro.png");


PDF-417 Error detection and correction (ECL)

Top
Each PDF417 symbol contains at least two error correction codewords. The Error Correction codewords provide capability for both error detection and correction.

The error correction level for a PDF417 symbol is selectable at the time of symbol creation. The barcode software provides property "ECL". The following table shows the number of error correction codewords for each error correction level.

Error Correction Level Total Number of Error Correction Codewords
0 2
1 4
2 8
3 16
4 32
5 64
6 128
7 256
8 512




PDF-417 Barcode Property Settings
Top
.NET Barcode Generator library has included 20+ property settings to customize the generated PDF417 barcode images. You view the complete list of PDF147 barcode properties here.




Create PDF-417 Barcodes in C#
Top
View the complete C# source code to generate PDF-417 barcodes in C# .NET application
More C# Barcode Generation Tutorials for Each Barcode
Top

Barcode Control for C#.NET - Bar Code Type Generation

OnBarcode is a market-leading provider of barcode imaging generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides comprehensive tutorials and how-tos for various linear, 2d barcode information, such as C# in ASP.NET, C# .NET, C# Barcode Encoding, C# Barcode Image, VB.NET in ASP.NET, VB.NET Winforms, VB.NET Barcode Encoding. OnBarcode barcode products are supported by RasterEdge ASP.NET Document Viewer, which supports ASP.NET PDF Viewer, ASP.NET MVC Document Viewer, ASP.NET PDF Editor, MVC PDF Viewer. And provide high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.