Reconnaître et générer des codes-barres PDF417 à l'aide du VintaSoft Barcode .NET SDK

Catégorie du blog: Code-barres.NET

30.01.2026

VintaSoft Barcode .NET SDK est un SDK professionnel multiplateforme pour Windows, Linux et macOS qui permet de reconnaître et de générer des codes-barres PDF417 dans les applications .NET, WPF, Web et MAUI. Quelques lignes de code suffisent pour intégrer cette fonctionnalité à votre application .NET.

Qu'est-ce qu'un code-barres PDF417?

Le code-barres PDF417 est un code-barres 2D multicouche haute densité utilisé pour stocker de grandes quantités de données (jusqu'à 1 850 caractères ou 1 108 octets). Inventé en 1991, il est largement utilisé pour les cartes d'identité gouvernementales, les cartes d'embarquement et dans la logistique. Il utilise un motif de 4 barres/4 espaces, 17 éléments par mot de code, prend en charge la correction d'erreurs intégrée et offre un stockage de données compact et fiable.

Voici l'image du code-barres PDF417:


Le code-barres PDF417 prend en charge les modes de stockage de données suivants:

Le code-barres PDF417 utilise l'algorithme de correction d'erreurs Reed-Solomon.ce qui nous permet de reconnaître les codes-barres PDF417 endommagés.

Le code-barres PDF417 peut encoder les caractères spéciaux suivants:

Structure du code-barres PDF417

Le code-barres PDF417 est composé de plusieurs modules, qui peuvent être divisés en trois groupes distincts:



Chaque module commence par une colonne noire et se termine par une colonne blanche, indiquant visuellement son début et sa fin. Une zone vide, appelée zone de silence, est présente de chaque côté du code-barres.

Les motifs de recherche de début et de fin indiquent les zones de début et de fin du code-barres. Ils aident le lecteur de codes-barres à détecter le code-barres, mais ne contiennent aucune donnée.

Les indicateurs gauche et droit contiennent des informations sur le code-barres, telles que le nombre de lignes, le niveau de correction d'erreur, etc.

Le module de données contient les données du code-barres. La taille d'un code-barres PDF417 dépend de la quantité de données encodées. Le module de données peut contenir de 1 à 30 mots de code et de 3 à 90 lignes. Sur la figure ci-dessus, le module de données contient 4 mots de code par ligne, marqués en violet. Dans la figure ci-dessus, le module de données comprend 4 lignes.

Chaque mot de code comprend 17 cellules et se compose de 4 bandes noires et 4 cellules blanches, d'où le nom PDF417. Chaque donnée mot de code est lue de gauche à droite et de haut en bas.


Qu'est-ce qu'un code-barres PDF417 Compact?

Le code-barres PDF417 Compact est une variante du code-barres PDF417 qui supprime l'indicateur de droite et le motif d'arrêt de recherche afin de gagner de la place.
Voici une image du code-barres PDF417 Compact:



Qu'est-ce qu'un code-barres Micro PDF417?

Le code-barres Micro PDF417 est une version compacte du code-barres PDF417. Les codes-barres Micro PDF417 sont généralement utilisés dans le cadre de codes composites (tels que GS1 DataBar) pour l'étiquetage de produits, l'étiquetage de documents et les applications médicales:


Le code-barres Micro PDF417 prend en charge les modes de stockage de données suivants:

Le code-barres Micro PDF417 peut encoder les caractères spéciaux suivants:

Qu'est-ce qu'un code-barres AAMVA?

Code-barres AAMVA (norme de conception des cartes de permis de conduire/d'identité): il s'agit d'un code-barres PDF417 qui stocke les informations d'un permis de conduire. VintaSoft Barcode .NET SDK peut encoder et décoder des données au format AAMVA.
Voici une image du code-barres AAMVA:



Qu'est-ce qu'un code-barres PDF417 compressé XFA?

Le code-barres "XFA Compressed PDF417" est un code-barres PDF417 qui stocke des données compressées conformément à la spécification Adobe XFA. VintaSoft Barcode .NET SDK peut générer et reconnaître les codes-barres "XFA Compressed PDF417".
Voici une image du code-barres "XFA Compressed QR":



Le caractère spécial "Structure Append"

Le code-barres PDF417 prend en charge le caractère spécial "Structure Append", qui permet de diviser les données en plusieurs codes-barres PDF417 (jusqu’à 99 999). Le caractère spécial "Structure Append" est encodé dans le code-barres et permet d’identifier de manière unique le nombre de parties du code-barres et leur ordre.

Voici une image d'un code-barres PDF417 avec le texte "In order to fit a non-square area or to handle larger messages than are practical in a single symbol, a data message can be distributed across several symbols. Aztec, Code 16K, DataMatrix, DotCode, MaxiCode, QR Code, PDF417, Micro PDF417 symbols may be appended in a structured format.":

Voici cinq codes-barres PDF417 avec le même texte, mais en plus petit. Ces cinq codes-barres PDF417 sont combinés en une seule valeur à l'aide du caractère spécial "Structure Append":

VintaSoft Barcode .NET SDK contient un algorithme permettant de récupérer des données à partir d'un ensemble de parties de code-barres PDF417 qui ont été séparées à l'aide du caractère spécial "Structure Append".


Quels codes-barres PDF417 peuvent être reconnus par le VintaSoft Barcode .NET SDK?

VintaSoft Barcode .NET SDK reconnaît tous les types de codes-barres PDF417: PDF417, PDF417 Compact, Micro PDF417, AAMVA et PDF417 compressé XFA. Des algorithmes uniques permettent une reconnaissance rapide des codes-barres dans des images présentant divers problèmes.



Voici un code C# qui montre comment reconnaître les codes-barres PDF417 dans une image capturée par un appareil photo:
/// <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();
            }
        }
    }
}


Voici un code C# qui montre comment générer et reconnaître un code-barres 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;
    }
}


Voici un code C# qui montre comment générer et reconnaître un code-barres PDF417, qui stocke des données compressées selon la spécification Adobe 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();
            }
        }
    }
}


Quels codes-barres PDF417 le VintaSoft Barcode .NET SDK peut-il générer?

VintaSoft Barcode .NET SDK a généré tous les types de codes-barres PDF417: PDF417, PDF417 Compact, Micro PDF417, AAMVA, XFA Compressed PDF417.

Voici un code C# qui montre comment générer une image bitmap d'un code-barres 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);
    }
}


Voici un code C# qui montre comment générer une image bitmap d'un code-barres 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);
    }
}


Voici un code C# qui montre comment générer une image vectorielle (SVG) d'un code-barres PDF417:
/// <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();
    }
}