How to Generate Micro, Compact, and Macro PDF417 Barcodes .NET
This article covers how to generate Micro PDF417, Compact PDF417, and Macro PDF417 barcodes in .NET applications using Aspose.BarCode. These variants offer space-saving, high-capacity, and multi-segment features ideal for labeling, documentation, and data transfer.
Real-World Problem
Standard PDF417 barcodes can be too large for some products or labels, and sometimes information needs to be split across multiple barcodes or encoded in a highly compact format for regulatory or operational reasons.
Solution Overview
Aspose.BarCode for .NET lets developers generate all PDF417 variants programmatically. You can create:
- Micro PDF417: For very small labels with reduced data and size.
- Compact PDF417: Optimized for size without loss of capacity.
- Macro PDF417: Splits large data across multiple barcode symbols with file/segment metadata.
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
using Aspose.BarCode.Generation;
Step 2: Create the PDF417 Variant Generator
Micro PDF417
BarcodeGenerator microGen = new BarcodeGenerator(EncodeTypes.MicroPdf417, "Micro data");
microGen.Parameters.Barcode.XDimension.Pixels = 4;
Compact PDF417:
BarcodeGenerator compactGen = new BarcodeGenerator(EncodeTypes.CompactPdf417, "Compact info");
compactGen.Parameters.Barcode.XDimension.Pixels = 4;
Macro PDF417:
BarcodeGenerator macroGen = new BarcodeGenerator(EncodeTypes.MacroPdf417, "Segmented large dataset");
macroGen.Parameters.Barcode.Pdf417.Pdf417MacroFileID = 123;
macroGen.Parameters.Barcode.Pdf417.Pdf417MacroSegmentID = 1;
macroGen.Parameters.Barcode.Pdf417.Pdf417MacroSegmentsCount = 3;
macroGen.Parameters.Barcode.XDimension.Pixels = 4;
Step 3: Adjust Rows, Columns, and ECC
Customize as needed:
microGen.Parameters.Barcode.Pdf417.Pdf417Rows = 4;
microGen.Parameters.Barcode.Pdf417.Pdf417Columns = 2;
compactGen.Parameters.Barcode.Pdf417.Pdf417ErrorLevel = Pdf417ErrorLevel.Level2;
macroGen.Parameters.Barcode.Pdf417.Pdf417ErrorLevel = Pdf417ErrorLevel.Level4; ```
---
### Step 4: Save and Test the Barcode Output
```cs
microGen.Save("micro-pdf417.png", BarCodeImageFormat.Png);
compactGen.Save("compact-pdf417.png", BarCodeImageFormat.Png);
macroGen.Save("macro-pdf417-segment1.png", BarCodeImageFormat.Png);
Step 5: Complete Example (All PDF417 Variants)
using Aspose.BarCode.Generation;
using System.Drawing;
class Program
{
static void Main()
{
// Micro PDF417
BarcodeGenerator microGen = new BarcodeGenerator(EncodeTypes.MicroPdf417, "Micro data");
microGen.Parameters.Barcode.XDimension.Pixels = 4;
microGen.Parameters.Barcode.Pdf417.Pdf417Rows = 4;
microGen.Parameters.Barcode.Pdf417.Pdf417Columns = 2;
microGen.Save("micro-pdf417.png", BarCodeImageFormat.Png);
// Compact PDF417
BarcodeGenerator compactGen = new BarcodeGenerator(EncodeTypes.CompactPdf417, "Compact info");
compactGen.Parameters.Barcode.XDimension.Pixels = 4;
compactGen.Parameters.Barcode.Pdf417.Pdf417ErrorLevel = Pdf417ErrorLevel.Level2;
compactGen.Save("compact-pdf417.png", BarCodeImageFormat.Png);
// Macro PDF417 (segment 1 of 3)
BarcodeGenerator macroGen = new BarcodeGenerator(EncodeTypes.MacroPdf417, "Segmented large dataset");
macroGen.Parameters.Barcode.Pdf417.Pdf417MacroFileID = 123;
macroGen.Parameters.Barcode.Pdf417.Pdf417MacroSegmentID = 1;
macroGen.Parameters.Barcode.Pdf417.Pdf417MacroSegmentsCount = 3;
macroGen.Parameters.Barcode.XDimension.Pixels = 4;
macroGen.Parameters.Barcode.Pdf417.Pdf417ErrorLevel = Pdf417ErrorLevel.Level4;
macroGen.Save("macro-pdf417-segment1.png", BarCodeImageFormat.Png);
}
}
Use Cases and Applications
- Micro PDF417: Small product labels, compact packaging
- Compact PDF417: Document tagging, compact supply chain barcodes
- Macro PDF417: Split data for forms, manifests, or regulatory multi-part documents
Common Challenges and Solutions
Challenge 1: Not enough data capacity? Solution: Use Macro PDF417 with segments for very large data sets.
Challenge 2: Output unreadable or too small? Solution: Increase module (pixel) size, adjust rows/columns for space/data.
Challenge 3: Multi-segment file reconstruction? Solution: Use unique MacroFileID and matching segment IDs/count for proper reassembly.
Performance Considerations
- Choose the right PDF417 variant for your application size/space
- Batch generate Micro/Compact/Macro barcodes as needed
- Use memory streams for integration with digital workflows
Best Practices
- Test all PDF417 output with physical scanners or compliance validators
- Use Macro for splitting large files/documents
- Document segment IDs for Macro PDF417 use
- Export PNG at high DPI for small or detailed labels
Advanced Scenarios
1. Batch Generate All PDF417 Variants
foreach (var doc in documents)
{
BarcodeGenerator g = new BarcodeGenerator(EncodeTypes.MacroPdf417, doc.SegmentData);
g.Parameters.Barcode.Pdf417.Pdf417MacroFileID = doc.FileID;
g.Parameters.Barcode.Pdf417.Pdf417MacroSegmentID = doc.SegmentID;
g.Parameters.Barcode.Pdf417.Pdf417MacroSegmentsCount = doc.TotalSegments;
g.Save($"macro_{doc.FileID}_segment{doc.SegmentID}.png", BarCodeImageFormat.Png);
}
Conclusion
Aspose.BarCode for .NET makes it easy to generate all PDF417 variants—Micro, Compact, and Macro—for packaging, documentation, regulatory, and digital workflows. See the Aspose.BarCode API Reference for details.