Ստեղծել 2D շտրիխ կոդեր XFA սեղմմամբ .NET-ում

Բլոգի կատեգորիա՝ Barcode.NET

16.06.2020

Շտրիխ կոդի տվյալները, որոնք ներառում են սիմվոլների կրկնվող հաջորդականություններ (օրինակ՝ սերիական համարների ցանկ, XML տվյալներ, URL-ներ և այլն), կարող են փոքրացվել չափսերով, եթե շտրիխ կոդի տվյալները սեղմվեն Flate (ZIP) սեղմման միջոցով:
Շտրիխ կոդի տվյալների չափի փոքրացումը կարող է անհրաժեշտ լինել, եթե ցանկանում եք՝
VintaSoft Barcode .NET SDK-ն ապահովում է երկչափ շտրիխ կոդի տվյալները սեղմելու 2 եղանակ։

ՃԱՆԱՊԱՐՀ 1: Ինքնուրույն սեղմեք տվյալները և ստեղծեք երկչափ շտրիխ կոդ՝ սեղմված երկուական տվյալներով: Սա հնարավոր է, քանի որ բոլոր երկչափ շտրիխ կոդերը թույլ են տալիս պահպանել երկուական տվյալներ (մանրամասն տեղեկությունների համար դիմեք BinaryValueItem դասին):

2-րդ եղանակը. XML Forms Architecture (XFA) սպեցիֆիկացիայի համաձայն երկչափ շտրիխ կոդի ստեղծում: Այս դեպքում շտրիխ կոդի տվյալները կսեղմվեն "DEFLATE Compressed Data Format" (RFC1951) սեղմման ալգորիթմի միջոցով:


Այս հոդվածում մենք կցույց տանք, թե ինչպես ստեղծել երկչափ շտրիխ կոդեր՝ համաձայն XML Forms Architecture (XFA) սպեցիֆիկացիայի։

VintaSoft Barcode .NET SDK-ն առաջարկում է դասեր, որոնք թույլ են տալիս հեշտությամբ ստեղծել և ճանաչել շտրիխ կոդեր XFA սեղմված տվյալներով.

Ահա C# կոդը, որը թույլ է տալիս ստեղծել Aztec շտրիխ կոդ՝ XFA սպեցիֆիկացիայի համաձայն սեղմված տվյալներով.
/// <summary>
/// Generates Aztec barcode with XFA compression.
/// </summary>
public void GenerateAztecBarcodeWithXfaCompression()
{
    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
    Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter();

    // create the XFA compressed Aztec barcode symbology
    Vintasoft.Barcode.SymbologySubsets.XFACompressedAztecBarcodeSymbology xfaCompressedAztecBarcodeSymbology =
        new Vintasoft.Barcode.SymbologySubsets.XFACompressedAztecBarcodeSymbology();
    // encode barcode text using XFA compressed Aztec barcode symbology
    xfaCompressedAztecBarcodeSymbology.Encode(barcodeText, barcodeWriter.Settings);

    // get barcode as image
    using (System.Drawing.Image barcodeImage = barcodeWriter.GetBarcodeAsBitmap())
    {
        // save the barcode image to a file
        barcodeImage.Save("aztec-barcode-with-xfa-compression.png");
    }
}

Ահա Aztec շտրիխ կոդի պատկերը, որը պարունակում է URL-ների ցանկ՝ սեղմված XFA սպեցիֆիկացիայի համաձայն.
An image of Aztec barcode that contains a list of URLs compressed according to the XFA specification
Ահա Aztec շտրիխ կոդի պատկերը, որը պարունակում է URL-ների ցանկ՝ չսեղմված տեքստի տեսքով.
An image of Aztec barcode that contains a list of URLs in the form of uncompressed text

Ահա C# կոդը, որը թույլ է տալիս ստեղծել DataMatrix շտրիխ կոդ՝ սեղմված տվյալներով՝ XFA սպեցիֆիկացիայի համաձայն.
/// <summary>
/// Generates DataMatrix barcode with XFA compression.
/// </summary>
public void GenerateDataMatrixBarcodeWithXfaCompression()
{
    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
    Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter();

    // create the XFA compressed DataMatrix barcode symbology
    Vintasoft.Barcode.SymbologySubsets.XFACompressedDataMatrixBarcodeSymbology xfaCompressedDataMatrixBarcodeSymbology =
        new Vintasoft.Barcode.SymbologySubsets.XFACompressedDataMatrixBarcodeSymbology();
    // encode barcode text using XFA compressed DataMatrix barcode symbology
    xfaCompressedDataMatrixBarcodeSymbology.Encode(barcodeText, barcodeWriter.Settings);

    // get barcode as image
    using (System.Drawing.Image barcodeImage = barcodeWriter.GetBarcodeAsBitmap())
    {
        // save the barcode image to a file
        barcodeImage.Save("dataMatrix-barcode-with-xfa-compression.png");
    }
}

Ահա DataMatrix շտրիխ կոդի պատկերը, որը պարունակում է URL-ների ցանկ՝ սեղմված XFA սպեցիֆիկացիայի համաձայն.
An image of DataMatrix barcode that contains a list of URLs compressed according to the XFA specification
Ահա DataMatrix շտրիխ կոդի պատկերը, որը պարունակում է URL-ների ցանկ չսեղմված տեքստի ձևաչափ՝
An image of DataMatrix barcode that contains a list of URLs in the form of uncompressed text

Ահա C# կոդը, որը թույլ է տալիս ստեղծել PDF417 շտրիխ կոդ՝ 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
    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);

    // get barcode as image
    using (System.Drawing.Image barcodeImage = barcodeWriter.GetBarcodeAsBitmap())
    {
        // save the barcode image to a file
        barcodeImage.Save("pdf417-barcode-with-xfa-compression.png");
    }
}

Ահա PDF417 շտրիխ կոդի պատկերը, որը պարունակում է XFA սպեցիֆիկացիայի համաձայն սեղմված URL-ների ցանկ։
An image of PDF417 barcode that contains a list of URLs compressed according to the XFA specification
Ահա PDF417 շտրիխ կոդի պատկերը, որը պարունակում է URL-ների ցանկ՝ չսեղմված տեքստի տեսքով։
An image of PDF417 barcode that contains a list of URLs in the form of uncompressed text

Ահա C# կոդը, որը թույլ է տալիս ստեղծել QR կոդի շտրիխ կոդ՝ XFA սպեցիֆիկացիայի համաձայն սեղմված տվյալներով։
/// <summary>
/// Generates QR barcode with XFA compression.
/// </summary>
public void GenerateQrCodeBarcodeWithXfaCompression()
{
    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
    Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter();

    // create the XFA compressed QR barcode symbology
    Vintasoft.Barcode.SymbologySubsets.XFACompressedQRCodeBarcodeSymbology xfaCompressedQrCodeBarcodeSymbology =
        new Vintasoft.Barcode.SymbologySubsets.XFACompressedQRCodeBarcodeSymbology();
    // encode barcode text using XFA compressed QR barcode symbology
    xfaCompressedQrCodeBarcodeSymbology.Encode(barcodeText, barcodeWriter.Settings);

    // get barcode as image
    using (System.Drawing.Image barcodeImage = barcodeWriter.GetBarcodeAsBitmap())
    {
        // save the barcode image to a file
        barcodeImage.Save("qr-barcode-with-xfa-compression.png");
    }
}

Ահա QR շտրիխ կոդի պատկերը, որը պարունակում է XFA սպեցիֆիկացիայի համաձայն սեղմված URL-ների ցանկ։
An image of QR barcode that contains a list of URLs compressed according to the XFA specification
Ահա QR շտրիխ կոդի պատկերը, որը պարունակում է URL-ների ցանկ՝ չսեղմված տեքստի տեսքով։
An image of QR barcode that contains a list of URLs in the form of uncompressed text


Ահա C# կոդը, որը թույլ է տալիս ճանաչել XFA սպեցիֆիկացիայի համաձայն ստեղծված երկչափ շտրիխ կոդերը։ սպեցիֆիկացիա՝
/// <summary>
/// Recognizes 2D barcode with XFA compressed data.
/// </summary>
/// <param name="barcodeImageFile">A path to a barcode image file.</param>
public void Recognize2DBarcodeWithXfaCompressedData(string barcodeImageFile)
{
    // create barcode reader
    using (Vintasoft.Barcode.BarcodeReader reader = new Vintasoft.Barcode.BarcodeReader())
    {
        // specify that reader must search for XFA compressed Aztec barcodes
        reader.Settings.ScanBarcodeSubsets.Add(Vintasoft.Barcode.SymbologySubsets.BarcodeSymbologySubsets.XFACompressedAztec);
        // specify that reader must search for XFA compressed DataMatrix barcodes
        reader.Settings.ScanBarcodeSubsets.Add(Vintasoft.Barcode.SymbologySubsets.BarcodeSymbologySubsets.XFACompressedDataMatrix);
        // specify that reader must search for XFA compressed PDF417 barcodes
        reader.Settings.ScanBarcodeSubsets.Add(Vintasoft.Barcode.SymbologySubsets.BarcodeSymbologySubsets.XFACompressedPDF417);
        // specify that reader must search for XFA compressed QR barcodes
        reader.Settings.ScanBarcodeSubsets.Add(Vintasoft.Barcode.SymbologySubsets.BarcodeSymbologySubsets.XFACompressedQRCode);

        // specify that reader must search for horizontal barcodes only
        reader.Settings.ScanDirection = Vintasoft.Barcode.ScanDirection.Horizontal;

        // read barcodes from image file
        Vintasoft.Barcode.IBarcodeInfo[] barcodeInfos = reader.ReadBarcodes(barcodeImageFile);

        // 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();
            }
        }
    }
    System.Console.WriteLine();
    System.Console.WriteLine();
}


Պետք է նշել, որ հարթ սեղմումը (ZIP) կարող է մեծացնել տվյալների քանակը, եթե տվյալների ավելորդությունը քիչ է կամ եթե տվյալների հոսքը չափազանց կարճ է։