Riconosci e genera codici a barre PDF417 utilizzando VintaSoft Barcode .NET SDK

Categoria del blog: Barcode.NET

30.01.2026

VintaSoft Barcode .NET SDK è un SDK multipiattaforma professionale per Windows, Linux, macOS, che consente di riconoscere e generare codici a barre PDF417 in .NET, WPF, Web, MAUI. Bastano poche righe di codice per aggiungere la possibilità di riconoscere e generare codici a barre PDF417 alla tua applicazione .NET.

Cos'è un codice a barre PDF417?

Il codice a barre PDF417 è un codice a barre 2D multistrato ad alta densità utilizzato per memorizzare grandi quantità di dati (fino a 1850 caratteri o 1108 byte). Inventato nel 1991, è ampiamente utilizzato per carte d'identità governative, carte d'imbarco e nella logistica. Utilizza uno schema a 4 barre/4 spazi, 17 elementi per parola di codice, supporta la correzione degli errori integrata e fornisce un'archiviazione dati compatta e affidabile.

Ecco l'immagine del codice a barre PDF417:


Il codice a barre PDF417 supporta le seguenti modalità di archiviazione dati:

Il codice a barre PDF417 utilizza l'algoritmo di correzione degli errori Reed-Solomon, che consente di riconoscere i codici a barre PDF417 danneggiati.

Il codice a barre PDF417 può codificare i seguenti caratteri speciali:

Struttura del codice a barre PDF417

Il codice a barre PDF417 è costituito da diversi moduli, che possono essere suddivisi in tre gruppi distinti:



Ogni modulo inizia con una colonna nera piena e termina con una colonna bianca piena per indicare visivamente dove inizia e finisce ogni modulo. C'è anche un'area vuota su entrambi i lati del codice a barre, nota come zona silenziosa.

I modelli di ricerca di inizio e fine indicano le aree di inizio e fine del codice a barre. Aiutano lo scanner di codici a barre a rilevare il codice a barre ma non contengono dati.

Gli indicatori sinistro e destro contengono informazioni sul codice a barre, come il numero di righe del codice a barre, il livello di correzione degli errori, ecc.

Il modulo del codice dati contiene i dati del codice a barre. La dimensione di un codice a barre PDF417 dipende dalla quantità di dati codificati. Il modulo del codice dati può contenere da 1 a 30 codici e da 3 a 90 righe. Nella figura sopra, il modulo del codice dati contiene 4 parole in codice per riga, contrassegnati in viola. Nella figura sopra, il modulo del codice dati è composto da 4 righe.

Ogni parola in codice è lunga 17 celle ed è composta da 4 strisce nere e 4 celle bianche, da cui il nome PDF417. Ogni dato parola in codice viene letto da sinistra a destra, dall'alto verso il basso.


Cos'è il codice a barre PDF417 Compact?

Il codice a barre PDF417 Compact è una variante del codice a barre PDF417 che rimuove l'indicatore destro e il modello di ricerca di stop per risparmiare spazio.
Ecco un'immagine del codice a barre PDF417 Compact:



Cos'è il codice a barre Micro PDF417?

Il codice a barre Micro PDF417 è una versione compatta del codice a barre PDF417. I codici a barre Micro PDF417 vengono in genere utilizzati come parte di codici compositi (come GS1 DataBar) per l'etichettatura di prodotti, l'etichettatura di documenti e applicazioni sanitarie:


Il codice a barre Micro PDF417 supporta le seguenti modalità di archiviazione dati:

Il codice a barre Micro PDF417 può codificare i seguenti caratteri speciali:

Cos'è il codice a barre AAMVA?

Codice a barre AAMVA (DL/ID Card Design Standard): si tratta di un codice a barre PDF417 che memorizza le informazioni della patente di guida. VintaSoft Barcode .NET SDK può codificare e decodificare i dati nel formato AAMVA.
Ecco l'immagine del codice a barre AAMVA:



Cos'è il codice a barre PDF417 compresso XFA?

Il codice a barre "PDF417 compresso XFA" è un codice a barre PDF417 che memorizza i dati compressi secondo le specifiche Adobe XFA. VintaSoft Barcode .NET SDK può generare e riconoscere codici a barre "XFA Compressed PDF417".
Ecco l'immagine del codice a barre "XFA Compressed QR":



Il carattere speciale "Aggiunta struttura"

Il codice a barre PDF417 supporta il carattere speciale "Aggiunta struttura", che consente di suddividere i dati in più codici a barre PDF417 (fino a 99.999). Il carattere speciale "Aggiunta struttura" è codificato all'interno del codice a barre e consente l'identificazione univoca del numero di parti del codice a barre e del loro ordine.

Ecco l'immagine di un codice a barre PDF417 con il testo "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.":

Ed ecco cinque codici a barre PDF417 con lo stesso testo, ma in dimensioni più piccole. Questi cinque codici a barre PDF417 vengono combinati in un singolo valore utilizzando il carattere speciale "Aggiungi struttura":

VintaSoft Barcode .NET SDK contiene un algoritmo per il recupero dei dati da un set di parti di codici a barre PDF417 che sono state separate utilizzando il carattere speciale "Aggiungi struttura".


Quali codici a barre PDF417 possono essere riconosciuti utilizzando VintaSoft Barcode .NET SDK?

VintaSoft Barcode .NET SDK è in grado di riconoscere tutti i tipi di codici a barre PDF417: PDF417, PDF417 Compact, Micro PDF417, AAMVA e XFA Compressed PDF417. Per il riconoscimento vengono utilizzati algoritmi esclusivi, che consentono un rapido riconoscimento dei codici a barre nelle immagini con vari problemi:



Ecco il codice C# che dimostra come riconoscere i codici a barre PDF417 in un'immagine acquisita da una fotocamera:
/// <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();
            }
        }
    }
}


Ecco il codice C# che dimostra come generare e riconoscere un codice a barre 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;
    }
}


Ecco il codice C# codice che dimostra come generare e riconoscere un codice a barre PDF417, che memorizza i dati compressi secondo la specifica 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();
            }
        }
    }
}


Quali codici a barre PDF417 può generare VintaSoft Barcode .NET SDK?

VintaSoft Barcode .NET SDK ha generato tutti i tipi di codici a barre PDF417: PDF417, PDF417 Compact, Micro PDF417, AAMVA,PDF417 compresso XFA.

Ecco il codice C# che mostra come generare un'immagine bitmap di un codice a barre 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);
    }
}


Ecco il codice C# che mostra come generare un'immagine bitmap di un codice a barre 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);
    }
}


Ecco il codice C# che mostra come generare un'immagine vettoriale (SVG) di un codice a barre 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();
    }
}