Migrate from Legacy Barcode Generation API
- 3 minutes to read
The Barcode Generation API contains the new DevExpress.Docs.Barcode and legacy DevExpress.BarCodes namespaces.
This topic helps you migrate existing barcode generation code from legacy types to the new API. Use the new API for new projects and for long-term maintenance.
To migrate from the DevExpress.BarCodes namespace to DevExpress.Docs.Barcode, follow the steps below:
Reference the
DevExpress.Docs.BarcodeNuGet package. To do this, you can call the following command:dotnet add package DevExpress.Docs.BarcodeIf you do not use any Office & PDF File API libraries other than barcodes, remove the
DevExpress.Document.ProcessorNuGet package reference.Replace
using DevExpress.BarCodes;withusing DevExpress.Docs.Barcode;or add the new namespace and update type names:Replace legacy types with the new counterparts listed in the table below.
- Verify barcode output in a sample set (scan results, module size, quiet zones, and checksum behavior).
Basic Migration Example
Legacy
using DevExpress.Docs.Barcode;
using DevExpress.Drawing;
// Create an Aztec Code.
BarCode barCode = new BarCode();
barCode.Symbology = Symbology.AztecCode;
barCode.CodeText = "0123-456789";
barCode.Options.AztecCode.ErrorLevel = AztecCodeErrorLevel.Level1;
barCode.Options.AztecCode.Version = AztecCodeVersion.Version45x45;
// Save the barcode as an image.
barCode.Save("BarCodeImage.png", DXImageFormat.Png);
New API
using DevExpress.Docs.Barcode;
using DevExpress.Drawing;
// Create an Aztec Code.
var aztecOptions = new AztecCodeOptions();
aztecOptions.CompactionMode = AztecCodeCompactionMode.Text;
aztecOptions.ErrorCorrectionLevel = AztecCodeErrorCorrectionLevel.Level1;
aztecOptions.Version = AztecCodeVersion.Version45x45;
using var aztecOptionsStream = new FileStream(Path.Combine(outDir,
"BarCodeImage.png"), FileMode.Create, FileAccess.Write);
using var aztecOptionsGenerator = new BarcodeGenerator(aztecOptions);
aztecOptionsGenerator.Export("0123-456789", aztecOptionsStream, DXImageFormat.Png);
Fluent API Example (New API Only)
Legacy API does not include Fluent API builders. Use them only with the new namespace:
using DevExpress.Docs.Barcode;
using DevExpress.Drawing;
using System.Drawing;
var aztekOptions = AztecCodeOptionsBuilder.Create()
.WithCompactionMode(AztecCodeCompactionMode.Text)
.WithErrorCorrectionLevel(AztecCodeErrorCorrectionLevel.Level1)
.WithVersion(AztecCodeVersion.Version45x45)
.Build();
var filePath = Path.GetFullPath("aztec_barcode.png");
using var stream = new FileStream(filePath, FileMode.Create);
using var generator = new BarcodeGenerator(aztekOptions);
generator.Export("0123-456789", stream, DXImageFormat.Png);
Symbology Type Renames
The table below lists types available in the DevExpress.BarCodes namespace and their DevExpress.Docs.Barcode counterparts.
Common Property Renames
| Legacy | New |
|---|---|
CalcCheckSum |
CalculateChecksum |
ErrorLevel |
ErrorCorrectionLevel |
Margins |
Margin |
Module |
ModuleSize |
Paddings |
Padding |