VintaSoft Barcode .NET SDK を使用して PDF417 バーコードを認識および生成します。

ブログ カテゴリ: バーコード.NET

2026/01/30

VintaSoft Barcode .NET SDK は、Windows、Linux、macOS 用の専門的なクロスプラットフォーム SDK であり、.NET、WPF、Web、MAUI で PDF417 バーコードを認識および生成できます。数行のコードを追加するだけで、.NET アプリケーションに PDF417 バーコードを認識および生成する機能を追加できます。

PDF417 バーコードとは?

PDF417 バーコードは、大容量データ(最大 1850 文字または 1108 バイト)の保存に使用される高密度の多層 2D バーコードです。1991 年に発明され、政府発行の身分証明書、搭乗券、物流などで広く使用されています。コードワードごとに 4 本のバーと 4 本のスペース、17 個の要素パターンを使用し、組み込みのエラー訂正機能をサポートし、コンパクトで信頼性の高いデータストレージを提供します。

PDF417 バーコードの画像は次のとおりです:


PDF417 バーコードは次のデータ保存モードをサポートしています:

PDF417 バーコードはリード・ソロモン誤り訂正アルゴリズムを使用しており、これにより破損した PDF417 バーコードを認識できます。

PDF417 バーコードは次の特殊文字をエンコードできます。

PDF417 バーコードの構造

PDF417 バーコードは、3 つのグループに分けられる多数のモジュールで構成されています。



各モジュールは、各モジュールの開始位置と終了位置を視覚的に示すために、黒一色の列で始まり、白一色の列で終わります。また、バーコードの両側にはクワイエット ゾーンと呼ばれる空白領域があります。

開始および終了検索パターン バーコードの開始領域と終了領域を示します。これらはバーコード スキャナーがバーコードを検出するのに役立ちますが、データは含まれていません。

左と右のインジケーター バーコードの行数、エラー訂正レベルなどのバーコード情報が含まれます。

データ コードワード モジュールには、バーコード データが含まれています。 PDF417 バーコードのサイズは、エンコードされるデータの量によって異なります。 データ コードワード モジュールには、バーコード データが含まれています。 1 から 30 個のコードワードと 3 から 90 行を含めることができます。上の図では、 データ コードワード モジュール 4個入り コードワード が含まれており、紫色でマークされています。上の図では、 データ コードワード モジュール は 4 行で構成されています。

コードワード は 17 セルの長さで、4 つの黒いストライプと 4 つの白いセルで構成されているため、PDF417 と呼ばれています。 コードワード 各データは、左から右、上から下に読み取られます。


PDF417 コンパクト バーコードとは何ですか?

PDF417 コンパクト バーコードは、スペースを節約するために右インジケーターとストップ検索パターンを削除した PDF417 バーコードのバリエーションです。
PDF417 コンパクト バーコードの画像は次のとおりです。



マイクロ PDF417 バーコードとは何ですか?

マイクロ PDF417 バーコードは PDF417 バーコードのコンパクト版です。マイクロ PDF417 バーコードは通常、製品ラベル、文書ラベル、ヘルスケア アプリケーション用の複合コード (GS1 DataBar など) の一部として使用されます。


マイクロ PDF417 バーコードは次のデータ保存モードをサポートしています。

マイクロ PDF417 バーコードは次の特殊文字をエンコードできます。

AAMVA バーコードとは何ですか?

AAMVA (DL/ID カード設計標準) バーコード - 運転免許証情報を保存する PDF417 バーコードです。 VintaSoft Barcode .NET SDK は、AAMVA 形式でデータをエンコードおよびデコードできます。
AAMVA バーコードの画像はこちらです:



XFA 圧縮 PDF417 バーコードとは何ですか?

「XFA 圧縮 PDF417」バーコードは、Adobe XFA 仕様に従って圧縮されたデータを保存する PDF417 バーコードです。 VintaSoft Barcode .NET SDKは、「XFA圧縮PDF417」バーコードを生成および認識できます。
「XFA 圧縮 QR」バーコードの画像はこちらです:



特殊文字「構造追加」

PDF417バーコードは特殊文字「構造追加」をサポートしており、これによりデータを複数(最大99,999個)のPDF417バーコードに分割できます。特殊文字「構造追加」はバーコード内にエンコードされており、バーコードの各部の数と順序を一意に識別できます。

「正方形以外の領域に収めるため、または単一のシンボルでは実現できないほど大きなメッセージを処理するために、データメッセージを複数のシンボルに分散させることができます。Aztec、Code 16K、DataMatrix、DotCode、MaxiCode、QR Code、PDF417、Micro PDF417シンボルは、構造化された形式で追加できます。」というテキストが書かれたPDF417バーコードの画像です。:

同じテキストが書かれた、小さいサイズのPDF417バーコードが5つあります。これらの5つのPDF417バーコードは、特殊文字「構造追加」を使用して1つの値に結合されています。:

VintaSoft Barcode .NET SDKには、特殊文字「構造追加」を使用して分離されたPDF417バーコード部分からデータを復元するアルゴリズムが含まれています。


VintaSoft Barcode .NET SDK を使用して認識できる PDF417 バーコードはどれですか?

VintaSoft Barcode .NET SDK は、PDF417、PDF417 Compact、Micro PDF417、AAMVA、および XFA 圧縮 PDF417 など、すべての種類の PDF417 バーコードを認識できます。認識には独自のアルゴリズムが使用されるため、さまざまな問題のある画像内のバーコードをすばやく認識できます。



カメラでキャプチャした画像内の PDF417 バーコードを認識する方法を示した C# コードは次のとおりです。
/// <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();
            }
        }
    }
}


AAMVA バーコードを生成および認識する方法を示した C# コードは次のとおりです。
/// <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;
    }
}


Adobe XFA 仕様に従って圧縮されたデータを保存する PDF417 バーコードを生成および認識する方法を示した C# コードは次のとおりです。
/// <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 圧縮 PDF417) を生成しました。

PDF417 バーコードのビットマップ画像を生成する方法を示す C# コードは次のとおりです。
/// <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);
    }
}


マイクロ PDF417 バーコードのビットマップ画像を生成する方法を示す C# コードは次のとおりです。
/// <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);
    }
}


PDF417 バーコードのベクター (SVG) 画像を生成する方法を示す C# コードは次のとおりです。
/// <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();
    }
}