PDF417 barcodes are widely used in various industries such as transport, logistics, and identity management due to their high data capacity and robust error correction capabilities. This article will guide you through the process of generating PDF417 barcodes using Aspose.BarCode for .NET.

Introduction

PDF417 is a stacked 2D barcode that can encode up to 1,850 bytes of data per symbol, making it ideal for applications requiring large amounts of information. This tutorial will walk you through the process of generating PDF417 barcodes programmatically using Aspose.BarCode for .NET.

Setting Up Your Environment

Before diving into code examples, ensure your development environment is properly set up:

Prerequisites

  • Visual Studio 2019 or later
  • .NET 6.0 or later (or .NET Framework 4.6.2+)
  • Aspose.BarCode for .NET installed via NuGet

Install the package using the following command in your Package Manager Console:

PM> Install-Package Aspose.BarCode

Step-by-Step Implementation

Step 1: Create and Configure BarcodeGenerator

First, create an instance of BarcodeGenerator and specify the type as PDF417.

BarcodeGenerator barcodeGenerator = new BarcodeGenerator(EncodeTypes.Pdf417, "PASSENGER: SMITH/JANE\nFLIGHT: 1234\nDATE: 2025-06-18");

Step 2: Customize PDF417 Settings

Adjust various properties such as rows, columns, error correction level, and color settings to fit your requirements.

// Set number of rows and columns
barcodeGenerator.Parameters.Barcode.Pdf417.Pdf417Rows = 10;
barcodeGenerator.Parameters.Barcode.Pdf417.Pdf417Columns = 4;
// Set error correction level (0-8, higher is stronger)
barcodeGenerator.Parameters.Barcode.Pdf417.Pdf417ErrorLevel = Pdf417ErrorLevel.Level5;
// Optional: Set XDimension (pixel size)
barcodeGenerator.Parameters.Barcode.XDimension.Pixels = 4;
// Optional: Set foreground and background color
barcodeGenerator.Parameters.Barcode.BarColor = Color.Black;
barcodeGenerator.Parameters.Barcode.BackColor = Color.White;

Step 3: Generate and Save the Barcode Image

Finally, save the generated barcode image to a file or stream.

barcodeGenerator.Save("boarding-pass-pdf417.png", BarCodeImageFormat.Png);

Complete Example

Here is the complete example that ties everything together:

Use Cases and Applications

  • Boarding passes: Airlines and transport tickets
  • ID cards and credentials: Machine-readable identity, licenses
  • Logistics and inventory: Shipment and warehouse labels

Common Challenges and Solutions

Challenge 1: PDF417 not scanning? Solution: Use sufficient error correction, match rows/columns to data size, verify module size for scanners.

Challenge 2: Data too large? Solution: Increase barcode size, tune rows/columns, or split data.

Challenge 3: Blurry or low-res image? Solution: Export at higher pixel size or DPI for print use.

Performance Considerations

  • Use the right error correction for application criticality
  • Batch generate PDF417 for passenger lists or shipment manifests
  • Use memory streams for in-memory barcode export

Best Practices

  1. Tune rows and columns for data and label size
  2. Test with certified PDF417 scanners/devices
  3. Export to PNG for print, JPEG for digital display
  4. Keep data text structured and concise

Advanced Scenarios

1. Batch Generate PDF417 Barcodes

foreach (var ticket in tickets)
{
    BarcodeGenerator g = new BarcodeGenerator(EncodeTypes.Pdf417, ticket.Data);
    g.Save($"pdf417_{ticket.Id}.png", BarCodeImageFormat.Png);
}

2. Set PDF417 Compaction and Macro Modes

// Set compaction mode for numeric, text, or binary data
barcodeGenerator.Parameters.Barcode.Pdf417.Pdf417CompactionMode = Pdf417CompactionMode.Text;
// Enable macro PDF417 for segmented/barcoded documents
barcodeGenerator.Parameters.Barcode.Pdf417.Pdf417MacroFileID = 12345;

Conclusion

Aspose.BarCode for .NET empowers you to create PDF417 barcodes for transport, ID, and inventory applications, with advanced control over format and security. See more in the Aspose.BarCode API Reference.

More in this category