使用 VintaSoft Barcode .NET SDK 识别和生成 PDF417 条形码

博客分类:条形码   .NET

2026/01/30

VintaSoft Barcode .NET SDK 是一款专业的跨平台 SDK,支持 Windows、Linux 和 macOS,可用于在 .NET、WPF、Web 和 MAUI 中识别和生成 PDF417 条形码。只需几行代码即可将识别和生成 PDF417 条形码的功能添加到您的 .NET 应用程序中。

什么是 PDF417 条形码?

PDF417 条形码是一种高密度、多层二维条形码,用于存储大量数据(最多 1850 个字符或 1108 字节)。 PDF417条形码发明于1991年,广泛应用于政府身份证件、登机牌和物流等领域。它采用4条/4个空格、每个码字17个元素的模式,支持内置纠错功能,并提供紧凑可靠的数据存储。

以下是PDF417条形码的图像:


PDF417条形码支持以下数据存储模式:

PDF417条形码采用里德-所罗门纠错算法,可以识别损坏的PDF417条形码。

PDF417条形码可以编码以下特殊字符:

PDF417条形码结构

PDF417条形码由多个模块组成,这些模块可以分为三个不同的组:



每个模块以黑色实心列开始,以白色实心列结束,从而直观地指示每个模块的起始和结束位置。条形码两侧还有空白区域。被称为静默区。

起始和停止搜索模式 指示条形码的起始和结束区域。它们帮助条形码扫描器检测条形码,但不包含任何数据。

左侧和右侧指示器 包含有关条形码的信息,例如条形码中的行数、纠错级别等。

数据码字模块 包含条形码数据。PDF417条形码的大小取决于编码的数据量。 数据码字模块 可以包含1到30个码字和3到90行。在上图中,数据码字模块( 数据码字模块 每行包含4个 码字 ,以紫色标记。在上图中, 数据码字模块 )由 4 行组成。每个码字(

每个 码字 长17个单元格,由4条黑色条纹和4个白色单元格组成,因此得名PDF417。每个数据 码字 从左到右、从上到下读取。


什么是PDF417 Compact条形码?

PDF417紧凑型条形码是PDF417条形码的变体,它移除了右指示符和停止搜索模式以节省空间。
这是 PDF417 Compact 条形码的图片:



什么是Micro PDF417条形码?

Micro PDF417 条形码是 PDF417 条形码的紧凑版本。Micro PDF417 条形码通常用作复合码(例如 GS1 DataBar)的一部分,用于产品标签、文档标签和医疗保健应用:


Micro PDF417 条形码支持以下数据存储模式:

Micro PDF417 条形码可以编码以下特殊字符:

什么是AAMVA条形码?

AAMVA(驾照/身份证设计标准)条形码--这是一种存储驾驶执照信息的PDF417条形码。 VintaSoft Barcode .NET SDK 可以对 AAMVA 格式的数据进行编码和解码。
以下是 AAMVA 条形码的图像:



什么是"XFA Compressed PDF417"条形码?

"XFA Compressed PDF417"条形码是一种 PDF417 条形码,它存储的数据根据​Adobe XFA 规范进行压缩。 VintaSoft Barcode .NET SDK 可以生成和识别"XFA Compressed PDF417"条形码。
以下是"XFA Compressed QR"条形码的图像:



特殊字符"Structure Append"

PDF417 条形码支持特殊字符"结构附加",它允许将数据拆分成多个(最多 99,999 个)PDF417 条形码。特殊字符"结构附加"编码在条形码中,用于唯一标识条形码部分的数量及其顺序。

以下是一个 PDF417 条形码的图像,其中包含文本"为了适应非正方形区域或处理比单个符号实际更大的消息,数据消息可以分布在多个符号上。Aztec、Code 16K、DataMatrix、DotCode、MaxiCode、QR 码、PDF417 和 Micro PDF417 符号可以以结构化格式附加。":

这里有五个 PDF417 条形码,文本相同,但尺寸较小。这五个 PDF417 条形码使用特殊字符"Structure Append"组合成一个值。":

VintaSoft Barcode .NET SDK 包含一种算法,用于从一组使用特殊字符"Structure Append"分隔的 PDF417 条形码部分中恢复数据。


VintaSoft Barcode .NET SDK 可以识别哪些 PDF417 条形码?

VintaSoft Barcode .NET SDK 可以识别所有类型的 PDF417 条形码:PDF417、PDF417 Compact、Micro PDF417、AAMVA 和 XFA Compressed PDF417。 VintaSoft Barcode .NET SDK 采用独特的算法进行识别,能够快速识别各种图像中的条形码:



以下 C# 代码演示了如何识别相机拍摄图像中的 PDF417 条形码:
/// <summary>
/// Reads PDF417 barcodes from a <see cref="System.Drawing.Bitmap"/>.
/// </summary>
/// <param name="bitmap">A bitmap with barcodes.</param>
public static void ReadPdf417BarcodesFromBitmap(System.Drawing.Bitmap bitmap)
{
    // create barcode reader
    using (Vintasoft.Barcode.BarcodeReader reader = new Vintasoft.Barcode.BarcodeReader())
    {
        // specify that reader must search for PDF417 barcodes
        reader.Settings.ScanBarcodeTypes = Vintasoft.Barcode.BarcodeType.PDF417;

        // read barcodes from image
        Vintasoft.Barcode.IBarcodeInfo[] infos = Vintasoft.Barcode.GdiExtensions.ReadBarcodes(reader, bitmap);

        // if barcodes are not detected
        if (infos.Length == 0)
        {
            System.Console.WriteLine("No barcodes found.");
        }
        // if barcodes are detected
        else
        {
            // get information about extracted barcodes

            System.Console.WriteLine(string.Format("{0} barcodes found:", infos.Length));
            System.Console.WriteLine();
            for (int i = 0; i < infos.Length; i++)
            {
                Vintasoft.Barcode.IBarcodeInfo info = infos[i];
                System.Console.WriteLine(string.Format("[{0}:{1}]", i + 1, info.BarcodeType));
                System.Console.WriteLine(string.Format("Value:      {0}", info.Value));
                System.Console.WriteLine(string.Format("Region:     {0}", info.Region));
                System.Console.WriteLine();
            }
        }
    }
}


以下 C# 代码演示了如何生成和识别 AAMVA 条形码:
/// <summary>
/// Generates and recognizes AAMVA barcode.
/// </summary>
public static void GenerateAndRecognizeAamvaBarcode()
{
    // create DL data elements
    AamvaDataElement[] dlElements = new AamvaDataElement[] {
        new AamvaDataElement(AamvaDataElementIdentifiers.DAQ, "C12345678"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DCS, "CARPENTER"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DDE, "N"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DAC, "JON"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DDF, "N"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DAD, "T"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DDG, "N"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DCA, "D"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DCB, "1"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DCD, "NONE"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DBD, "10052015"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DBB, "07241984"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DBA, "01092022"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DBC, "1"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DAU, "067 in"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DAY, "BLK"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DAG, "3211 SANCTUARY LANE"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DAI, "LOUISVILLE"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DAJ, "KY"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DAK, "123454321"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DCF, "9876543210123456"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DCG, "USA"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DCK, "1234567890123456"),
        new AamvaDataElement(AamvaDataElementIdentifiers.DDB, "01062016")
    };

    // create ZK data elements
    AamvaDataElement[] zkElements = new AamvaDataElement[] {
        new AamvaDataElement("ZKA", "Y"),
        new AamvaDataElement("ZKB", "TEST"),
        new AamvaDataElement("ZKC", "9876"),
        new AamvaDataElement("ZKD", "DUP"),
    };

    // create subfiles
    AamvaSubfile[] subfiles = new AamvaSubfile[]{
        new AamvaSubfile("DL", dlElements),
        new AamvaSubfile("ZK", zkElements)
    };
    
    // create AAMVA barcode value
    AamvaBarcodeValue barcodeValue = new AamvaBarcodeValue(AamvaVersionLevel.AAMVA2016, 636046, 0, subfiles);
    
    // generate barcode image
    using (VintasoftBitmap barcodeImage = GenerateAamvaBarcode(barcodeValue))
    {
        // recognize barcode value
        AamvaBarcodeInfo recognizedBarcode = RecognizeAamvaBarcode(barcodeImage);

        // check value
        if (barcodeValue.ToString() != recognizedBarcode.AamvaValue.ToString())
            throw new ApplicationException();

        // print value
        Console.WriteLine("Version:         {0}", recognizedBarcode.VersionLevel);
        Console.WriteLine("Country:         {0}", recognizedBarcode.CountryId);
        Console.WriteLine("IIN:             {0}", recognizedBarcode.IssuerIdentificationNumber);
        Console.WriteLine("License number:  {0}", recognizedBarcode.LicenseNumber);
        Console.WriteLine("First name:      {0}", recognizedBarcode.FirstName);
        Console.WriteLine("Family name:     {0}", recognizedBarcode.FamilyName);
        Console.WriteLine("Middle name:     {0}", recognizedBarcode.MiddleName);
        Console.WriteLine("Sex (1=M;2=F):   {0}", recognizedBarcode.Sex);
        Console.WriteLine("Eye color:       {0}", recognizedBarcode.EyeColor);            
        Console.WriteLine("Date of birth:   {0}", recognizedBarcode.DateOfBirth.ToShortDateString());
        Console.WriteLine("Issue date:      {0}", recognizedBarcode.IssueDate.ToShortDateString());
        Console.WriteLine("Expiration date: {0}", recognizedBarcode.ExpirationDate.ToShortDateString());
        Console.WriteLine("State code:      {0}", recognizedBarcode.AddressStateCode);
        Console.WriteLine("City:            {0}", recognizedBarcode.AddressCity);
        Console.WriteLine("Postal code:     {0}", recognizedBarcode.AddressPostalCode);
        Console.WriteLine("Street:          {0}", recognizedBarcode.AddressStreet1);
        Console.WriteLine();
        Console.WriteLine("Data elements:");
        foreach (AamvaSubfile subfile in recognizedBarcode.Subfiles)
        {
            Console.WriteLine("[{0}] subfile:", subfile.SubfileType);
            foreach (AamvaDataElement dataElement in subfile.DataElements)
            {
                if (dataElement.Identifier.VersionLevel != AamvaVersionLevel.Undefined)
                    Console.Write("  [{0}] {1}:", dataElement.Identifier.ID, dataElement.Identifier.Description);
                else
                    Console.Write("  [{0}]:", dataElement.Identifier.ID);
                Console.WriteLine(" {0}", dataElement.Value);
            }
        }
    }
}

/// <summary>
/// Generates the AAMVA barcode image.
/// </summary>
/// <param name="barcodeValue">The barcode value.</param>
private static VintasoftBitmap GenerateAamvaBarcode(AamvaBarcodeValue barcodeValue)
{
    // create barcode writer
    using (BarcodeWriter writer = new BarcodeWriter())
    {
        // encode AAMVA barcode to writer settings
        BarcodeSymbologySubsets.AAMVA.Encode(barcodeValue, writer.Settings);

        // generate barcode image
        return writer.GetBarcodeAsVintasoftBitmap();
    }
}

/// <summary>
/// Recognizes the AAMVA barcode from image.
/// </summary>
/// <param name="barcodeImage">The barcode image.</param>
private static AamvaBarcodeInfo RecognizeAamvaBarcode(VintasoftBitmap barcodeImage)
{
    // create barcode reader
    using (BarcodeReader reader = new BarcodeReader())
    {
        // specify that AAMVA barcode must be recognized
        reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.AAMVA);

        // recognize barcodes
        IBarcodeInfo info = reader.ReadBarcodes(barcodeImage)[0];

        // return information about recognized AAMVA barcode
        return (AamvaBarcodeInfo)info;
    }
}


以下 C# 代码演示了如何生成和识别 PDF417 条形码,该条形码存储的数据根据​​ Adob​​e XFA 规范进行压缩:
/// <summary>
/// Generates PDF417 barcode with XFA compression.
/// </summary>
public void GeneratePdf417BarcodeWithXfaCompression()
{
    string barcodeText =
        "https://www.vintasoft.com/vsbarcode-dotnet-index.html" + System.Environment.NewLine +
        "https://www.vintasoft.com/vstwain-dotnet-index.html" + System.Environment.NewLine +
        "https://www.vintasoft.com/vstwain-index.html" + System.Environment.NewLine +
        "https://www.vintasoft.com/vsimaging-dotnet-index.html" + System.Environment.NewLine +
        "https://www.vintasoft.com/vsannotation-dotnet-index.html" + System.Environment.NewLine +
        "https://www.vintasoft.com/vspdf-dotnet-index.html" + System.Environment.NewLine +
        "https://www.vintasoft.com/vsjbig2-dotnet-index.html" + System.Environment.NewLine +
        "https://www.vintasoft.com/vsjpeg2000-dotnet-index.html" + System.Environment.NewLine +
        "https://www.vintasoft.com/vsdoccleanup-dotnet-index.html" + System.Environment.NewLine +
        "https://www.vintasoft.com/vsocr-dotnet-index.html" + System.Environment.NewLine +
        "https://www.vintasoft.com/vsdicom-dotnet-index.html" + System.Environment.NewLine +
        "https://www.vintasoft.com/vsformsprocessing-dotnet-index.html" + System.Environment.NewLine +
        "https://www.vintasoft.com/vsoffice-dotnet-index.html";

    // create the barcode writer
    using (Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter())
    {
        // create the XFA compressed PDF417 barcode symbology
        Vintasoft.Barcode.SymbologySubsets.XFACompressedPDF417BarcodeSymbology xfaCompressedPdf417BarcodeSymbology =
            new Vintasoft.Barcode.SymbologySubsets.XFACompressedPDF417BarcodeSymbology();
        // encode barcode text using XFA compressed PDF417 barcode symbology
        xfaCompressedPdf417BarcodeSymbology.Encode(barcodeText, barcodeWriter.Settings);

        // save the barcode image to a file
        barcodeWriter.SaveBarcodeAsImage("pdf417-barcode-with-xfa-compression.png");
    }
}

/// <summary>
/// Recognizes PDF417 barcode with XFA compression.
/// </summary>
public void RecognizePdf417BarcodeWithXfaCompression()
{
    // create barcode reader
    using (Vintasoft.Barcode.BarcodeReader reader = new Vintasoft.Barcode.BarcodeReader())
    {
        // specify that reader must search for XFA compressed PDF417 barcodes
        reader.Settings.ScanBarcodeSubsets.Add(Vintasoft.Barcode.SymbologySubsets.BarcodeSymbologySubsets.XFACompressedPDF417);

        // read barcodes from image file
        Vintasoft.Barcode.IBarcodeInfo[] barcodeInfos = reader.ReadBarcodes("pdf417-barcode-with-xfa-compression.png");

        // if barcodes are not detected
        if (barcodeInfos.Length == 0)
        {
            System.Console.WriteLine("Barcodes are not found.");
        }
        // if barcodes are detected
        else
        {
            // get information about recognized barcodes

            System.Console.WriteLine(string.Format("{0} barcode(s) found:", barcodeInfos.Length));
            System.Console.WriteLine();
            for (int i = 0; i < barcodeInfos.Length; i++)
            {
                Vintasoft.Barcode.IBarcodeInfo barcodeInfo = barcodeInfos[i];
                System.Console.WriteLine(string.Format("[{0}:{1}]", i + 1, barcodeInfo.BarcodeType));
                System.Console.WriteLine(string.Format("Value:      {0}", barcodeInfo.Value));
                System.Console.WriteLine(string.Format("Region:     {0}", barcodeInfo.Region));
                System.Console.WriteLine();
            }
        }
    }
}


VintaSoft Barcode .NET SDK 可以生成哪些 PDF417 条形码?

VintaSoft Barcode .NET SDK 可生成所有类型的 PDF417 条形码:PDF417、PDF417 Compact、Micro PDF417、AAMVA 和 XFA Compressed PDF417。

以下 C# 代码演示了如何生成 PDF417 条形码的位图图像:
/// <summary>
/// Returns the PDF417 barcode as <see cref="System.Drawing.Bitmap"/>.
/// </summary>
/// <param name="value">The barcode value.</param>
/// <returns>A <see cref="System.Drawing.Bitmap"/> object.</returns>
public static System.Drawing.Bitmap GetPdf417BarcodeAsBitmap(string value)
{
    // create the barcode writer
    using (Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter())
    {
        // set barcode writer settings
        barcodeWriter.Settings.Barcode = Vintasoft.Barcode.BarcodeType.PDF417;
        barcodeWriter.Settings.Value = value;

        // get a barcode image as System.Drawing.Bitmap
        return Vintasoft.Barcode.GdiExtensions.GetBarcodeAsBitmap(barcodeWriter);
    }
}


以下 C# 代码演示了如何生成 Micro PDF417 条形码的位图图像:
/// <summary>
/// Returns the Micro PDF417 barcode as <see cref="System.Drawing.Bitmap"/>.
/// </summary>
/// <param name="value">The barcode value.</param>
/// <returns>A <see cref="System.Drawing.Bitmap"/> object.</returns>
public static System.Drawing.Bitmap GetMicroPdf417BarcodeAsBitmap(string value)
{
    // create the barcode writer
    using (Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter())
    {
        // set barcode writer settings
        barcodeWriter.Settings.Barcode = Vintasoft.Barcode.BarcodeType.MicroPDF417;
        barcodeWriter.Settings.Value = value;

        // get a barcode image as System.Drawing.Bitmap
        return Vintasoft.Barcode.GdiExtensions.GetBarcodeAsBitmap(barcodeWriter);
    }
}


以下 C# 代码演示了如何生成 PDF417 条形码的矢量 (SVG) 图像:
/// <summary>
/// Returns the PDF417 barcode in vector form as a SVG string.
/// </summary>
/// <param name="barcodeValue">Barcode value.</param>
public static void GetPdf417BarcodeAsSvgString(string barcodeValue)
{
    // create the barcode writer
    using (Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter())
    {
        // set barcode writer settings
        barcodeWriter.Settings.Barcode = Vintasoft.Barcode.BarcodeType.PDF417;
        barcodeWriter.Settings.Value = barcodeValue;

        // generate PDF417 barcode as a SVG string
        return barcodeWriter.GetBarcodeAsSvgFile();
    }
}