C# PDF-417 Barcode Generator Library
C# PDF 417 Barcode Writing Guide


Tutorial for PDF-417 Barcode Generator for C#.NET Imaging Application





C# PDF417 Generator Add-On Overview



This PDF 417 bar code generator for Visual C# is actually a composing functionality of RasterEdge DocImage SDK for .NET. It is a fully-featured barcode add-on library DLL written in C#.NET for developers to quickly add PDF-417 barcodes on image formats including PNG, JPG, GIF, BMP, as well as other file formats such TIFF, PDF, Microsoft Office Word, Excel and PowerPoint.


Related .net document control helps:
asp.net image viewer: ASP.NET Image Viewer Control(MVC & WebForms): view, annotate, redact, convert image files in html, JQuery
asp.net mvc document viewer: ASP.NET MVC Document Viewer: view, annotate, redact files on ASP.NET MVC web projects
asp.net document viewer: EdgeDoc:ASP.NET Document Viewer C# Control: Open, view, annotate, redact, convert documents online in C#, VB.NET, AS...
asp.net excel viewer: ASP.NET Excel Viewer in C# Control (MVC & WebForms): view Office Excel document in web browser.
asp.net pdf editor: EdgePDF: ASP.NET PDF Editor Web Control: Online view, annotate, redact, edit, process, convert PDF documents
asp.net pdf viewer: ASP.NET PDF Viewer Control: view, navigate, zoom Adobe PDF document in C# ASP.NET
asp.net powerpoint viewer: ASP.NET PowerPoint Document Viewer Control (MVC & WebForms): view ppt, pptx files online in C# using ASP.NET


Detailed features are listed below:


Create two-dimensional PDF-417 barcodes in .NET Windows Forms projects


Streaming PDF-417 2D bar code images in ASP.NET web form/web site


Write & draw PDF-417 on various raster image formats and .pdf, .docx, .xlsx, .pptx files using C# language


Provide detailed tutorial for PDF-417 generation with Visual C# sample codes


Support creating C# PDF-417, Macro PDF 417, PDF 417 Truncated (Composite PDF 417)




C# Code for Customizing PDF417 Barcode Generation



You can easily generator PDF417 barcode and save it  to image files/object using this C#.NET barcode generator control. The following steps will show how to create a PDF417 type barcode encoding numeric data text "123456789" into the image object with XImage.Barcode.Creator.


Add References


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.BarcodeCreator.dll


  System.Drawing.dll


Using Namespaces


  using System.Drawing;


  using RasterEdge.XImage.BarcodeCreator;


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.


Please copy the sample code as follow to generator a PDF417 barcode.




private static PDF417 CreateBarcode()
        {
            PDF417 barcode = new PDF417();// create a Data Matrix barcode
            barcode.Data = "123456789";// encode data into Data Matrix barcode    
            barcode.X = 5.0F;// set module size
            barcode.RightMargin = barcode.LeftMargin = barcode.TopMargin = barcode.BottomMargin = barcode.X; // the minimum value for each margin should be equal to X
            barcode.Resolution = 96;// set barcode printing resolution   
            barcode.Rotate = Rotate.Rotate0;// set rotation
            barcode.BarcodeHeight = 200;
            barcode.BarcodeWidth = 200;
            barcode.AutoResize = true;

            //convert barcode to a bitmap and save it to image file
            //Bitmap bmp = barcode.ToImage();
            //bmp.Save(@"C:\barcode.bmp");

            return barcode;
        }





How to Create C# PDF 417 Barcode on Image



In order to create a PDF 417 bar code on images, you need to integrate .NET barcode generator component DLL into your C#.NET imaging project first. Below is the C# sample coding to draw PDF-417 at user-defined area on a png image. Please feel free to change the barcode location as you wish or shift image format to gif, jpeg or bmp.





private static void AddBarcodeToImage(PDF417 barcode)
        {
            REImage image = new REImage(inputDirectory + "Sample.png");
            barcode.DrawBarcode(image, 150F, 150F);
            image.Save(ImageType.PNG, outputDirectory + "Sample_Barcode.png");
        }





How to Insert C# PDF 417 Barcode on Document



Apart from generating & printing PDF-417 barcode in image editing project, this C#.NET PDF-417 generator library can also help you insert PDF-417 barcode into a PDF, TIFF, Word, Excel or PowerPoint document. View detailed Visual C# samples below.



Generate PDF 417 Barcode on PDF Using C# Code



Add References(Extra)


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Using Namespace(Extra)


  RasterEdge.XDoc.PDF;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;



private static void AddBarcodeToPDF(PDF417 barcode)
        {
            PDFDocument docx = new PDFDocument(inputDirectory + "Sample.pdf");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.pdf");
        }




Insert PDF 417 Barcode on TIFF with C# Code



Add References(Extra)


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.TIFF.dll


Using Namespace(Extra)


  RasterEdge.XDoc.TIFF;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;




private static void AddBarcodeToTIFF(PDF417 barcode)
        {
            TIFFDocument docx = new TIFFDocument(inputDirectory + "Sample.tif");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.tif");
        }




Create PDF 417 Barcode on Word in C# Code



Add References(Extra)


  RasterEdge.XDoc.Word.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner..Office03.dll


Using Namespace(Extra)


  RasterEdge.XDoc.Word;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;




private static void AddBarcodeToWord(PDF417 barcode)
        {
            DOCXDocument docx = new DOCXDocument(inputDirectory + "Sample.docx");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.docx");
        }




Generate PDF 417 Barcode Image on Excel in C#



Add References(Extra)


  RasterEdge.XDoc.Excel.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner..Office03.dll


Using Namespace(Extra)


  RasterEdge.XDoc.Excel;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;




private static void AddBarcodeToExcel(PDF417 barcode)
        {
            XLSXDocument docx = new XLSXDocument(inputDirectory + "Sample.xlsx");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.xlsx");
        }




Write PDF 417 Barcode Image on PowerPoint in C#



Add References(Extra)


  RasterEdge.XDoc.PowerPoint.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner..Office03.dll


Using Namespace(Extra)


  RasterEdge.XDoc.PowerPoint;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;




private static void AddBarcodeToPowerPoint(PDF417 barcode)
        {
            PPTXDocument docx = new PPTXDocument(inputDirectory + "Sample.pptx");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.pptx");
        }






Create, print PDF417 barcode with options using C#

PDF-417 Error detection and correction (ECL) in C#

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




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

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;

PDF417 barcode = new PDF417();
barcode.Data = "PDF417";
barcode.Truncated = true;
barcode.drawBarcode("C://Output//csharp-pdf417-truncated-demo.png");





Create Macro PDF417 barcodes using C#

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.drawBarcode("W://Projects//Test-Output//OnBarcode.com//csharp-pdf417-macro.png");








Common Asked Questions

What is PDF417 used for?

PDF417 is a high-density, stacked 2D barcode. It's used on official documents for storing significant personal data. Such as transportation (boarding passes), government-issued IDs, and inventory management systems. RasteEdge XImage PDF417 Generator C# library supports PDF417 and Micro PDF417 barcodes generation in ASP.NET Core, MVC, Blazor web app and console, WinForms, WPF desktop applications.

What is the key difference between PDF417 and QR Code?

PDF417 and QR Code are both 2D barcodes, but PDF417 is more robust. PDF417 remains scannable when up to half of it is damaged, whereas QR codes can handle only about 30%. C# PDF417 barcode generator library supports both PDF417 and QR Code (including Micro version) generation in C# Visual Studio .NET projects.

What is the maximum data capacity of a PDF417 barcode?

  • Text Compaction: Up to 1,850 characters.
  • Byte Compaction: Up to 1,108 characters.
  • Numeric Compaction: Up to 2,710 characters.
XImage.Barcode Generator C# library supports PDF417 generation with the above data formats and data length encoding in C# class.

How is the aspect ratio of a PDF417 determined?

It is defined by two parameters:
  • X: The narrowest bar/space width.
  • Y: The height of each row.
Using XImage PDF417 Barcode Generator C# library, you are able to customize the PDF417 with the target aspect ratio in C# ASP.NET Core, MVC, .NET Framework web applications.