Генерация 2D штрих-кодов с XFA сжатием в .NET
Категория: Штрих-коды; .NET
16 июня 2020
/// <summary> /// Generates Aztec barcode with XFA compression. /// </summary> public void GenerateAztecBarcodeWithXfaCompression() { string barcodeText = "https://www.vintasoft.ru/vsbarcode-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vstwain-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vstwain-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsimaging-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsannotation-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vspdf-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsjbig2-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsjpeg2000-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsdoccleanup-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsocr-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsdicom-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsformsprocessing-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/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.XFACompressed.XFACompressedAztecBarcodeSymbology xfaCompressedAztecBarcodeSymbology = new Vintasoft.Barcode.SymbologySubsets.XFACompressed.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"); } }
/// <summary> /// Generates DataMatrix barcode with XFA compression. /// </summary> public void GenerateDataMatrixBarcodeWithXfaCompression() { string barcodeText = "https://www.vintasoft.ru/vsbarcode-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vstwain-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vstwain-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsimaging-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsannotation-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vspdf-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsjbig2-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsjpeg2000-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsdoccleanup-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsocr-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsdicom-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsformsprocessing-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/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.XFACompressed.XFACompressedDataMatrixBarcodeSymbology xfaCompressedDataMatrixBarcodeSymbology = new Vintasoft.Barcode.SymbologySubsets.XFACompressed.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"); } }
/// <summary> /// Generates PDF417 barcode with XFA compression. /// </summary> public void GeneratePdf417BarcodeWithXfaCompression() { string barcodeText = "https://www.vintasoft.ru/vsbarcode-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vstwain-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vstwain-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsimaging-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsannotation-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vspdf-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsjbig2-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsjpeg2000-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsdoccleanup-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsocr-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsdicom-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsformsprocessing-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/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.XFACompressed.XFACompressedPDF417BarcodeSymbology xfaCompressedPdf417BarcodeSymbology = new Vintasoft.Barcode.SymbologySubsets.XFACompressed.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"); } }
/// <summary> /// Generates QR barcode with XFA compression. /// </summary> public void GenerateQrCodeBarcodeWithXfaCompression() { string barcodeText = "https://www.vintasoft.ru/vsbarcode-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vstwain-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vstwain-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsimaging-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsannotation-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vspdf-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsjbig2-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsjpeg2000-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsdoccleanup-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsocr-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsdicom-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/vsformsprocessing-dotnet-index.html" + System.Environment.NewLine + "https://www.vintasoft.ru/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.XFACompressed.XFACompressedQRCodeBarcodeSymbology xfaCompressedQrCodeBarcodeSymbology = new Vintasoft.Barcode.SymbologySubsets.XFACompressed.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"); } }
/// <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(); }