How to Generate PDF417 Barcodes Using Aspose.BarCode for .NET
This article demonstrates how to generate PDF417 barcodes using Aspose.BarCode for .NET in C#. PDF417 is a stacked, high-density 2D barcode widely used for transport tickets, boarding passes, ID cards, and inventory management.
Real-World Problem
PDF417 barcodes are required by airlines, logistics providers, and government agencies for encoding large volumes of data in a secure, machine-readable format. Generating PDF417 manually is error-prone, and few barcode tools support batch, automation, or .NET workflows.
Solution Overview
Aspose.BarCode for .NET lets you generate PDF417 barcodes programmatically with full control over rows, columns, error correction, and export format—ideal for digital passes, shipment labels, or credentials.
Prerequisites
Before you start, ensure you have:
- Visual Studio 2019 or later
- .NET 6.0 or later (or .NET Framework 4.6.2+)
- Aspose.BarCode for .NET installed via NuGet
- Basic knowledge of C#
PM> Install-Package Aspose.BarCode
Step-by-Step Implementation
Step 1: Install and Import Aspose.BarCode
Install the NuGet package and import the required namespaces:
using Aspose.BarCode.Generation;
Step 2: Create the PDF417 Barcode Generator
Instantiate the generator for PDF417:
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Pdf417, "PASSENGER: SMITH/JANE\nFLIGHT: 1234\nDATE: 2025-06-18");
Step 3: Customize PDF417 Settings
Adjust rows, columns, ECC, or style as needed:
// Set number of rows and columns
generator.Parameters.Barcode.Pdf417.Pdf417Rows = 10;
generator.Parameters.Barcode.Pdf417.Pdf417Columns = 4;
// Set error correction level (0-8, higher is stronger)
generator.Parameters.Barcode.Pdf417.Pdf417ErrorLevel = Pdf417ErrorLevel.Level5;
// Optional: Set XDimension (pixel size)
generator.Parameters.Barcode.XDimension.Pixels = 4;
// Optional: Set foreground and background color
generator.Parameters.Barcode.BarColor = Color.Black;
generator.Parameters.Barcode.BackColor = Color.White;
Step 4: Generate and Save the PDF417 Barcode
Export the barcode to PNG, JPEG, or any supported format:
generator.Save("boarding-pass-pdf417.png", BarCodeImageFormat.Png);
Step 5: Complete Example
using Aspose.BarCode.Generation;
using System.Drawing; // Required for Color
class Program
{
static void Main()
{
// Create PDF417 generator for transport data
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Pdf417, "PASSENGER: SMITH/JANE\nFLIGHT: 1234\nDATE: 2025-06-18");
generator.Parameters.Barcode.Pdf417.Pdf417Rows = 10;
generator.Parameters.Barcode.Pdf417.Pdf417Columns = 4;
generator.Parameters.Barcode.Pdf417.Pdf417ErrorLevel = Pdf417ErrorLevel.Level5;
generator.Parameters.Barcode.XDimension.Pixels = 4;
generator.Parameters.Barcode.BarColor = Color.Black;
generator.Parameters.Barcode.BackColor = Color.White;
generator.Save("boarding-pass-pdf417.png", BarCodeImageFormat.Png);
// Test with a PDF417 scanner
}
}
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
- Tune rows and columns for data and label size
- Test with certified PDF417 scanners/devices
- Export to PNG for print, JPEG for digital display
- 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
generator.Parameters.Barcode.Pdf417.Pdf417CompactionMode = Pdf417CompactionMode.Text;
// Enable macro PDF417 for segmented/barcoded documents
generator.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 .