diff --git a/hibc-lic-barcode/add-quiet-zone-of-ten-modules-around-datamatrix-hibc-lic-barcode-to-meet-printing-standards.cs b/hibc-lic-barcode/add-quiet-zone-of-ten-modules-around-datamatrix-hibc-lic-barcode-to-meet-printing-standards.cs index 625535e..26eb840 100644 --- a/hibc-lic-barcode/add-quiet-zone-of-ten-modules-around-datamatrix-hibc-lic-barcode-to-meet-printing-standards.cs +++ b/hibc-lic-barcode/add-quiet-zone-of-ten-modules-around-datamatrix-hibc-lic-barcode-to-meet-printing-standards.cs @@ -1,64 +1,60 @@ -// Title: Add Quiet Zone to HIBC DataMatrix LIC Barcode -// Description: Demonstrates how to generate a HIBC DataMatrix LIC barcode with a ten‑module quiet zone using Aspose.BarCode. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It shows how to work with the ComplexBarcodeGenerator, HIBCLICSecondaryAndAdditionalDataCodetext, and SecondaryAndAdditionalData classes to create HIBC‑compliant DataMatrix barcodes. Developers often need to adjust quiet zones, module size, and padding to satisfy printing standards and regulatory requirements. +// Title: Adding a Quiet Zone to a DataMatrix HIBC LIC Barcode +// Description: Demonstrates how to configure a DataMatrix HIBC LIC barcode with a ten‑module quiet zone using Aspose.BarCode. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and barcode parameters such as XDimension and Padding. Typical use cases include creating compliant HIBC‑LIC barcodes for medical device labeling where a specific quiet zone is required. Developers often need to adjust module size, colors, and padding to meet printing standards. // Prompt: Add a quiet zone of ten modules around a DataMatrix HIBC LIC barcode to meet printing standards. -// Tags: datamatrix, hibc, quietzone, png, generation, complexbarcode, aspose.barcodes, secondarydata +// Tags: datamatrix, hibc, quiet zone, png, aspose.barcodes, generation using System; -using Aspose.BarCode.ComplexBarcode; +using System.IO; +using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.Drawing; -using Aspose.Drawing.Imaging; /// -/// Generates a HIBC DataMatrix LIC barcode with a ten‑module quiet zone and saves it as a PNG image. +/// Program demonstrating adding a quiet zone to a DataMatrix HIBC LIC barcode. /// class Program { /// - /// Entry point of the example. Prepares secondary data, configures barcode parameters, adds a quiet zone, - /// and saves the resulting image. + /// Entry point. Generates the barcode, applies a ten‑module quiet zone, and saves it as PNG. /// static void Main() { - // Prepare secondary data for the HIBC LIC DataMatrix barcode (lot and serial numbers). - var secondaryData = new SecondaryAndAdditionalData - { - LotNumber = "LOT123", - SerialNumber = "SN001" - }; - - // Create the complex codetext object that combines the barcode type, link character, and secondary data. - var hibcCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext - { - BarcodeType = EncodeTypes.HIBCDataMatrixLIC, - LinkCharacter = '+', - Data = secondaryData - }; + // Sample HIBC LIC DataMatrix code text (Labeler ID + Product Number) + const string codeText = "A99912345"; - // Initialize the complex barcode generator with the prepared codetext. - using (var generator = new ComplexBarcodeGenerator(hibcCodetext)) + // Create the barcode generator for HIBC DataMatrix LIC + using (var generator = new BarcodeGenerator(EncodeTypes.HIBCDataMatrixLIC, codeText)) { - // Define the module size (XDimension) – 2 points per module. + // Set module size (XDimension) – 2 points per module generator.Parameters.Barcode.XDimension.Point = 2f; - // Calculate quiet zone size: ten modules on each side. - float quietZone = generator.Parameters.Barcode.XDimension.Point * 10f; + // Calculate quiet zone size: 10 modules * XDimension + float quietZone = 10f * generator.Parameters.Barcode.XDimension.Point; - // Apply the quiet zone to all four padding sides. - generator.Parameters.Barcode.Padding.Left.Point = quietZone; - generator.Parameters.Barcode.Padding.Top.Point = quietZone; - generator.Parameters.Barcode.Padding.Right.Point = quietZone; + // Apply the quiet zone to all sides of the barcode + generator.Parameters.Barcode.Padding.Left.Point = quietZone; + generator.Parameters.Barcode.Padding.Top.Point = quietZone; + generator.Parameters.Barcode.Padding.Right.Point = quietZone; generator.Parameters.Barcode.Padding.Bottom.Point = quietZone; - // Enable automatic sizing using interpolation mode. - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; + // Optional: set foreground and background colors + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Save the generated barcode as a PNG file. - generator.Save("hibc_datamatrix.png"); - } + // Define output file path + string outputPath = "hibc_datamatrix.png"; + + // Ensure the output directory exists + string directory = Path.GetDirectoryName(Path.GetFullPath(outputPath)); + if (!Directory.Exists(directory)) + { + Directory.CreateDirectory(directory); + } - // Inform the user that the barcode has been generated. - Console.WriteLine("HIBC DataMatrix LIC barcode generated with a 10‑module quiet zone."); + // Save the barcode image as PNG + generator.Save(outputPath, BarCodeImageFormat.Png); + Console.WriteLine($"Barcode saved to {outputPath}"); + } } } \ No newline at end of file diff --git a/hibc-lic-barcode/adjust-image-resolution-to-600-dpi-when-generating-datamatrix-hibc-lic-barcode-for-high-density-labels.cs b/hibc-lic-barcode/adjust-image-resolution-to-600-dpi-when-generating-datamatrix-hibc-lic-barcode-for-high-density-labels.cs index 91c3883..377c22e 100644 --- a/hibc-lic-barcode/adjust-image-resolution-to-600-dpi-when-generating-datamatrix-hibc-lic-barcode-for-high-density-labels.cs +++ b/hibc-lic-barcode/adjust-image-resolution-to-600-dpi-when-generating-datamatrix-hibc-lic-barcode-for-high-density-labels.cs @@ -1,49 +1,53 @@ -// Title: Generate HIBC DataMatrix LIC Barcode at 600 DPI -// Description: Creates a HIBC DataMatrix LIC barcode with secondary data and saves it as a 600 DPI PNG image. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It demonstrates how to use the ComplexBarcodeGenerator together with HIBCLICSecondaryAndAdditionalDataCodetext to produce high‑density HIBC LIC DataMatrix barcodes. Typical use cases include pharmaceutical labeling and inventory tracking where secondary information (lot, serial, dates) must be encoded at high resolution for small‑format labels. -// Prompt: Adjust the image resolution to 600 DPI when generating a DataMatrix HIBC LIC barcode for high‑density labels. -// Tags: datamatrix, hibc, lic, generation, resolution, png, complexbarcodegenerator, hibclicsecondaryandadditionaldatacodetext +// Title: Generate High‑Resolution DataMatrix HIBC LIC Barcode +// Description: Demonstrates how to create a DataMatrix HIBC LIC barcode with a 600 DPI image resolution for high‑density label printing. +// Category-Description: This example belongs to the Aspose.BarCode generation category, focusing on complex barcode creation using the ComplexBarcodeGenerator class. It shows typical usage of EncodeTypes, PrimaryData, and HIBCLICPrimaryDataCodetext to produce HIBC‑compliant DataMatrix barcodes, a common requirement for pharmaceutical and medical device labeling where high‑density, machine‑readable codes are needed. Developers often need to adjust image resolution, colors, and output formats for printing workflows. +/// Prompt: Adjust the image resolution to 600 DPI when generating a DataMatrix HIBC LIC barcode for high‑density labels. +// Tags: datamatrix, hibc, complexbarcode, resolution, png, generation using System; -using Aspose.BarCode.ComplexBarcode; using Aspose.BarCode.Generation; +using Aspose.BarCode.ComplexBarcode; +using Aspose.Drawing; /// -/// Demonstrates generation of a HIBC DataMatrix LIC barcode with secondary data -/// and saves the image at 600 DPI resolution. +/// Example program that generates a high‑resolution DataMatrix HIBC LIC barcode. /// class Program { /// - /// Entry point of the example. Prepares secondary data, configures the generator, - /// and saves the high‑resolution barcode image. + /// Generates and saves the barcode image at 600 DPI. /// static void Main() { - // Prepare secondary and additional data required for a HIBC LIC DataMatrix barcode - var secondaryCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext + // Prepare primary HIBC data (product number, labeler ID, unit of measure) + var primaryData = new PrimaryData + { + ProductOrCatalogNumber = "12345", + LabelerIdentificationCode = "A999", + UnitOfMeasureID = 1 + }; + + // Create HIBC DataMatrix LIC complex codetext + var hibcCodetext = new HIBCLICPrimaryDataCodetext { BarcodeType = EncodeTypes.HIBCDataMatrixLIC, - LinkCharacter = '+', - Data = new SecondaryAndAdditionalData - { - LotNumber = "LOT123", - SerialNumber = "SN456", - ExpiryDate = DateTime.Today.AddMonths(6), - ExpiryDateFormat = HIBCLICDateFormat.MMDDYY, - Quantity = 10, - DateOfManufacture = DateTime.Today - } + Data = primaryData }; - // Generate the barcode with a high image resolution (600 DPI) - using (var generator = new ComplexBarcodeGenerator(secondaryCodetext)) + // Generate the barcode with high resolution (600 DPI) + using (var generator = new ComplexBarcodeGenerator(hibcCodetext)) { - // Set the resolution property to 600 DPI + // Set image resolution to 600 DPI generator.Parameters.Resolution = 600; - // Save the generated barcode as a PNG file - generator.Save("HIBC_DataMatrix_600dpi.png"); + // Optional: set foreground and background colors + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; + + // Save the barcode image as PNG + const string outputPath = "HIBC_DataMatrix_LIC.png"; + generator.Save(outputPath, BarCodeImageFormat.Png); + Console.WriteLine($"Barcode saved to {outputPath} at 600 DPI."); } } } \ No newline at end of file diff --git a/hibc-lic-barcode/apply-white-background-and-black-foreground-to-qr-hibc-lic-barcode-for-high-contrast-printing.cs b/hibc-lic-barcode/apply-white-background-and-black-foreground-to-qr-hibc-lic-barcode-for-high-contrast-printing.cs index 464225a..6a12103 100644 --- a/hibc-lic-barcode/apply-white-background-and-black-foreground-to-qr-hibc-lic-barcode-for-high-contrast-printing.cs +++ b/hibc-lic-barcode/apply-white-background-and-black-foreground-to-qr-hibc-lic-barcode-for-high-contrast-printing.cs @@ -1,48 +1,52 @@ -// Title: Apply white background and black foreground to a QR HIBC LIC barcode -// Description: Demonstrates generating a QR HIBC LIC barcode with high‑contrast colors for printing. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on complex barcode creation using the ComplexBarcodeGenerator and HIBCLICSecondaryAndAdditionalDataCodetext classes. It shows how to configure color parameters for QR HIBC LIC barcodes, a common requirement for clear, high‑contrast print output in healthcare and logistics applications. Developers often need to customize foreground and background colors when generating barcodes for scanners and label printers. +// Title: Generate a high‑contrast HIBC QR LIC barcode with white background and black foreground +// Description: Demonstrates how to create a HIBC QR LIC barcode using Aspose.BarCode, applying a white background and black foreground for optimal print contrast. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category, illustrating the use of the ComplexBarcodeGenerator and related codetext classes to produce specialized symbologies such as HIBC QR LIC. Developers often need to customize colors, embed secondary data, and export images in common formats. The snippet shows typical steps: preparing secondary data, configuring barcode parameters, and saving the result. // Prompt: Apply a white background and black foreground to a QR HIBC LIC barcode for high‑contrast printing. -// Tags: barcode, hibc, qr, lic, color, background, foreground, generation, aspnet, aspose.barcode +// Tags: hibc, qr, lic, color, png, complexbarcodegenerator, secondaryandadditionaldata using System; -using Aspose.BarCode.ComplexBarcode; +using System.IO; using Aspose.BarCode.Generation; +using Aspose.BarCode.ComplexBarcode; using Aspose.Drawing; /// -/// Generates a QR HIBC LIC barcode with a white background and black foreground, -/// illustrating color customization for high‑contrast printing scenarios. +/// Example program that generates a HIBC QR LIC barcode with high‑contrast colors. /// class Program { /// - /// Entry point of the example. Creates secondary and additional data for a QR HIBC LIC barcode, - /// sets color parameters, and saves the resulting image. + /// Entry point of the application. Creates and saves a barcode image. /// static void Main() { - // Prepare secondary‑and‑additional data codetext for a QR HIBC LIC barcode + // Prepare secondary data (lot and serial numbers) required for the HIBC LIC QR barcode. + var secondaryData = new SecondaryAndAdditionalData + { + LotNumber = "LOT123", + SerialNumber = "SN456" + }; + + // Build the complex codetext object that defines the barcode type, link character, and secondary data. var hibcCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext { - BarcodeType = EncodeTypes.HIBCQRLIC, // QR version of HIBC LIC - LinkCharacter = '+', // Required link character - Data = new SecondaryAndAdditionalData - { - LotNumber = "LOT123" // Example secondary data - } + BarcodeType = EncodeTypes.HIBCQRLIC, + LinkCharacter = '+', // Required link character for HIBC QR LIC. + Data = secondaryData }; - // Generate the barcode with specified colors + // Generate the barcode using the complex barcode generator. using (var generator = new ComplexBarcodeGenerator(hibcCodetext)) { - // Set foreground (barcode) color to black + // Set foreground (bars) to black. generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; - - // Set background color to white + // Set background to white for high contrast. generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Save the generated barcode image to a PNG file - generator.Save("hibc_qr.png"); + // Define output file path and save the barcode as a PNG image. + string outputPath = "HIBC_QR.png"; + generator.Save(outputPath, BarCodeImageFormat.Png); + Console.WriteLine($"Barcode saved to {Path.GetFullPath(outputPath)}"); } } } \ No newline at end of file diff --git a/hibc-lic-barcode/batch-decode-folder-of-tiff-images-containing-hibc-lic-barcodes-and-export-results-to-csv-file.cs b/hibc-lic-barcode/batch-decode-folder-of-tiff-images-containing-hibc-lic-barcodes-and-export-results-to-csv-file.cs index f9cfe5d..4c55532 100644 --- a/hibc-lic-barcode/batch-decode-folder-of-tiff-images-containing-hibc-lic-barcodes-and-export-results-to-csv-file.cs +++ b/hibc-lic-barcode/batch-decode-folder-of-tiff-images-containing-hibc-lic-barcodes-and-export-results-to-csv-file.cs @@ -1,111 +1,110 @@ -// Title: Batch decode HIBC LIC barcodes from TIFF images and export to CSV -// Description: Demonstrates how to read multiple TIFF files, iterate through each frame, decode HIBC LIC barcodes, and write the results to a CSV file. -// Category-Description: This example belongs to the Aspose.BarCode barcode recognition category, illustrating the use of BarCodeReader with specific DecodeType values (HIBCAztecLIC, HIBCCode128LIC, HIBCDataMatrixLIC, HIBCQRLIC). It shows typical workflows for batch processing image files, handling multi‑page TIFFs, and exporting decoded data, which developers often need when integrating barcode scanning into document processing pipelines. +// Title: Batch decode HIBC LIC barcodes from TIFF files and export to CSV +// Description: Demonstrates how to read HIBC LIC barcodes from a folder of TIFF images using Aspose.BarCode and write the results to a CSV file. +// Category-Description: This example belongs to the Aspose.BarCode barcode recognition and generation category. It showcases the use of BarCodeReader for batch decoding, DecodeType for specifying symbology, and ComplexBarcodeGenerator for creating sample barcodes. Typical scenarios include processing large sets of medical or pharmaceutical labels, extracting product information, and exporting data for downstream systems. Developers often need to automate bulk barcode extraction and generate test images, making this pattern a common reference. // Prompt: Batch decode a folder of TIFF images containing HIBC LIC barcodes and export results to a CSV file. -// Tags: hibc, lic, barcode, decoding, tiff, csv, batch-processing, aspose.barcode, aspose.drawing +// Tags: barcode, hibc, lic, tiff, csv, batch, decoding, generation, aspose.barcode, recognition, generation using System; using System.IO; -using System.Linq; +using System.Text; +using Aspose.BarCode.Generation; using Aspose.BarCode.BarCodeRecognition; -using Aspose.Drawing; -using Aspose.Drawing.Imaging; +using Aspose.BarCode.ComplexBarcode; /// -/// Demonstrates batch decoding of HIBC LIC barcodes from TIFF images and exporting results to a CSV file. +/// Demonstrates batch decoding of HIBC LIC barcodes from TIFF images and exporting the results to a CSV file. /// class Program { /// - /// Entry point of the example. Processes up to 10 TIFF files in the specified input folder, - /// decodes HIBC LIC barcodes from each frame, and writes the findings to a CSV file. + /// Entry point of the example. Scans a folder for TIFF images, decodes HIBC LIC barcodes, + /// and writes the filename, barcode type, and decoded text to a CSV file. /// static void Main() { - // Input folder containing TIFF images - string inputFolder = "InputTiffImages"; + // Define input folder (Barcodes) and output CSV file paths relative to the current directory. + string inputFolder = Path.Combine(Directory.GetCurrentDirectory(), "Barcodes"); + string csvPath = Path.Combine(Directory.GetCurrentDirectory(), "results.csv"); - // Output CSV file path - string outputCsv = "DecodedBarcodes.csv"; - - // Ensure input folder exists; if not, create it and exit because there are no files to process + // Ensure the input folder exists; create it if it does not. if (!Directory.Exists(inputFolder)) { - Console.WriteLine($"Input folder \"{inputFolder}\" does not exist. Creating it."); Directory.CreateDirectory(inputFolder); - return; } - // Retrieve up to 10 TIFF files (both .tif and .tiff extensions) from the folder - var tiffFiles = Directory.GetFiles(inputFolder, "*.*", SearchOption.TopDirectoryOnly) - .Where(f => f.EndsWith(".tif", StringComparison.OrdinalIgnoreCase) || - f.EndsWith(".tiff", StringComparison.OrdinalIgnoreCase)) - .Take(10) - .ToArray(); + // If the folder is empty, generate a few sample HIBC LIC barcode TIFF images for demonstration. + string[] existingTiffFiles = Directory.GetFiles(inputFolder, "*.tif"); + if (existingTiffFiles.Length == 0) + { + GenerateSampleBarcodes(inputFolder); + } - // Open a StreamWriter for the CSV output; overwrite any existing file - using (var writer = new StreamWriter(outputCsv, false)) + // Open a StreamWriter for the CSV output (UTF‑8 encoding, overwrite existing file). + using (var csvWriter = new StreamWriter(csvPath, false, Encoding.UTF8)) { - // Write CSV header line - writer.WriteLine("FileName,FrameIndex,BarcodeType,CodeText"); + // Write CSV header. + csvWriter.WriteLine("FileName,BarcodeType,CodeText"); - // Process each TIFF file found - foreach (var filePath in tiffFiles) + // Iterate over each TIFF file in the input folder. + foreach (string filePath in Directory.GetFiles(inputFolder, "*.tif")) { - // Extract just the file name for CSV reporting - string fileName = Path.GetFileName(filePath); - - // Load the TIFF image using Aspose.Drawing - using (var image = Image.FromFile(filePath)) + // Verify the file still exists before processing. + if (!File.Exists(filePath)) { - // Determine the number of frames (pages) in the multi‑page TIFF - var frameDimension = FrameDimension.Time; - int frameCount = image.GetFrameCount(frameDimension); + Console.WriteLine($"File not found: {filePath}"); + continue; + } - // Iterate through each frame in the TIFF - for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) + // Decode using the HIBC LIC Code128 symbology. + using (var reader = new BarCodeReader(filePath, DecodeType.HIBCCode128LIC)) + { + // Read all barcodes found in the image. + foreach (var result in reader.ReadBarCodes()) { - // Select the current frame as the active image - image.SelectActiveFrame(frameDimension, frameIndex); + // Compose a CSV line with the file name, barcode type, and decoded text. + string line = $"{Path.GetFileName(filePath)},{result.CodeTypeName},{result.CodeText}"; + csvWriter.WriteLine(line); + Console.WriteLine(line); + } + } + } + } - // Save the active frame to a memory stream in PNG format for barcode reading - using (var ms = new MemoryStream()) - { - image.Save(ms, ImageFormat.Png); - ms.Position = 0; // Reset stream position before reading + Console.WriteLine($"Decoding completed. Results saved to: {csvPath}"); + } - // Initialize BarCodeReader to look for HIBC LIC barcode types - using (var reader = new BarCodeReader( - ms, - DecodeType.HIBCAztecLIC, - DecodeType.HIBCCode128LIC, - DecodeType.HIBCDataMatrixLIC, - DecodeType.HIBCQRLIC)) - { - // Perform barcode detection on the current frame - var results = reader.ReadBarCodes(); + // Generates a few sample HIBC LIC barcode images (TIFF) for demonstration purposes. + private static void GenerateSampleBarcodes(string folderPath) + { + // Sample data for primary HIBC LIC barcode. + var primaryData = new PrimaryData + { + ProductOrCatalogNumber = "12345", + LabelerIdentificationCode = "A999", + UnitOfMeasureID = 1 + }; - // If no barcodes were found, write an empty entry for this frame - if (results.Length == 0) - { - writer.WriteLine($"{fileName},{frameIndex},,"); - } - else - { - // Write a CSV line for each detected barcode - foreach (var result in results) - { - writer.WriteLine($"{fileName},{frameIndex},{result.CodeTypeName},{result.CodeText}"); - } - } - } - } - } - } + // Wrap the primary data in a complex codetext object specifying the barcode type. + var complexCodetext = new HIBCLICPrimaryDataCodetext + { + BarcodeType = EncodeTypes.HIBCCode128LIC, + Data = primaryData + }; + + // Create three sample images with slightly different product numbers. + for (int i = 1; i <= 3; i++) + { + // Modify the product number to make each barcode unique. + primaryData.ProductOrCatalogNumber = $"1234{i}"; + string fileName = Path.Combine(folderPath, $"Sample{i}.tif"); + + // Generate the barcode image and save it as a TIFF file. + using (var generator = new ComplexBarcodeGenerator(complexCodetext)) + { + generator.Save(fileName, BarCodeImageFormat.Tiff); } } - // Inform the user that processing is complete - Console.WriteLine($"Decoding completed. Results saved to \"{outputCsv}\"."); + Console.WriteLine($"Generated {3} sample HIBC LIC barcode images in '{folderPath}'."); } } \ No newline at end of file diff --git a/hibc-lic-barcode/batch-generate-ten-code-39-hibc-lic-barcodes-with-varying-primary-product-numbers-and-store-them-in-zip-archive.cs b/hibc-lic-barcode/batch-generate-ten-code-39-hibc-lic-barcodes-with-varying-primary-product-numbers-and-store-them-in-zip-archive.cs index 64d39f5..c11ab68 100644 --- a/hibc-lic-barcode/batch-generate-ten-code-39-hibc-lic-barcodes-with-varying-primary-product-numbers-and-store-them-in-zip-archive.cs +++ b/hibc-lic-barcode/batch-generate-ten-code-39-hibc-lic-barcodes-with-varying-primary-product-numbers-and-store-them-in-zip-archive.cs @@ -1,79 +1,81 @@ -// Title: Batch Generation of Code 39 HIBC LIC Barcodes and Zipping -// Description: Generates ten Code 39 HIBC LIC barcodes with unique primary product numbers, saves them as PNG images, and packages them into a zip archive. -// Category-Description: This example demonstrates Aspose.BarCode's complex barcode generation for HIBC Code 39 LIC symbology using the ComplexBarcodeGenerator and HIBCLICPrimaryDataCodetext classes. It shows how to create multiple barcodes in a batch, customize primary data fields, and archive the results. Developers working with healthcare or logistics labeling often need to produce HIBC‑compliant barcodes programmatically and bundle them for distribution. +// Title: Batch generate HIBC Code 39 LIC barcodes and archive them in a ZIP file +// Description: Demonstrates generating ten HIBC Code 39 LIC barcodes with unique product numbers, saving each as a PNG image, and packaging the images into a zip archive. +// Category-Description: This example belongs to the Aspose.BarCode generation category, focusing on complex barcode creation using the ComplexBarcodeGenerator class. It showcases typical use cases such as batch barcode production for inventory labeling, where developers need to programmatically create multiple barcodes with varying data and bundle the results for distribution or storage. // Prompt: Batch generate ten Code 39 HIBC LIC barcodes with varying primary product numbers and store them in a zip archive. -// Tags: barcode symbology, batch generation, png, zip, complexbarcode, hibc, code39 +// Tags: barcode symbology, generation, zip, code39, hibc, lic, aspose.barcode, complexbarcode using System; using System.IO; using System.IO.Compression; -using Aspose.BarCode.ComplexBarcode; +using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.Drawing; +using Aspose.BarCode.ComplexBarcode; /// -/// Demonstrates batch creation of Code 39 HIBC LIC barcodes and archiving them into a zip file. +/// Demonstrates batch generation of HIBC Code 39 LIC barcodes and archiving them. /// class Program { /// - /// Entry point of the example. Generates barcodes, saves them as PNG files, and creates a zip archive. + /// Entry point that creates barcode images, stores them, and zips the collection. /// static void Main() { - // Define the output directory for generated barcode images. + // Directory to store individual barcode images string outputDir = Path.Combine(Directory.GetCurrentDirectory(), "Barcodes"); if (!Directory.Exists(outputDir)) { - // Create the directory if it does not already exist. Directory.CreateDirectory(outputDir); } - // Loop to generate 10 distinct Code 39 HIBC LIC barcodes. + // Generate 10 HIBC Code 39 LIC barcodes with different primary product numbers for (int i = 1; i <= 10; i++) { - // Prepare primary data with a unique product number for each barcode. - var primaryData = new PrimaryData - { - ProductOrCatalogNumber = $"P{i:D4}", // e.g., P0001, P0002, ... - LabelerIdentificationCode = "A999", - UnitOfMeasureID = 1 - }; + // Example primary product number (e.g., "P00001", "P00002", ...) + string productNumber = $"P{i:D5}"; - // Build the complex codetext specifying the HIBC Code 39 LIC symbology. - var codetext = new HIBCLICPrimaryDataCodetext + // Build the complex codetext for HIBC Code 39 LIC + var complexCodetext = new HIBCLICPrimaryDataCodetext { BarcodeType = EncodeTypes.HIBCCode39LIC, - Data = primaryData + Data = new PrimaryData + { + ProductOrCatalogNumber = productNumber, + LabelerIdentificationCode = "A999", + UnitOfMeasureID = 1 + } }; - // Determine the file path for the current barcode image. - string filePath = Path.Combine(outputDir, $"barcode_{i}.png"); - - // Generate the barcode image and save it to the file system. - using (var generator = new ComplexBarcodeGenerator(codetext)) + // Generate the barcode image and save it as PNG + string imagePath = Path.Combine(outputDir, $"barcode{i}.png"); + using (var generator = new ComplexBarcodeGenerator(complexCodetext)) { - generator.Save(filePath); + generator.Save(imagePath); } - - Console.WriteLine($"Generated barcode {i}: {filePath}"); } - // Path for the resulting zip archive containing all barcode images. + // Create a ZIP archive containing all generated barcode images string zipPath = Path.Combine(Directory.GetCurrentDirectory(), "Barcodes.zip"); + if (File.Exists(zipPath)) + { + File.Delete(zipPath); + } - // Create the zip archive and add each PNG file from the output directory. using (var zipStream = new FileStream(zipPath, FileMode.Create)) using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Create)) { - foreach (string file in Directory.GetFiles(outputDir, "*.png")) + foreach (string filePath in Directory.GetFiles(outputDir, "*.png")) { - string entryName = Path.GetFileName(file); - archive.CreateEntryFromFile(file, entryName); - Console.WriteLine($"Added {entryName} to zip archive."); + string entryName = Path.GetFileName(filePath); + archive.CreateEntryFromFile(filePath, entryName); } } - Console.WriteLine($"All barcodes have been zipped to: {zipPath}"); + // Optional: clean up the temporary image files + // foreach (string filePath in Directory.GetFiles(outputDir, "*.png")) + // { + // File.Delete(filePath); + // } + // Directory.Delete(outputDir); } } \ No newline at end of file diff --git a/hibc-lic-barcode/cast-returned-hibcliccomplexcodetext-to-hibclicsecondaryandadditionaldatacodetext-to-access-expiration-date-for-inventor.cs b/hibc-lic-barcode/cast-returned-hibcliccomplexcodetext-to-hibclicsecondaryandadditionaldatacodetext-to-access-expiration-date-for-inventor.cs index aaafd8f..efcf33b 100644 --- a/hibc-lic-barcode/cast-returned-hibcliccomplexcodetext-to-hibclicsecondaryandadditionaldatacodetext-to-access-expiration-date-for-inventor.cs +++ b/hibc-lic-barcode/cast-returned-hibcliccomplexcodetext-to-hibclicsecondaryandadditionaldatacodetext-to-access-expiration-date-for-inventor.cs @@ -1,79 +1,73 @@ -// Title: HIBC Secondary Data Barcode Generation and Decoding -// Description: Demonstrates generating a HIBC Code128 LIC barcode that carries secondary data (expiration date, lot number) and decoding it to retrieve the expiration date for inventory processing. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode operations collection. It showcases the use of ComplexBarcodeGenerator, ComplexCodetextReader, and HIBCLICSecondaryAndAdditionalDataCodetext to create and read HIBC‑LIC barcodes. Typical scenarios include healthcare product tracking, pharmaceutical inventory, and any application that needs to embed and later extract secondary information such as expiry dates. Developers often need to generate compliant HIBC barcodes, embed additional data, and reliably decode that data for downstream processing. +// Title: Decode HIBC QRLIC barcode and access secondary data (expiry date) +// Description: Demonstrates generating a HIBC QRLIC barcode with secondary and additional data, then decoding it to retrieve the expiration date and lot number. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode operations collection. It showcases how to use ComplexBarcodeGenerator to create a HIBCLICSecondaryAndAdditionalDataCodetext, save the barcode as PNG, and employ BarCodeReader with DecodeType.HIBCQRLIC to read and interpret the complex codetext. Developers working with healthcare inventory or regulatory labeling often need to embed and extract secondary data such as expiry dates, lot numbers, and other attributes using the HIBC QRLIC symbology. // Prompt: Cast the returned HIBCLICComplexCodetext to HIBCLICSecondaryAndAdditionalDataCodetext to access expiration date for inventory processing. -// Tags: hibc, secondary-data, barcode-generation, barcode-decoding, complex-barcode, aspose.barcode +// Tags: hibc, secondary-and-additional-data, barcode generation, barcode recognition, png, complexbarcode, aspose.barcode using System; -using Aspose.BarCode.ComplexBarcode; +using System.IO; +using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.BarCode.BarCodeRecognition; -using Aspose.Drawing; -using Aspose.Drawing.Imaging; +using Aspose.BarCode.ComplexBarcode; /// -/// Generates a HIBC Code128 LIC barcode containing secondary data, saves the image, -/// reads it back, and extracts the expiration date for inventory processing. +/// Example program that generates a HIBC QRLIC barcode containing secondary data, +/// then decodes the barcode and extracts the expiration date and lot number. /// class Program { /// - /// Entry point of the example. Executes barcode generation, saving, decoding, - /// and extraction of the expiration date from the decoded complex codetext. + /// Entry point of the example. Generates, saves, reads, and processes a HIBC QRLIC barcode. /// static void Main() { // Prepare secondary data with an expiration date and lot number var secondaryData = new SecondaryAndAdditionalData { - ExpiryDate = DateTime.Today.AddDays(30), // Set expiry 30 days from today - ExpiryDateFormat = HIBCLICDateFormat.MMDDYY, // Use MMDDYY format as required by HIBC - LotNumber = "LOT123" // Example lot identifier + ExpiryDate = DateTime.Today, + ExpiryDateFormat = HIBCLICDateFormat.MMDDYY, + LotNumber = "LOT123" }; - // Create the complex codetext that holds only secondary data + // Create a complex codetext object that holds the secondary data var complexCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext { - BarcodeType = EncodeTypes.HIBCCode128LIC, // Specify HIBC Code128 LIC symbology - LinkCharacter = '+', // Standard link character for HIBC - Data = secondaryData // Attach the secondary data object + BarcodeType = EncodeTypes.HIBCQRLIC, + LinkCharacter = '+', + Data = secondaryData }; - // Generate the barcode image using the complex codetext - using (var generator = new ComplexBarcodeGenerator(complexCodetext)) - using (Bitmap bitmap = generator.GenerateBarCodeImage()) + // Generate the barcode image and store it in a memory stream + using (var imageStream = new MemoryStream()) { - // Optionally save the image to verify generation (not required for processing) - bitmap.Save("hibc_secondary.png", ImageFormat.Png); - - // Decode the barcode from the generated image - using (var reader = new BarCodeReader(bitmap, DecodeType.HIBCCode128LIC)) + using (var generator = new ComplexBarcodeGenerator(complexCodetext)) { - var results = reader.ReadBarCodes(); - - // Ensure at least one barcode was detected - if (results.Length == 0) - { - Console.WriteLine("No barcode detected."); - return; - } - - // Retrieve the raw codetext from the first detection result - string rawCodeText = results[0].CodeText; + // Save the generated barcode as PNG into the stream + generator.Save(imageStream, BarCodeImageFormat.Png); + } - // Parse the raw codetext into a strongly‑typed complex codetext object - var parsed = ComplexCodetextReader.TryDecodeHIBCLIC(rawCodeText); + // Reset stream position to the beginning for reading + imageStream.Position = 0; - // Cast to the specific secondary‑data codetext type to access expiration information - if (parsed is HIBCLICSecondaryAndAdditionalDataCodetext secondaryResult) - { - // Access the expiration date for inventory processing - DateTime expiry = secondaryResult.Data.ExpiryDate; - Console.WriteLine($"Expiration Date: {expiry:yyyy-MM-dd}"); - } - else + // Decode the barcode image from the memory stream + using (var reader = new BarCodeReader(imageStream, DecodeType.HIBCQRLIC)) + { + foreach (var result in reader.ReadBarCodes()) { - Console.WriteLine("Decoded codetext is not of secondary data type."); + // Attempt to decode the raw codetext into a complex codetext object + var decoded = ComplexCodetextReader.TryDecodeHIBCLIC(result.CodeText); + + // Cast to the specific secondary-and-additional-data type to access expiry information + if (decoded is HIBCLICSecondaryAndAdditionalDataCodetext secondary) + { + Console.WriteLine("Expiry date: " + secondary.Data.ExpiryDate); + Console.WriteLine("Lot number: " + secondary.Data.LotNumber); + } + else + { + Console.WriteLine("Decoded codetext is not of the expected secondary data type."); + } } } } diff --git a/hibc-lic-barcode/configure-barcode-generator-to-use-high-dpi-300-for-sharper-datamatrix-hibc-lic-images-in-medical-reports.cs b/hibc-lic-barcode/configure-barcode-generator-to-use-high-dpi-300-for-sharper-datamatrix-hibc-lic-images-in-medical-reports.cs index e1e9a9d..07bb48f 100644 --- a/hibc-lic-barcode/configure-barcode-generator-to-use-high-dpi-300-for-sharper-datamatrix-hibc-lic-images-in-medical-reports.cs +++ b/hibc-lic-barcode/configure-barcode-generator-to-use-high-dpi-300-for-sharper-datamatrix-hibc-lic-images-in-medical-reports.cs @@ -1,49 +1,56 @@ -// Title: Generate high-resolution HIBC DataMatrix LIC barcode -// Description: Demonstrates configuring Aspose.BarCode to produce a 300 DPI DataMatrix HIBC LIC barcode, useful for clear printing in medical reports. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category, focusing on HIBC (Health Industry Bar Code) symbology. It showcases the use of ComplexBarcodeGenerator, HIBCLICSecondaryAndAdditionalDataCodetext, and SecondaryAndAdditionalData classes to embed lot and serial numbers. Developers creating medical or pharmaceutical labels often need high-resolution barcodes for accurate scanning and regulatory compliance. +// Title: Generate high‑resolution HIBC DataMatrix LIC barcode image +// Description: Demonstrates configuring Aspose.BarCode to produce a 300 DPI DataMatrix HIBC LIC barcode, suitable for clear rendering in medical reports. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating how to set image resolution, module size, and colors using the BarcodeGenerator class. Typical use cases include creating high‑quality barcodes for healthcare documentation, inventory, and labeling where precise scanning is required. Developers often need to adjust DPI and visual parameters to meet regulatory and readability standards. // Prompt: Configure the barcode generator to use high DPI (300) for sharper DataMatrix HIBC LIC images in medical reports. -// Tags: datamatrix, hibc, lic, highdpi, barcode, generation, aspnet, aspnetcore +// Tags: datamatrix, hibc, barcode-generation, png, aspose.barcode, aspose.drawing using System; -using Aspose.BarCode.ComplexBarcode; +using System.IO; +using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.Drawing; /// -/// Demonstrates generating a high‑resolution HIBC DataMatrix LIC barcode using Aspose.BarCode. +/// Demonstrates generating a high‑resolution HIBC DataMatrix LIC barcode image. /// class Program { /// - /// Entry point. Creates secondary data, builds complex codetext, sets DPI to 300, and saves the barcode as PNG. + /// Entry point. Generates the barcode and saves it as a PNG file. /// static void Main() { - // Prepare secondary data for HIBC LIC DataMatrix barcode - var secondaryData = new SecondaryAndAdditionalData - { - LotNumber = "LOT123", - SerialNumber = "SN001" - }; + // Sample HIBC DataMatrix LIC codetext (replace with actual medical report data as needed) + string codeText = "A12345B67890"; + + // Define the output file path in the current working directory + string outputPath = Path.Combine(Directory.GetCurrentDirectory(), "HIBCDataMatrixLIC.png"); - // Configure complex codetext with required link character - var complexCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext + // Ensure the output directory exists before saving the image + string outputDir = Path.GetDirectoryName(outputPath); + if (!Directory.Exists(outputDir)) { - BarcodeType = EncodeTypes.HIBCDataMatrixLIC, - LinkCharacter = '+', - Data = secondaryData - }; + Directory.CreateDirectory(outputDir); + } - // Generate the barcode with high DPI (300) - using (var generator = new ComplexBarcodeGenerator(complexCodetext)) + // Initialize the barcode generator with HIBC DataMatrix LIC symbology and the provided code text + using (var generator = new BarcodeGenerator(EncodeTypes.HIBCDataMatrixLIC, codeText)) { - // Set the resolution (dots per inch) to 300 for sharper output - generator.Parameters.Resolution = 300f; - // Save the generated barcode image as PNG - generator.Save("hibc_datamatrix_lic.png"); + // Set high DPI resolution (300 DPI) for a sharper image suitable for printing + generator.Parameters.Resolution = 300; + + // Optional: adjust the module (X) dimension for better readability + generator.Parameters.Barcode.XDimension.Point = 2f; + + // Define barcode colors: black bars on a white background + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; + + // Save the generated barcode as a PNG file + generator.Save(outputPath, BarCodeImageFormat.Png); } - // Inform the user that generation succeeded - Console.WriteLine("HIBC DataMatrix LIC barcode generated with 300 DPI."); + // Inform the user where the image was saved + Console.WriteLine($"Barcode image saved to: {outputPath}"); } } \ No newline at end of file diff --git a/hibc-lic-barcode/configure-barcode-image-size-to-300-150-pixels-before-rendering-datamatrix-hibc-lic-barcode.cs b/hibc-lic-barcode/configure-barcode-image-size-to-300-150-pixels-before-rendering-datamatrix-hibc-lic-barcode.cs index 78085a8..bed9ec1 100644 --- a/hibc-lic-barcode/configure-barcode-image-size-to-300-150-pixels-before-rendering-datamatrix-hibc-lic-barcode.cs +++ b/hibc-lic-barcode/configure-barcode-image-size-to-300-150-pixels-before-rendering-datamatrix-hibc-lic-barcode.cs @@ -1,51 +1,43 @@ -// Title: Configure Image Size for HIBC DataMatrix LIC Barcode -// Description: Demonstrates setting the barcode image dimensions to 300 × 150 pixels before generating a DataMatrix HIBC LIC barcode using Aspose.BarCode. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It showcases the use of ComplexBarcodeGenerator, HIBCLICSecondaryAndAdditionalDataCodetext, and SecondaryAndAdditionalData classes to create HIBC‑LIC DataMatrix barcodes. Developers often need to control image size, format, and secondary data when integrating barcodes into packaging, labeling, or inventory systems. -// Prompt: Configure barcode image size to 300 × 150 pixels before rendering a DataMatrix HIBC LIC barcode. -// Tags: datamatrix, hibc, lic, image-size, generation, png, aspose.barcode, complexbarcodegenerator +// Title: Generate HIBC DataMatrix LIC barcode with custom image size +// Description: Demonstrates how to set a specific image size (300 × 150 pixels) and generate a DataMatrix HIBC LIC barcode using Aspose.BarCode. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to configure image dimensions, colors, and save the result as a PNG. It showcases the BarcodeGenerator class with EncodeTypes.HIBCDataMatrixLIC, a common scenario for developers needing HIBC‑compliant DataMatrix barcodes in healthcare labeling. +// Prompt: Configure barcode image size to 300 × 150 pixels before rendering a DataMatrix HIBC LIC barcode. +// Tags: barcode, datamatrix, hibc, image-size, png, generation, aspose.barcodes, aspose.drawing using System; -using Aspose.BarCode.ComplexBarcode; +using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.BarCode.BarCodeRecognition; using Aspose.Drawing; -using Aspose.Drawing.Imaging; /// -/// Example program that generates a HIBC DataMatrix LIC barcode with a custom image size. +/// Demonstrates configuring image size and generating a HIBC DataMatrix LIC barcode. /// class Program { /// - /// Entry point. Prepares secondary data, configures barcode parameters, and saves the image. + /// Entry point that creates and saves the barcode image. /// static void Main() { - // Prepare secondary data for the HIBC LIC DataMatrix barcode (e.g., lot number). - var secondaryData = new SecondaryAndAdditionalData - { - LotNumber = "LOT123" - }; - - // Create complex codetext that combines barcode type, link character, and secondary data. - var complexCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext - { - BarcodeType = EncodeTypes.HIBCDataMatrixLIC, - LinkCharacter = '+', - Data = secondaryData - }; + // Sample HIBC DataMatrix LIC codetext (adjust as needed for a valid HIBC string) + string codeText = "A12345"; - // Generate the barcode using ComplexBarcodeGenerator. - using (var generator = new ComplexBarcodeGenerator(complexCodetext)) + // Initialize the barcode generator for HIBC DataMatrix LIC symbology + using (var generator = new BarcodeGenerator(EncodeTypes.HIBCDataMatrixLIC, codeText)) { - // Set the desired image dimensions (300 × 150 pixels). + // Set the desired image size: 300 × 150 pixels generator.Parameters.ImageWidth.Point = 300f; generator.Parameters.ImageHeight.Point = 150f; - // Save the generated barcode as a PNG file. - generator.Save("HIBC_DataMatrix_LIC.png"); + // Optional: define foreground (bar) and background colors + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; + + // Save the generated barcode as a PNG file + generator.Save("HIBCDataMatrixLIC.png"); } - // Inform the user that the barcode has been created. - Console.WriteLine("Barcode generated and saved as HIBC_DataMatrix_LIC.png"); + Console.WriteLine("Barcode generated and saved as HIBCDataMatrixLIC.png"); } } \ No newline at end of file diff --git a/hibc-lic-barcode/create-hibcliccombinedcodetext-set-lot-number-and-unit-of-measure-then-generate-code-39-barcode.cs b/hibc-lic-barcode/create-hibcliccombinedcodetext-set-lot-number-and-unit-of-measure-then-generate-code-39-barcode.cs index 1e25a2a..d27f138 100644 --- a/hibc-lic-barcode/create-hibcliccombinedcodetext-set-lot-number-and-unit-of-measure-then-generate-code-39-barcode.cs +++ b/hibc-lic-barcode/create-hibcliccombinedcodetext-set-lot-number-and-unit-of-measure-then-generate-code-39-barcode.cs @@ -1,60 +1,50 @@ -// Title: Generate HIBC LIC Code 39 Barcode with Lot Number and Unit of Measure -// Description: Demonstrates creating a HIBCLICCombinedCodetext, setting the lot number and unit of measure, and generating a Code 39 barcode image. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It showcases the use of HIBCLICCombinedCodetext, ComplexBarcodeGenerator, and related classes to produce HIBC‑LIC barcodes. Developers often need to encode product information, lot numbers, and measurement units for healthcare and logistics applications, and this snippet illustrates the typical workflow for such scenarios. +// Title: Generate a HIBC Code 39 LIC barcode with lot number and unit of measure +// Description: Demonstrates creating a HIBCLICCombinedCodetext, setting required primary fields and a lot number, then generating a Code 39 barcode image. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category, illustrating how to use HIBCLICCombinedCodetext with ComplexBarcodeGenerator. Developers commonly use these APIs to create HIBC‑compliant barcodes for medical and pharmaceutical labeling, customizing primary and secondary data such as product numbers, unit of measure, and lot numbers. // Prompt: Create a HIBCLICCombinedCodetext, set lot number and unit of measure, then generate a Code 39 barcode. -// Tags: code39, barcode-generation, png, hibcliccombinedcodetext, complexbarcode, complexbarcodegenerator, bitmap +// Tags: code39, hibc, barcode generation, png, complexbarcode, hibliccombinedcodetext using System; -using Aspose.BarCode.ComplexBarcode; using Aspose.BarCode.Generation; -using Aspose.Drawing; -using Aspose.Drawing.Imaging; +using Aspose.BarCode.ComplexBarcode; /// -/// Example program that builds a HIBCLICCombinedCodetext with lot number and unit of measure, -/// then generates a Code 39 barcode image using Aspose.BarCode. +/// Demonstrates generation of a HIBC Code 39 LIC barcode using Aspose.BarCode. /// class Program { /// - /// Entry point. Creates the combined codetext, generates the barcode, and saves it as PNG. + /// Entry point. Builds the combined codetext, configures required fields, and saves the barcode image. /// static void Main() { - // Initialize combined HIBC LIC codetext with required fields - var combinedCodetext = new HIBCLICCombinedCodetext - { - // Specify Code 39 LIC symbology (default) for clarity - BarcodeType = EncodeTypes.HIBCCode39LIC, + // Create a combined HIBC LIC codetext object that holds both primary and secondary data. + var combinedCodetext = new HIBCLICCombinedCodetext(); - // Primary data includes product number, labeler ID, and unit of measure - PrimaryData = new PrimaryData - { - ProductOrCatalogNumber = "12345", - LabelerIdentificationCode = "A999", - UnitOfMeasureID = 1 // Set unit of measure identifier - }, + // Specify the barcode symbology: HIBC Code 39 LIC. + combinedCodetext.BarcodeType = EncodeTypes.HIBCCode39LIC; - // Secondary data includes the lot number; other fields are optional - SecondaryAndAdditionalData = new SecondaryAndAdditionalData - { - LotNumber = "LOT123" // Set lot number - // Additional secondary fields can be left unset - } + // Populate primary data (mandatory fields) such as product number, labeler ID, and unit of measure. + combinedCodetext.PrimaryData = new PrimaryData + { + ProductOrCatalogNumber = "12345", + LabelerIdentificationCode = "A999", + UnitOfMeasureID = 1 // Unit of measure identifier. + }; + + // Populate secondary data with optional information, e.g., the lot number. + combinedCodetext.SecondaryAndAdditionalData = new SecondaryAndAdditionalData + { + LotNumber = "LOT123" }; - // Use ComplexBarcodeGenerator to create the barcode image from the codetext + // Generate the barcode using ComplexBarcodeGenerator and save it as a PNG file. using (var generator = new ComplexBarcodeGenerator(combinedCodetext)) { - // Generate the bitmap representation of the barcode - using (Bitmap bitmap = generator.GenerateBarCodeImage()) - { - // Save the bitmap as a PNG file - bitmap.Save("hibc_combined_code39.png", ImageFormat.Png); - } + generator.Save("hibc_code39.png"); } - // Inform the user that the barcode has been generated - Console.WriteLine("HIBC LIC Code 39 barcode generated: hibc_combined_code39.png"); + // Inform the user that the barcode image has been created. + Console.WriteLine("Barcode generated: hibc_code39.png"); } } \ No newline at end of file diff --git a/hibc-lic-barcode/create-hibclicprimarydatacodetext-set-labeler-id-and-generate-bmp-image-of-barcode.cs b/hibc-lic-barcode/create-hibclicprimarydatacodetext-set-labeler-id-and-generate-bmp-image-of-barcode.cs index 982aabd..f79238a 100644 --- a/hibc-lic-barcode/create-hibclicprimarydatacodetext-set-labeler-id-and-generate-bmp-image-of-barcode.cs +++ b/hibc-lic-barcode/create-hibclicprimarydatacodetext-set-labeler-id-and-generate-bmp-image-of-barcode.cs @@ -1,50 +1,53 @@ // Title: Generate HIBC Code 128 LIC barcode with primary data and save as BMP -// Description: Demonstrates creating a HIBCLICPrimaryDataCodetext, setting the labeler ID, and generating a BMP image of the barcode. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category, showcasing the use of ComplexBarcodeGenerator with HIBCCode128LIC symbology. It illustrates how to configure primary data fields, such as product number and labeler identification, and render the barcode to a bitmap image. Developers needing to produce HIBC-compliant barcodes for medical or pharmaceutical labeling can follow this pattern. +// Description: Demonstrates creating a HIBCLICPrimaryDataCodetext, setting the labeler ID, and exporting the barcode to a BMP image file. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It showcases the use of ComplexBarcodeGenerator with HIBC Code 128 LIC symbology, illustrating how to populate primary data fields such as product number and labeler identification. Developers working with healthcare or logistics barcodes can reference this pattern for creating compliant HIBC barcodes and saving them in various image formats. // Prompt: Create a HIBCLICPrimaryDataCodetext, set labeler ID, and generate a BMP image of the barcode. -// Tags: hibc, code128lic, barcode generation, bmp, complexbarcode, aspnet, aspose.barcode +// Tags: hibc, code128lic, complexbarcode, barcode generation, bmp, aspnet.barcode, aspose.barcode using System; -using Aspose.BarCode.ComplexBarcode; +using System.IO; using Aspose.BarCode.Generation; -using Aspose.Drawing; +using Aspose.BarCode.ComplexBarcode; using Aspose.Drawing.Imaging; -/// -/// Example program that creates a HIBCLIC primary data codetext, -/// sets the labeler identification code, and saves the generated barcode as a BMP image. -/// -class Program +namespace BarcodeSample { /// - /// Entry point of the application. + /// Entry point for the barcode generation sample. /// - static void Main() + class Program { - // Initialize HIBCLIC primary data codetext with required fields - var primaryCodetext = new HIBCLICPrimaryDataCodetext + /// + /// Creates a HIBCLICPrimaryDataCodetext, generates a barcode, and saves it as a BMP file. + /// + static void Main() { - BarcodeType = EncodeTypes.HIBCCode128LIC, - Data = new PrimaryData + // Initialize primary data codetext for HIBC Code 128 LIC barcode + var primaryCodetext = new HIBCLICPrimaryDataCodetext { - ProductOrCatalogNumber = "12345", - LabelerIdentificationCode = "A999", // labeler ID - UnitOfMeasureID = 1 - } - }; + // Select the HIBC Code 128 LIC symbology + BarcodeType = EncodeTypes.HIBCCode128LIC, + // Populate the required primary data fields + Data = new PrimaryData + { + ProductOrCatalogNumber = "12345", + LabelerIdentificationCode = "A999", // labeler ID + UnitOfMeasureID = 1 // optional, example value + } + }; - // Generate the barcode image using ComplexBarcodeGenerator - using (var generator = new ComplexBarcodeGenerator(primaryCodetext)) - { - // Render the barcode to a bitmap - using (Bitmap bitmap = generator.GenerateBarCodeImage()) + // Use ComplexBarcodeGenerator to create the barcode image + using (var generator = new ComplexBarcodeGenerator(primaryCodetext)) { - // Save the bitmap as a BMP file - bitmap.Save("hibc_primary.bmp", ImageFormat.Bmp); + // Define output file path + string outputPath = "hibc_primary.bmp"; + + // Save the generated barcode as a BMP image + generator.Save(outputPath, BarCodeImageFormat.Bmp); + + // Inform the user where the file was saved + Console.WriteLine($"Barcode image saved to: {Path.GetFullPath(outputPath)}"); } } - - // Inform the user that the image has been saved - Console.WriteLine("Barcode image saved as hibc_primary.bmp"); } } \ No newline at end of file diff --git a/hibc-lic-barcode/create-hibclicsecondaryandadditionaldatacodetext-set-expiration-date-and-generate-datamatrix-barcode.cs b/hibc-lic-barcode/create-hibclicsecondaryandadditionaldatacodetext-set-expiration-date-and-generate-datamatrix-barcode.cs index 67aab48..67879c3 100644 --- a/hibc-lic-barcode/create-hibclicsecondaryandadditionaldatacodetext-set-expiration-date-and-generate-datamatrix-barcode.cs +++ b/hibc-lic-barcode/create-hibclicsecondaryandadditionaldatacodetext-set-expiration-date-and-generate-datamatrix-barcode.cs @@ -1,52 +1,62 @@ -// Title: Generate HIBC LIC Secondary Data DataMatrix Barcode -// Description: Creates a HIBCLICSecondaryAndAdditionalDataCodetext with an expiration date and encodes it as a DataMatrix barcode. -// Category-Description: This example demonstrates the use of Aspose.BarCode's ComplexBarcodeGenerator to produce HIBC (Health Industry Bar Code) LIC (Labeler Identification Code) barcodes with secondary and additional data. It showcases key API classes such as HIBCLICSecondaryAndAdditionalDataCodetext, SecondaryAndAdditionalData, and ComplexBarcodeGenerator, which are commonly used for healthcare labeling, inventory tracking, and regulatory compliance. Developers looking to embed lot numbers, serial numbers, and expiry dates into DataMatrix barcodes will find this pattern useful. +// Title: Generate HIBCLIC DataMatrix Barcode with Expiration Date +// Description: Demonstrates how to create a HIBCLIC secondary and additional data codetext, set an expiration date, and generate a DataMatrix barcode image using Aspose.BarCode. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It showcases the use of ComplexBarcodeGenerator together with HIBCLICSecondaryAndAdditionalDataCodetext to produce HIBC‑compliant DataMatrix barcodes. Typical use cases include labeling pharmaceutical or medical devices where secondary data such as expiry date, lot number, and serial number must be encoded. Developers often need to combine HIBC standards with Aspose.BarCode's EncodeTypes and complex data structures to meet regulatory labeling requirements. // Prompt: Create a HIBCLICSecondaryAndAdditionalDataCodetext, set expiration date, and generate a DataMatrix barcode. -// Tags: hibc, datamatrix, secondary data, expiration date, complexbarcode, generation, png +// Tags: hibc, datamatrix, barcode, generation, complexbarcode, aspose.barcode using System; -using Aspose.BarCode.ComplexBarcode; +using System.IO; using Aspose.BarCode.Generation; -using Aspose.Drawing; +using Aspose.BarCode.ComplexBarcode; /// -/// Demonstrates how to create a HIBCLICSecondaryAndAdditionalDataCodetext, -/// set an expiration date, and generate a DataMatrix barcode using Aspose.BarCode. +/// Example program that creates a HIBCLIC secondary and additional data codetext, +/// sets an expiration date, and generates a DataMatrix barcode image. /// class Program { /// - /// Entry point of the example. Builds the secondary data object, - /// configures the barcode generator, and saves the resulting image. + /// Entry point of the example. Builds the complex codetext, generates the barcode, + /// and saves it as a PNG file. /// static void Main() { - // Build secondary-and-additional data codetext for a HIBC LIC DataMatrix barcode - var secondaryCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext + // Initialize secondary and additional data codetext for HIBC LIC + var complexCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext { - BarcodeType = EncodeTypes.HIBCDataMatrixLIC, // Specify DataMatrix symbology for HIBC LIC - LinkCharacter = '+', // Required link character for HIBC format + // Specify the barcode symbology (DataMatrix) for HIBC LIC + BarcodeType = EncodeTypes.HIBCDataMatrixLIC, + // The link character is mandatory; '+' is the default value + LinkCharacter = '+', + // Populate secondary data such as expiry date, quantity, lot number, and serial number Data = new SecondaryAndAdditionalData { - ExpiryDate = DateTime.Now.AddDays(30), // Set expiration date 30 days from now - ExpiryDateFormat = HIBCLICDateFormat.MMDDYY, // Choose MMDDYY date format - LotNumber = "LOT123", // Example lot number - SerialNumber = "SERIAL123" // Example serial number + // Set expiration date to 30 days from now + ExpiryDate = DateTime.Now.AddDays(30), + // Define the date format (MMDDYY) required by HIBC + ExpiryDateFormat = HIBCLICDateFormat.MMDDYY, + // Example quantity value + Quantity = 10, + // Example lot number + LotNumber = "LOT123", + // Example serial number + SerialNumber = "SN001" } }; - // Initialize the complex barcode generator with the prepared codetext - using (var generator = new ComplexBarcodeGenerator(secondaryCodetext)) + // Generate the barcode using ComplexBarcodeGenerator + using (var generator = new ComplexBarcodeGenerator(complexCodetext)) { - // Optionally define the output image dimensions (in points) - generator.Parameters.ImageWidth.Point = 300f; - generator.Parameters.ImageHeight.Point = 300f; - - // Save the generated barcode as a PNG file - generator.Save("hibc_secondary_datamatrix.png"); + // Save the barcode image to a memory stream in PNG format + using (var ms = new MemoryStream()) + { + generator.Save(ms, BarCodeImageFormat.Png); + // Write the PNG bytes to a file on disk + File.WriteAllBytes("hibc_datamatrix.png", ms.ToArray()); + } } - // Inform the user that the barcode has been created successfully - Console.WriteLine("HIBC LIC secondary-data DataMatrix barcode generated successfully."); + // Inform the user that the barcode has been generated + Console.WriteLine("HIBC LIC DataMatrix barcode generated: hibc_datamatrix.png"); } } \ No newline at end of file diff --git a/hibc-lic-barcode/create-reusable-method-that-accepts-primary-data-parameters-and-returns-png-byte-array-of-generated-barcode.cs b/hibc-lic-barcode/create-reusable-method-that-accepts-primary-data-parameters-and-returns-png-byte-array-of-generated-barcode.cs index 0101872..b4311c7 100644 --- a/hibc-lic-barcode/create-reusable-method-that-accepts-primary-data-parameters-and-returns-png-byte-array-of-generated-barcode.cs +++ b/hibc-lic-barcode/create-reusable-method-that-accepts-primary-data-parameters-and-returns-png-byte-array-of-generated-barcode.cs @@ -1,61 +1,60 @@ -// Title: Generate barcode PNG as byte array -// Description: Demonstrates creating a barcode image in PNG format and returning it as a byte array for further processing or storage. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use the BarcodeGenerator class with AutoSizeMode and Save method to produce PNG images. Developers commonly need to generate barcodes dynamically for reports, labels, or web APIs, and this snippet shows the typical workflow of configuring parameters, encoding data, and retrieving the image as a byte array. +// Title: Generate Barcode PNG as Byte Array +// Description: Demonstrates how to generate a barcode image using Aspose.BarCode and return it as a PNG byte array. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of the BarcodeGenerator class together with BaseEncodeType and BarCodeImageFormat to create barcode images. Typical scenarios include creating barcodes for labels, tickets, or inventory systems where the image needs to be transmitted or stored as a byte array. Developers often need reusable methods that accept encoding parameters and produce image data without writing to disk. // Prompt: Create a reusable method that accepts primary data parameters and returns a PNG byte array of generated barcode. -// Tags: barcode, symbology, generation, png, byte-array, aspose.barcode, encode-types +// Tags: barcode, generation, png, byte-array, aspose.barcode, aspnet using System; using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing.Imaging; /// -/// Demonstrates barcode generation and returning the image as a PNG byte array. +/// Demonstrates barcode generation using Aspose.BarCode and returns the image as a PNG byte array. /// class Program { - /// - /// Generates a barcode image and returns it as a PNG byte array. - /// - /// The text to encode. - /// The barcode symbology (e.g., EncodeTypes.Code128). - /// Byte array containing the PNG image. - static byte[] GenerateBarcode(string codeText, BaseEncodeType encodeType) + // Generates a barcode image and returns it as a PNG byte array. + // Parameters: + // encodeType - the barcode symbology (e.g., EncodeTypes.Code128) + // codeText - the text to encode + // Returns: PNG image bytes + static byte[] GenerateBarcode(BaseEncodeType encodeType, string codeText) { - // Validate input parameters. + // Validate input to avoid generating an empty barcode. if (string.IsNullOrEmpty(codeText)) throw new ArgumentException("codeText cannot be null or empty.", nameof(codeText)); - if (encodeType == null) - throw new ArgumentNullException(nameof(encodeType)); - // Initialize the generator with the specified symbology and data. + // Create a generator instance with the specified symbology and data. using (var generator = new BarcodeGenerator(encodeType, codeText)) { - // Use interpolation mode so the image size adapts to the content. - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; + // Optional: customize appearance here, e.g. colors, dimensions, etc. + // generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + // generator.Parameters.BackColor = Aspose.Drawing.Color.White; // Save the generated barcode to a memory stream in PNG format. using (var ms = new MemoryStream()) { generator.Save(ms, BarCodeImageFormat.Png); - // Return the stream contents as a byte array. + // Return the raw PNG bytes. return ms.ToArray(); } } } /// - /// Entry point that generates a sample Code128 barcode and writes the PNG to disk. + /// Entry point that shows example usage of GenerateBarcode. /// static void Main() { - // Example: generate a Code128 barcode. - byte[] pngBytes = GenerateBarcode("1234567890", EncodeTypes.Code128); + // Example usage: generate a Code128 barcode. + byte[] pngBytes = GenerateBarcode(EncodeTypes.Code128, "123ABC"); - // Output the size of the generated byte array for verification. + // Output some info to verify execution. Console.WriteLine($"Generated PNG byte array length: {pngBytes.Length}"); - // Write the PNG to a file for visual verification (optional). - File.WriteAllBytes("sample.png", pngBytes); + // Optionally, write the image to a file for visual verification. + // File.WriteAllBytes("barcode.png", pngBytes); } } \ No newline at end of file diff --git a/hibc-lic-barcode/create-unit-test-verifying-correct-encoding-of-primary-fields-into-code-128-hibc-lic-barcode.cs b/hibc-lic-barcode/create-unit-test-verifying-correct-encoding-of-primary-fields-into-code-128-hibc-lic-barcode.cs index d97096e..4527f36 100644 --- a/hibc-lic-barcode/create-unit-test-verifying-correct-encoding-of-primary-fields-into-code-128-hibc-lic-barcode.cs +++ b/hibc-lic-barcode/create-unit-test-verifying-correct-encoding-of-primary-fields-into-code-128-hibc-lic-barcode.cs @@ -1,89 +1,72 @@ -// Title: Encode primary fields into Code 128 HIBC LIC barcode and verify via unit test -// Description: Demonstrates creating a HIBC LIC barcode from primary data fields, generating an image, and decoding it to confirm correct encoding. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation and recognition category. It shows how to use ComplexBarcodeGenerator with HIBCLICPrimaryDataCodetext, image generation, and BarCodeReader to validate encoding. Developers working with healthcare product identification (HIBC) often need to encode primary fields into a Code 128 LIC barcode and verify the result programmatically. +// Title: Unit Test for Encoding Primary Fields in Code 128 HIBC LIC Barcode +// Description: Demonstrates generating a Code 128 HIBC LIC barcode from primary data, then decoding it to verify that the encoded fields match the original values. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation and recognition category. It shows how to use the ComplexBarcodeGenerator with HIBCLICPrimaryDataCodetext, EncodeTypes.HIBCCode128LIC, and BarCodeReader to create and validate HIBC‑LIC barcodes. Developers working with healthcare or logistics labeling often need to encode primary product information into HIBC barcodes and confirm correctness via decoding. // Prompt: Create a unit test verifying correct encoding of primary fields into a Code 128 HIBC LIC barcode. -// Tags: barcode symbology, encoding, png, complexbarcode, generator, reader +// Tags: barcode, code128, hibc, lic, complexbarcode, generation, recognition, unit-test, aspose.barcode using System; using System.IO; -using Aspose.BarCode.ComplexBarcode; using Aspose.BarCode.Generation; using Aspose.BarCode.BarCodeRecognition; -using Aspose.Drawing; -using Aspose.Drawing.Imaging; +using Aspose.BarCode.ComplexBarcode; /// -/// Example program that generates a HIBC LIC Code 128 barcode from primary data, -/// then reads it back to verify that the encoded fields match the original values. +/// Demonstrates a simple verification of primary field encoding for a Code 128 HIBC LIC barcode using Aspose.BarCode. /// class Program { /// - /// Entry point of the example. Performs barcode generation, image saving, - /// decoding, and validation of primary data fields. + /// Entry point that generates a barcode from primary data, decodes it, and checks field integrity. /// static void Main() { - // Define primary data fields that will be encoded into the barcode - const string productNumber = "12345"; - const string labelerCode = "A999"; - const int unitOfMeasure = 1; + // Prepare primary data for HIBC LIC Code128 barcode + var primaryData = new PrimaryData + { + ProductOrCatalogNumber = "12345", + LabelerIdentificationCode = "A999", + UnitOfMeasureID = 1 + }; - // Build the complex codetext object with the required primary data - var primaryCodetext = new HIBCLICPrimaryDataCodetext + // Build complex codetext containing only the primary data + var complexCodetext = new HIBCLICPrimaryDataCodetext { BarcodeType = EncodeTypes.HIBCCode128LIC, - Data = new PrimaryData - { - ProductOrCatalogNumber = productNumber, - LabelerIdentificationCode = labelerCode, - UnitOfMeasureID = unitOfMeasure - } + Data = primaryData }; - // Generate the barcode image using ComplexBarcodeGenerator - using (var generator = new ComplexBarcodeGenerator(primaryCodetext)) - // Render the barcode to an image object - using (var image = generator.GenerateBarCodeImage()) - // Prepare a memory stream to hold the PNG data + // Generate the barcode image and store it in a memory stream + using (var generator = new ComplexBarcodeGenerator(complexCodetext)) using (var ms = new MemoryStream()) { - // Save the image as PNG into the memory stream - image.Save(ms, ImageFormat.Png); + generator.Save(ms, BarCodeImageFormat.Png); ms.Position = 0; // Reset stream position for reading - // Decode the barcode from the memory stream using BarCodeReader + // Decode the barcode from the memory stream using (var reader = new BarCodeReader(ms, DecodeType.HIBCCode128LIC)) { var results = reader.ReadBarCodes(); - // Verify that at least one barcode was detected + // Verify that a barcode was detected if (results.Length == 0) { Console.WriteLine("FAILED: No barcode detected."); return; } - // Extract the raw codetext from the first detection result + // Extract the decoded text and attempt to parse it as primary data codetext var decodedText = results[0].CodeText; + var decodedCodetext = ComplexCodetextReader.TryDecodeHIBCLIC(decodedText) as HIBCLICPrimaryDataCodetext; - // Parse the complex codetext back into a HIBCLICPrimaryDataCodetext object - var decodedComplex = ComplexCodetextReader.TryDecodeHIBCLIC(decodedText) as HIBCLICPrimaryDataCodetext; - - // Ensure decoding succeeded and returned the expected type - if (decodedComplex == null) - { - Console.WriteLine("FAILED: Decoding returned null or wrong type."); - return; - } - - // Compare each primary field with the original values - bool passed = decodedComplex.Data.ProductOrCatalogNumber == productNumber && - decodedComplex.Data.LabelerIdentificationCode == labelerCode && - decodedComplex.Data.UnitOfMeasureID == unitOfMeasure; + // Compare each field of the decoded data with the original primary data + bool passed = decodedCodetext != null && + decodedCodetext.Data.ProductOrCatalogNumber == primaryData.ProductOrCatalogNumber && + decodedCodetext.Data.LabelerIdentificationCode == primaryData.LabelerIdentificationCode && + decodedCodetext.Data.UnitOfMeasureID == primaryData.UnitOfMeasureID; // Output the test result - Console.WriteLine(passed ? "PASSED" : "FAILED"); + Console.WriteLine(passed ? "PASSED: Primary fields encoded and decoded correctly." + : "FAILED: Decoded data does not match original."); } } } diff --git a/hibc-lic-barcode/decode-base64-encoded-hibc-lic-barcode-image-string-using-memory-stream-without-writing-to-disk.cs b/hibc-lic-barcode/decode-base64-encoded-hibc-lic-barcode-image-string-using-memory-stream-without-writing-to-disk.cs index 98ef60b..25a3207 100644 --- a/hibc-lic-barcode/decode-base64-encoded-hibc-lic-barcode-image-string-using-memory-stream-without-writing-to-disk.cs +++ b/hibc-lic-barcode/decode-base64-encoded-hibc-lic-barcode-image-string-using-memory-stream-without-writing-to-disk.cs @@ -1,13 +1,13 @@ -// Title: Decode HIBC LIC barcode from Base64 string using memory stream -// Description: Demonstrates how to convert a Base64‑encoded image of a HIBC LIC barcode into a byte array, read it from a MemoryStream, and decode the barcode without writing any files to disk. -// Category-Description: This example belongs to the Aspose.BarCode barcode recognition category, focusing on reading and parsing complex HIBC LIC symbology. It showcases the BarCodeReader with DecodeType.AllSupportedTypes and the ComplexCodetextReader for extracting primary, secondary, and combined data. Developers working with healthcare or logistics barcodes can use these APIs to integrate barcode decoding directly from in‑memory image data. +// Title: Decode a Base64‑encoded HIBC LIC barcode from a memory stream +// Description: Demonstrates how to convert a Base64 string containing a HIBC LIC barcode image into a byte array, load it into a MemoryStream, and decode it using Aspose.BarCode without writing any files to disk. +// Category-Description: This example belongs to the Aspose.BarCode barcode recognition category, focusing on in‑memory image processing. It showcases the BarCodeReader class with the DecodeType.HIBCCode128LIC enumeration, a common scenario for applications that receive barcode images via APIs or messaging queues and need to extract data instantly. Developers often use this pattern to avoid I/O overhead when handling barcode images in web services or background jobs. // Prompt: Decode a base64‑encoded HIBC LIC barcode image string using a memory stream without writing to disk. -// Tags: hibc, lic, barcode, decoding, memorystream, base64, aspose.barcode, c#, .net +// Tags: barcode, hibc, lic, decode, base64, memory stream, aspose.barcode, barcodereader using System; using System.IO; +using Aspose.BarCode; using Aspose.BarCode.BarCodeRecognition; -using Aspose.BarCode.ComplexBarcode; /// /// Example program that decodes a HIBC LIC barcode from a Base64‑encoded image using an in‑memory stream. @@ -15,70 +15,56 @@ class Program { /// - /// Entry point. Converts the Base64 string to a byte array, reads the barcode, and prints parsed HIBC LIC data. + /// Entry point of the example. Converts a Base64 string to a byte array, creates a MemoryStream, + /// and reads the barcode using Aspose.BarCode's BarCodeReader. /// static void Main() { - // Base64‑encoded PNG image containing a HIBC LIC barcode. - // Replace this string with actual Base64‑encoded image data of a HIBC LIC barcode. - string base64Image = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+XK6UAAAAASUVORK5CYII="; + // Base64‑encoded image of a HIBC LIC barcode. + // Replace the placeholder with an actual Base64 string when available. + string base64Image = "iVBORw0KGgoAAAANSUhEUgAA..."; - // Decode the Base64 string into a byte array. - byte[] imageBytes = Convert.FromBase64String(base64Image); + // Validate that the Base64 string is not empty or whitespace. + if (string.IsNullOrWhiteSpace(base64Image)) + { + Console.WriteLine("No base64 image data provided."); + return; + } - // Create a memory stream from the byte array so no file I/O is required. - using (var memoryStream = new MemoryStream(imageBytes)) - // Initialise the barcode reader to recognise all supported types. - using (var reader = new BarCodeReader(memoryStream, DecodeType.AllSupportedTypes)) + byte[] imageBytes; + try { - // Read all barcodes found in the image. - var results = reader.ReadBarCodes(); + // Convert the Base64 string to a byte array. + imageBytes = Convert.FromBase64String(base64Image); + } + catch (FormatException) + { + // Handle invalid Base64 format. + Console.WriteLine("Invalid base64 string."); + return; + } - // Process each recognised barcode. - foreach (var result in results) + // Load the image bytes into a memory stream to avoid disk I/O. + using (var memoryStream = new MemoryStream(imageBytes)) + { + // Initialize the barcode reader for HIBC Code128 LIC symbology. + using (var reader = new BarCodeReader(memoryStream, DecodeType.HIBCCode128LIC)) { - // Attempt to parse the codetext as HIBC LIC data. - var hibc = ComplexCodetextReader.TryDecodeHIBCLIC(result.CodeText); - if (hibc == null) + // Perform the barcode detection. + var results = reader.ReadBarCodes(); + + // Check if any barcodes were found. + if (results.Length == 0) { - Console.WriteLine("Unable to parse HIBC LIC codetext."); - continue; + Console.WriteLine("No barcode detected."); } - - // Determine which HIBC LIC data structure was returned and output its fields. - switch (hibc) + else { - case HIBCLICPrimaryDataCodetext primary: - Console.WriteLine("Primary Data:"); - Console.WriteLine($"Product or Catalog Number: {primary.Data.ProductOrCatalogNumber}"); - Console.WriteLine($"Labeler Identification Code: {primary.Data.LabelerIdentificationCode}"); - Console.WriteLine($"Unit of Measure ID: {primary.Data.UnitOfMeasureID}"); - break; - - case HIBCLICSecondaryAndAdditionalDataCodetext secondary: - Console.WriteLine("Secondary and Additional Data:"); - Console.WriteLine($"Lot Number: {secondary.Data.LotNumber}"); - Console.WriteLine($"Serial Number: {secondary.Data.SerialNumber}"); - Console.WriteLine($"Quantity: {secondary.Data.Quantity}"); - Console.WriteLine($"Expiry Date: {secondary.Data.ExpiryDate}"); - Console.WriteLine($"Expiry Date Format: {secondary.Data.ExpiryDateFormat}"); - Console.WriteLine($"Date of Manufacture: {secondary.Data.DateOfManufacture}"); - break; - - case HIBCLICCombinedCodetext combined: - Console.WriteLine("Combined Data:"); - Console.WriteLine($"Product or Catalog Number: {combined.PrimaryData.ProductOrCatalogNumber}"); - Console.WriteLine($"Labeler Identification Code: {combined.PrimaryData.LabelerIdentificationCode}"); - Console.WriteLine($"Unit of Measure ID: {combined.PrimaryData.UnitOfMeasureID}"); - Console.WriteLine($"Lot Number: {combined.SecondaryAndAdditionalData.LotNumber}"); - Console.WriteLine($"Serial Number: {combined.SecondaryAndAdditionalData.SerialNumber}"); - Console.WriteLine($"Quantity: {combined.SecondaryAndAdditionalData.Quantity}"); - Console.WriteLine($"Expiry Date: {combined.SecondaryAndAdditionalData.ExpiryDate}"); - break; - - default: - Console.WriteLine("Decoded HIBC LIC type not recognized."); - break; + // Output each decoded barcode's text. + foreach (var result in results) + { + Console.WriteLine("Decoded CodeText: " + result.CodeText); + } } } } diff --git a/hibc-lic-barcode/dispose-of-barcodereader-and-complexbarcodegenerator-objects-in-finally-block-to-ensure-resource-cleanup.cs b/hibc-lic-barcode/dispose-of-barcodereader-and-complexbarcodegenerator-objects-in-finally-block-to-ensure-resource-cleanup.cs index a888c71..443a24a 100644 --- a/hibc-lic-barcode/dispose-of-barcodereader-and-complexbarcodegenerator-objects-in-finally-block-to-ensure-resource-cleanup.cs +++ b/hibc-lic-barcode/dispose-of-barcodereader-and-complexbarcodegenerator-objects-in-finally-block-to-ensure-resource-cleanup.cs @@ -1,73 +1,68 @@ -// Title: Generate and read a Swiss QR Code using Aspose.BarCode -// Description: Demonstrates creating a Swiss QR bill barcode, saving it as PNG, and reading it back. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation and recognition category. It showcases the use of ComplexBarcodeGenerator for creating Swiss QR codes and BarCodeReader for decoding QR symbols. Developers often need to generate payment QR codes and validate them programmatically, making this pattern common in financial and invoicing applications. +// Title: Generate and read a Mailmark complex barcode using Aspose.BarCode +// Description: Demonstrates creating a Mailmark complex barcode, saving it to a PNG image in a memory stream, and reading it back with BarCodeReader. +// Category-Description: This example belongs to the Aspose.BarCode generation and recognition category, focusing on complex barcode types such as Mailmark. It showcases the use of ComplexBarcodeGenerator for barcode creation and BarCodeReader for decoding, common tasks for developers integrating barcode workflows into applications that require high‑density data encoding and verification. // Prompt: Dispose of BarCodeReader and ComplexBarcodeGenerator objects in a finally block to ensure resource cleanup. -// Tags: swiss qr, barcode generation, barcode reading, qr, aspnet, aspose.barcode, complexbarcodegenerator, barcodereader +// Tags: mailmark, complex barcode, generation, recognition, png, aspose.barcode using System; +using System.IO; using Aspose.BarCode.Generation; using Aspose.BarCode.BarCodeRecognition; using Aspose.BarCode.ComplexBarcode; /// -/// Demonstrates generating a Swiss QR bill barcode, saving it, and reading it back using Aspose.BarCode. +/// Example program that generates a Mailmark complex barcode, saves it to a memory stream, +/// and then reads the barcode back to display its type and text. /// class Program { /// - /// Entry point of the example. Generates a Swiss QR code, saves it as PNG, then reads and prints its content. + /// Entry point of the example. Executes the generation and reading of a Mailmark barcode. /// static void Main() { - // Output file path for the generated barcode image - const string outputPath = "sample.png"; + // Prepare a simple Mailmark codetext (valid sample) + var mailmark = new MailmarkCodetext + { + Format = 4, // 4-state Mailmark + VersionID = 1, + Class = "0", + SupplychainID = 384224, + ItemID = 16563762, + DestinationPostCodePlusDPS = "EF61AH8T " // trailing space required + }; - // Declare variables for generator and reader; will be instantiated later - ComplexBarcodeGenerator complexGenerator = null; BarCodeReader reader = null; + ComplexBarcodeGenerator generator = null; + MemoryStream barcodeStream = null; try { - // ------------------------------------------------------------ - // Prepare Swiss QR codetext with required fields - // ------------------------------------------------------------ - var swissQr = new SwissQRCodetext(); - swissQr.Bill.Creditor.Name = "John Doe"; - swissQr.Bill.Creditor.CountryCode = "CH"; - swissQr.Bill.Account = "CH9300762011623852957"; - swissQr.Bill.Amount = 199.95m; - swissQr.Bill.Version = SwissQRBill.QrBillStandardVersion.V2_0; - - // ------------------------------------------------------------ - // Generate and save the complex barcode image - // ------------------------------------------------------------ - complexGenerator = new ComplexBarcodeGenerator(swissQr); - complexGenerator.Save(outputPath, BarCodeImageFormat.Png); + // Generate the complex barcode and save it to a memory stream as PNG + generator = new ComplexBarcodeGenerator(mailmark); + barcodeStream = new MemoryStream(); + generator.Save(barcodeStream, BarCodeImageFormat.Png); + barcodeStream.Position = 0; // Reset stream position for reading - // ------------------------------------------------------------ - // Read the generated barcode image and output its content - // ------------------------------------------------------------ - reader = new BarCodeReader(outputPath, DecodeType.QR); - var results = reader.ReadBarCodes(); - foreach (var result in results) + // Read the barcode from the generated image + reader = new BarCodeReader(barcodeStream, DecodeType.Mailmark); + foreach (var result in reader.ReadBarCodes()) { - Console.WriteLine($"Detected CodeText: {result.CodeText}"); + Console.WriteLine($"Detected type: {result.CodeTypeName}"); + Console.WriteLine($"Code text: {result.CodeText}"); } } finally { - // ------------------------------------------------------------ - // Ensure proper disposal of resources regardless of success/failure - // ------------------------------------------------------------ + // Ensure resources are released even if an exception occurs if (reader != null) - { reader.Dispose(); - } - if (complexGenerator != null) - { - complexGenerator.Dispose(); - } + if (generator != null) + generator.Dispose(); + + if (barcodeStream != null) + barcodeStream.Dispose(); } } } \ No newline at end of file diff --git a/hibc-lic-barcode/embed-generated-hibc-lic-barcode-into-existing-word-document-using-asposewords-for-net.cs b/hibc-lic-barcode/embed-generated-hibc-lic-barcode-into-existing-word-document-using-asposewords-for-net.cs index 809a2a8..ed7ba6c 100644 --- a/hibc-lic-barcode/embed-generated-hibc-lic-barcode-into-existing-word-document-using-asposewords-for-net.cs +++ b/hibc-lic-barcode/embed-generated-hibc-lic-barcode-into-existing-word-document-using-asposewords-for-net.cs @@ -1,81 +1,65 @@ -// Title: Embed HIBC LIC barcode into a Word document -// Description: Demonstrates generating a HIBC LIC barcode with secondary data and embedding it into an existing or new Word document using Aspose.Words. -// Category-Description: This example belongs to the Aspose.BarCode and Aspose.Words integration category, showing how to create complex barcodes (HIBC LIC) with the ComplexBarcodeGenerator and insert the resulting image into a Word file via DocumentBuilder. Developers often need to automate document generation with embedded barcodes for labeling, tracking, and compliance purposes. +// Title: Embed HIBC LIC Barcode into a Word Document using Aspose.Words +// Description: Demonstrates generating a HIBC LIC barcode with Aspose.BarCode and inserting it into an existing Word document via Aspose.Words. +// Category-Description: This example belongs to the Aspose.BarCode and Aspose.Words integration category, showcasing how to create complex barcodes (HIBC LIC) using ComplexBarcodeGenerator and embed the resulting image into a Word file with DocumentBuilder. Typical scenarios include adding product identification barcodes to reports, invoices, or label templates. Developers often need to combine barcode generation with document automation, leveraging classes such as HIBCLICPrimaryDataCodetext, ComplexBarcodeGenerator, Document, and DocumentBuilder. // Prompt: Embed a generated HIBC LIC barcode into an existing Word document using Aspose.Words for .NET. -// Tags: hibc lic barcode generation, image insertion, aspnet, aspose.words, aspose.barcode, document automation +// Tags: hibc, lic, barcode, generation, embedding, word, aspose.barcode, aspose.words, png, csharp using System; using System.IO; -using Aspose.Words; -using Aspose.Words.Drawing; -using Aspose.BarCode.ComplexBarcode; +using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.Drawing; -using Aspose.Drawing.Imaging; +using Aspose.BarCode.ComplexBarcode; +using Aspose.Words; /// -/// Demonstrates embedding a generated HIBC LIC barcode into a Word document using Aspose.Words. +/// Sample program that creates a HIBC LIC barcode and embeds it into a Word document. /// class Program { /// - /// Entry point. Generates a HIBC LIC barcode with secondary data, creates or loads a Word document, - /// inserts the barcode image, and saves the file. + /// Entry point of the application. Generates a barcode, inserts it into a Word file, and saves the result. /// static void Main() { - // Define the path to the target Word document. - const string wordFilePath = "SampleDocument.docx"; + // Define file paths for the source and destination Word documents + string inputDocPath = "input.docx"; + string outputDocPath = "output.docx"; + + // If the input document does not exist, create a minimal Word file with placeholder text + if (!File.Exists(inputDocPath)) + { + var newDoc = new Document(); + var newBuilder = new DocumentBuilder(newDoc); + newBuilder.Writeln("Sample document with embedded HIBC LIC barcode:"); + newDoc.Save(inputDocPath); + } - // Prepare HIBC LIC secondary-data-only codetext. - var secondaryCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext + // Configure the primary data for the HIBC LIC barcode + var hibcCodetext = new HIBCLICPrimaryDataCodetext { BarcodeType = EncodeTypes.HIBCCode128LIC, - LinkCharacter = '+', - Data = new SecondaryAndAdditionalData + Data = new PrimaryData { - LotNumber = "LOT123", - SerialNumber = "SN456", - ExpiryDate = DateTime.Today.AddMonths(6), - ExpiryDateFormat = HIBCLICDateFormat.MMDDYY, - Quantity = 10, - DateOfManufacture = DateTime.Today.AddMonths(-1) + ProductOrCatalogNumber = "12345", + LabelerIdentificationCode = "A999", + UnitOfMeasureID = 1 } }; - // Generate the barcode image and store it in a memory stream. - using (var generator = new ComplexBarcodeGenerator(secondaryCodetext)) - using (Bitmap bitmap = generator.GenerateBarCodeImage()) - using (var imageStream = new MemoryStream()) + // Generate the barcode image and store it in a memory stream + using (var generator = new ComplexBarcodeGenerator(hibcCodetext)) + using (var barcodeStream = new MemoryStream()) { - // Save the bitmap as PNG into the stream. - bitmap.Save(imageStream, ImageFormat.Png); - imageStream.Position = 0; // Reset stream position for reading. + generator.Save(barcodeStream, BarCodeImageFormat.Png); + barcodeStream.Position = 0; // Reset stream position for reading - // Load the existing Word document or create a new one if it does not exist. - Document doc; - if (File.Exists(wordFilePath)) - { - doc = new Document(wordFilePath); - } - else - { - doc = new Document(); - // Add an initial paragraph so the document is not empty. - var builderInit = new DocumentBuilder(doc); - builderInit.Writeln("Document created by Aspose.Words."); - } - - // Insert the barcode image at the end of the document. + // Load the existing Word document, insert the barcode image, and save the updated file + var doc = new Document(inputDocPath); var builder = new DocumentBuilder(doc); - builder.MoveToDocumentEnd(); - builder.InsertParagraph(); - builder.InsertImage(imageStream); - - // Save the modified document back to the same file. - doc.Save(wordFilePath); + builder.InsertImage(barcodeStream); + doc.Save(outputDocPath); } - Console.WriteLine("HIBC LIC barcode embedded into Word document successfully."); + Console.WriteLine($"Barcode embedded successfully. Output saved to '{outputDocPath}'."); } } \ No newline at end of file diff --git a/hibc-lic-barcode/encode-combined-primary-and-secondary-fields-using-hibcliccombinedcodetext-and-output-qr-code-file.cs b/hibc-lic-barcode/encode-combined-primary-and-secondary-fields-using-hibcliccombinedcodetext-and-output-qr-code-file.cs index 530c1a9..73907f0 100644 --- a/hibc-lic-barcode/encode-combined-primary-and-secondary-fields-using-hibcliccombinedcodetext-and-output-qr-code-file.cs +++ b/hibc-lic-barcode/encode-combined-primary-and-secondary-fields-using-hibcliccombinedcodetext-and-output-qr-code-file.cs @@ -1,58 +1,64 @@ -// Title: Encode HIBC LIC Combined QR Code -// Description: Demonstrates encoding primary and secondary fields into a HIBC QR code using Aspose.BarCode and saving it as an image. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It showcases the use of HIBCLICCombinedCodetext, PrimaryData, and SecondaryAndAdditionalData classes to create a HIBC QR (LIC) barcode. Developers often need to combine multiple data fields for healthcare and logistics labeling, and this snippet illustrates the typical workflow for generating such barcodes with customizable error correction levels. +// Title: Encode HIBC QR Code with Combined Primary and Secondary Fields +// Description: Demonstrates how to create a HIBC QR (LIC) barcode by combining primary and secondary data fields and saving it as a PNG image. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category, showcasing the use of HIBCLICCombinedCodetext, PrimaryData, and SecondaryAndAdditionalData classes. Developers often need to generate HIBC LIC QR codes for product labeling, requiring both primary product information and additional lot or date details. The snippet illustrates typical steps: configuring data, setting visual parameters, and exporting the barcode image. // Prompt: Encode combined primary and secondary fields using HIBCLICCombinedCodetext and output a QR code file. -// Tags: hibc, qr, combined, barcode, generation, aspnet, aspose.barcode +// Tags: qr code, hibc, combined codetext, generation, png, aspose.barcode using System; -using Aspose.BarCode.ComplexBarcode; +using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.BarCode; // for QRErrorLevel enum +using Aspose.BarCode.ComplexBarcode; +using Aspose.Drawing; /// -/// Example program that creates a HIBC QR (LIC) barcode with combined primary and secondary data fields -/// and saves the resulting image to a PNG file. +/// Generates a HIBC QR (LIC) barcode that combines primary and secondary data fields, +/// then saves the resulting image as a PNG file. /// class Program { /// - /// Entry point of the example. Builds the combined codetext, configures the generator, - /// and writes the QR code image to disk. + /// Entry point of the example. Builds the combined codetext, configures visual parameters, + /// and writes the barcode image to disk. /// static void Main() { - // Build the combined codetext containing both primary and secondary data for a HIBC QR (LIC) barcode + // Assemble combined primary and secondary data for a HIBC LIC QR code var combinedCodetext = new HIBCLICCombinedCodetext { - BarcodeType = EncodeTypes.HIBCQRLIC, // Specify the HIBC QR LIC symbology + // Specify the QR code symbology for HIBC LIC + BarcodeType = EncodeTypes.HIBCQRLIC, + + // Populate primary product information PrimaryData = new PrimaryData { - ProductOrCatalogNumber = "12345", // Product identifier - LabelerIdentificationCode = "A999", // Labeler code - UnitOfMeasureID = 1 // Unit of measure identifier + ProductOrCatalogNumber = "12345", + LabelerIdentificationCode = "A999", + UnitOfMeasureID = 1 }, + + // Populate secondary and additional information such as dates, lot, and serial numbers SecondaryAndAdditionalData = new SecondaryAndAdditionalData { - ExpiryDate = DateTime.Now.AddMonths(6), // Expiration date (6 months from now) - ExpiryDateFormat = HIBCLICDateFormat.MMDDYY, // Date format for the expiry date - Quantity = 30, // Quantity of items - LotNumber = "LOT123", // Lot number - SerialNumber = "SERIAL123", // Serial number - DateOfManufacture = DateTime.Now.AddMonths(-1) // Manufacture date (1 month ago) + ExpiryDate = DateTime.Now, + ExpiryDateFormat = HIBCLICDateFormat.MMDDYY, + Quantity = 30, + LotNumber = "LOT123", + SerialNumber = "SERIAL123", + DateOfManufacture = DateTime.Now } }; - // Initialize the complex barcode generator with the combined codetext + // Create the barcode generator using the combined codetext using (var generator = new ComplexBarcodeGenerator(combinedCodetext)) { - // Configure a high error correction level to improve scan reliability - generator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelH; + // Optional: customize barcode and background colors + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Save the generated QR code as a PNG image file - generator.Save("hibc_combined_qr.png"); + // Save the generated QR code as a PNG file + generator.Save("hibc_qr.png"); } - // Inform the user that the barcode has been generated - Console.WriteLine("HIBC LIC combined QR code generated: hibc_combined_qr.png"); + Console.WriteLine("HIBC QR code generated: hibc_qr.png"); } } \ No newline at end of file diff --git a/hibc-lic-barcode/generate-code-39-hibc-lic-barcode-with-primary-data-and-save-it-as-png-image.cs b/hibc-lic-barcode/generate-code-39-hibc-lic-barcode-with-primary-data-and-save-it-as-png-image.cs index a6a11e2..84308fc 100644 --- a/hibc-lic-barcode/generate-code-39-hibc-lic-barcode-with-primary-data-and-save-it-as-png-image.cs +++ b/hibc-lic-barcode/generate-code-39-hibc-lic-barcode-with-primary-data-and-save-it-as-png-image.cs @@ -1,47 +1,43 @@ -// Title: Generate Code 39 HIBC LIC barcode with primary data -// Description: Demonstrates creating a HIBC Code 39 LIC barcode using primary data and saving it as a PNG image. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on complex barcode types such as HIBC Code 39 LIC. It showcases the use of ComplexBarcodeGenerator and HIBCLICPrimaryDataCodetext classes to encode product information. Developers often need to generate HIBC-compliant barcodes for healthcare labeling and inventory tracking. -// Prompt: Generate a Code 39 HIBC LIC barcode with primary data and save it as a PNG image. -// Tags: code39, hibc, lic, barcode generation, png, aspose.barcode, complexbarcode +// Title: Generate Code 39 HIBC LIC Barcode and Save as PNG +// Description: Demonstrates creating a HIBC Code 39 LIC barcode with primary data using Aspose.BarCode and saving it as a PNG image. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It shows how to use the ComplexBarcodeGenerator together with HIBCLICPrimaryDataCodetext to encode product information in a HIBC Code 39 LIC symbology. Typical use cases include labeling medical devices or pharmaceutical products where HIBC standards are required. Developers often need to set primary data fields, choose the appropriate EncodeTypes value, and export the result to common image formats such as PNG. +/// Prompt: Generate a Code 39 HIBC LIC barcode with primary data and save it as a PNG image. +// Tags: code39, hibc, lic, barcode, generation, png, aspose.barcode, complexbarcode using System; -using Aspose.BarCode.ComplexBarcode; +using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.Drawing; +using Aspose.BarCode.ComplexBarcode; -namespace BarcodeExample +/// +/// Example program that generates a HIBC Code 39 LIC barcode with primary data and saves it as a PNG image. +/// +class Program { /// - /// Demonstrates generation of a HIBC Code 39 LIC barcode with primary data and saving it as a PNG file. + /// Entry point that creates the barcode and writes it to a file. /// - class Program + static void Main() { - /// - /// Entry point. Creates primary data, generates the barcode, and saves it as PNG. - /// - static void Main() + // Define the primary data for the HIBC Code 39 LIC barcode. + var primaryCodetext = new HIBCLICPrimaryDataCodetext { - // Define the primary data required for a HIBC Code 39 LIC barcode - var primaryCodetext = new HIBCLICPrimaryDataCodetext + BarcodeType = EncodeTypes.HIBCCode39LIC, + Data = new PrimaryData { - BarcodeType = EncodeTypes.HIBCCode39LIC, - Data = new PrimaryData - { - ProductOrCatalogNumber = "12345", // Product or catalog identifier - LabelerIdentificationCode = "A999", // Labeler ID assigned by HIBC - UnitOfMeasureID = 1 // Unit of measure (e.g., each) - } - }; - - // Initialize the complex barcode generator with the primary data - using (var generator = new ComplexBarcodeGenerator(primaryCodetext)) - { - // Save the generated barcode; the file extension determines the PNG format - generator.Save("hibc_primary.png"); + ProductOrCatalogNumber = "12345", + LabelerIdentificationCode = "A999", + UnitOfMeasureID = 1 } + }; - // Inform the user that the barcode image has been created - Console.WriteLine("HIBC Code39 LIC barcode generated: hibc_primary.png"); + // Initialize the ComplexBarcodeGenerator with the primary data codetext. + using (var generator = new ComplexBarcodeGenerator(primaryCodetext)) + { + // Specify the output file path and save the generated barcode as a PNG image. + string outputPath = "HIBC_Code39_LIC.png"; + generator.Save(outputPath, BarCodeImageFormat.Png); + Console.WriteLine($"Barcode saved to {outputPath}"); } } } \ No newline at end of file diff --git a/hibc-lic-barcode/generate-hibc-lic-barcode-with-primary-data-and-embed-it-into-pdf-document.cs b/hibc-lic-barcode/generate-hibc-lic-barcode-with-primary-data-and-embed-it-into-pdf-document.cs index 89657dc..b6a19d8 100644 --- a/hibc-lic-barcode/generate-hibc-lic-barcode-with-primary-data-and-embed-it-into-pdf-document.cs +++ b/hibc-lic-barcode/generate-hibc-lic-barcode-with-primary-data-and-embed-it-into-pdf-document.cs @@ -1,66 +1,72 @@ -// Title: Generate HIBC LIC barcode and embed in PDF -// Description: Demonstrates creating a HIBC LIC barcode with primary data and inserting it into a PDF document. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on complex barcode creation using the ComplexBarcodeGenerator and HIBCLICPrimaryDataCodetext classes. It shows how to encode product information into a HIBC LIC symbology and embed the resulting image into a PDF via Aspose.Pdf. Developers often need to generate regulatory or healthcare barcodes and combine them with document workflows, making this pattern useful for automated report or label generation. +// Title: Generate HIBC LIC Barcode and Embed into PDF +// Description: Demonstrates creating a HIBC LIC barcode using Aspose.BarCode, converting it to PNG, and embedding the image into a PDF document with Aspose.Pdf. +// Category-Description: This example belongs to the Aspose.BarCode generation and Aspose.Pdf integration category. It shows how to use ComplexBarcodeGenerator, HIBCLICPrimaryDataCodetext, and PrimaryData to produce a HIBC LIC barcode, then embed the resulting PNG image into a PDF using Document, Page, and Image classes. Developers working on product labeling, healthcare packaging, or any scenario requiring HIBC LIC barcodes in PDF reports will find this pattern useful. // Prompt: Generate a HIBC LIC barcode with primary data and embed it into a PDF document. -// Tags: hibc, lic, barcode, generation, pdf, aspose.barcode, aspose.pdf +// Tags: hibc, lic, barcode, generation, pdf, embedding, aspose.barcode, aspose.pdf, complexbarcode, png, image using System; using System.IO; using Aspose.BarCode; -using Aspose.BarCode.ComplexBarcode; using Aspose.BarCode.Generation; -using Aspose.Drawing; -using Aspose.Drawing.Imaging; +using Aspose.BarCode.ComplexBarcode; using Aspose.Pdf; -using PdfImage = Aspose.Pdf.Image; /// -/// Demonstrates generating a HIBC LIC barcode with primary data and embedding it into a PDF file. +/// Example program that creates a HIBC LIC barcode and inserts it into a PDF document. /// class Program { /// - /// Entry point of the example. Creates the barcode, converts it to PNG, and adds it to a PDF. + /// Entry point. Generates the barcode, embeds it into a PDF, and saves the file. /// static void Main() { - // Define the primary data for the HIBC LIC barcode. - var primaryCodetext = new HIBCLICPrimaryDataCodetext + // Prepare primary data for the HIBC LIC barcode + var primaryData = new PrimaryData + { + ProductOrCatalogNumber = "12345", + LabelerIdentificationCode = "A999", + UnitOfMeasureID = 1 + }; + + // Wrap the primary data in a HIBCLICPrimaryDataCodetext object and specify the barcode type + var hibcCodetext = new HIBCLICPrimaryDataCodetext { BarcodeType = EncodeTypes.HIBCCode128LIC, - Data = new PrimaryData - { - ProductOrCatalogNumber = "12345", - LabelerIdentificationCode = "A999", - UnitOfMeasureID = 1 - } + Data = primaryData }; - // Generate the barcode image using ComplexBarcodeGenerator. - using (var generator = new ComplexBarcodeGenerator(primaryCodetext)) - // Render the barcode to a bitmap. - using (var bitmap = generator.GenerateBarCodeImage()) - // Store the bitmap in a memory stream as PNG. - using (var imageStream = new MemoryStream()) + // Generate the barcode image and store it in a memory stream + using (var generator = new ComplexBarcodeGenerator(hibcCodetext)) { - bitmap.Save(imageStream, ImageFormat.Png); - imageStream.Position = 0; // Reset stream position for reading. + var barcodeStream = new MemoryStream(); + generator.Save(barcodeStream, BarCodeImageFormat.Png); + barcodeStream.Position = 0; // Reset stream position for subsequent reading + + // Create a new PDF document and add a page + var pdfDoc = new Document(); + var page = pdfDoc.Pages.Add(); - // Create a new PDF document. - using (var pdfDoc = new Document()) + // Create an Aspose.Pdf.Image object that reads the barcode from the memory stream + var pdfImage = new Aspose.Pdf.Image { - // Add a page to the PDF. - var page = pdfDoc.Pages.Add(); + ImageStream = barcodeStream, + FixWidth = 200.0, + FixHeight = 100.0, + HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center, + VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center, + Margin = new Aspose.Pdf.MarginInfo { Top = 20 } + }; - // Create an Aspose.Pdf.Image from the barcode stream. - var pdfImage = new PdfImage { ImageStream = imageStream }; + // Add the image to the page's paragraph collection + page.Paragraphs.Add(pdfImage); - // Insert the image into the page's paragraph collection. - page.Paragraphs.Add(pdfImage); + // Save the PDF document to disk + const string outputPath = "HIBC_LIC.pdf"; + pdfDoc.Save(outputPath); - // Save the PDF to disk. - pdfDoc.Save("HIBC_LIC.pdf"); - } + // Dispose the memory stream after the PDF has been saved + barcodeStream.Dispose(); } Console.WriteLine("PDF with HIBC LIC barcode created successfully."); diff --git a/hibc-lic-barcode/generate-hibc-lic-barcode-with-secondary-data-only-and-save-it-as-tiff-image-with-lzw-compression.cs b/hibc-lic-barcode/generate-hibc-lic-barcode-with-secondary-data-only-and-save-it-as-tiff-image-with-lzw-compression.cs index b44ddd2..7ecde4b 100644 --- a/hibc-lic-barcode/generate-hibc-lic-barcode-with-secondary-data-only-and-save-it-as-tiff-image-with-lzw-compression.cs +++ b/hibc-lic-barcode/generate-hibc-lic-barcode-with-secondary-data-only-and-save-it-as-tiff-image-with-lzw-compression.cs @@ -1,8 +1,8 @@ // Title: Generate HIBC LIC barcode with secondary data and save as LZW‑compressed TIFF -// Description: Demonstrates creating a HIBC LIC barcode that contains only secondary data (lot and serial numbers) and saving the result as a TIFF image using LZW compression. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on complex barcode types such as HIBC LIC. It showcases the use of ComplexBarcodeGenerator, HIBCLICSecondaryAndAdditionalDataCodetext, and image encoding classes to produce high‑quality TIFF output. Developers needing to embed secondary information in HIBC barcodes for healthcare or logistics can follow this pattern. +// Description: Demonstrates creating a HIBC LIC barcode that contains only secondary and additional data, then saving the image as a TIFF file using LZW compression. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It shows how to use ComplexBarcodeGenerator with HIBCLICSecondaryAndAdditionalDataCodetext to encode HIBC LIC symbology, a common requirement in healthcare and logistics for encoding lot and serial numbers. Developers often need to generate such barcodes and export them to lossless image formats like TIFF with specific compression settings. // Prompt: Generate a HIBC LIC barcode with secondary data only and save it as a TIFF image with LZW compression. -// Tags: hibc, lic, barcode, generation, tiff, lzw, aspose.barcode, complexbarcode +// Tags: hibc, lic, secondary-data, tiff, lzw, complexbarcode, generation using System; using System.IO; @@ -13,51 +13,65 @@ using Aspose.Drawing.Imaging; /// -/// Program demonstrating generation of a HIBC LIC barcode with secondary data only and saving it as an LZW‑compressed TIFF image. +/// Example program that creates a HIBC LIC barcode containing only secondary data +/// and saves it as a TIFF image using LZW compression. /// class Program { /// - /// Entry point. Creates the barcode, encodes it, and writes the TIFF file. + /// Entry point of the example. Generates the barcode and writes the output file. /// static void Main() { - // Prepare secondary data for the HIBC LIC barcode - var secondaryCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext + // Prepare secondary data (lot number and serial number) for the HIBC LIC barcode + var secondaryData = new SecondaryAndAdditionalData { - BarcodeType = EncodeTypes.HIBCCode128LIC, - LinkCharacter = '+', - Data = new SecondaryAndAdditionalData - { - LotNumber = "LOT123", - SerialNumber = "SN456" - } + LotNumber = "LOT123", + SerialNumber = "SN456" }; - // Define the output file path - string outputPath = "hibc_secondary.tiff"; - - // Generate the barcode image and save it as an LZW‑compressed TIFF - using (var generator = new ComplexBarcodeGenerator(secondaryCodetext)) - using (Image image = generator.GenerateBarCodeImage()) - using (var bitmap = new Bitmap(image)) + // Build the codetext object that represents HIBC LIC secondary‑and‑additional‑data + var hibcCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext { - // Retrieve the TIFF codec information - var tiffCodec = ImageCodecInfo.GetImageEncoders() - .First(c => c.FormatID == ImageFormat.Tiff.Guid); + BarcodeType = EncodeTypes.HIBCCode128LIC, // HIBC LIC Code128 symbology + LinkCharacter = '+', // Required link character for HIBC + Data = secondaryData + }; - // Set encoder parameters to use LZW compression - using (var encoderParams = new EncoderParameters(1)) + // Generate the barcode image using ComplexBarcodeGenerator + using (var generator = new ComplexBarcodeGenerator(hibcCodetext)) + { + using (Bitmap bitmap = generator.GenerateBarCodeImage()) { - encoderParams.Param[0] = new EncoderParameter( - Encoder.Compression, (long)EncoderValue.CompressionLZW); + // Locate the TIFF encoder from the installed image codecs + var tiffEncoder = ImageCodecInfo.GetImageEncoders() + .FirstOrDefault(enc => enc.FormatID == ImageFormat.Tiff.Guid); + if (tiffEncoder == null) + { + Console.WriteLine("TIFF encoder not found."); + return; + } + + // Configure encoder parameters to use LZW compression + using (var encoderParams = new EncoderParameters(1)) + { + encoderParams.Param[0] = new EncoderParameter( + Encoder.Compression, + (long)EncoderValue.CompressionLZW); + + // Save the bitmap to a memory stream with the specified encoder settings + using (var ms = new MemoryStream()) + { + bitmap.Save(ms, tiffEncoder, encoderParams); + ms.Position = 0; - // Save the bitmap to the specified path with the chosen codec and parameters - bitmap.Save(outputPath, tiffCodec, encoderParams); + // Write the resulting TIFF file to disk + File.WriteAllBytes("hibc_lic_secondary.tif", ms.ToArray()); + } + } } } - // Output the full path of the saved barcode image - Console.WriteLine($"Barcode saved to {Path.GetFullPath(outputPath)}"); + Console.WriteLine("HIBC LIC barcode with secondary data saved as TIFF (LZW compression)."); } } \ No newline at end of file diff --git a/hibc-lic-barcode/generate-hibc-lic-barcodes-with-custom-foreground-color-blue-and-background-color-light-gray-for-branding.cs b/hibc-lic-barcode/generate-hibc-lic-barcodes-with-custom-foreground-color-blue-and-background-color-light-gray-for-branding.cs index 0446ee6..63e5846 100644 --- a/hibc-lic-barcode/generate-hibc-lic-barcodes-with-custom-foreground-color-blue-and-background-color-light-gray-for-branding.cs +++ b/hibc-lic-barcode/generate-hibc-lic-barcodes-with-custom-foreground-color-blue-and-background-color-light-gray-for-branding.cs @@ -1,56 +1,101 @@ -// Title: Generate HIBC LIC barcode with custom colors -// Description: Demonstrates creating a HIBC LIC barcode using Aspose.BarCode, applying a blue foreground and light‑gray background for branding purposes. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category, illustrating how to work with HIBC LIC symbology via the ComplexBarcodeGenerator and related data classes. Developers commonly use these APIs to embed product information, lot numbers, and serial numbers in healthcare labeling, customizing appearance to match brand guidelines. -// Prompt: Generate HIBC LIC barcodes with custom foreground color (blue) and background color (light gray) for branding. -// Tags: hibc, lic, barcode, color, customization, png, aspnet, aspnetcore, aspose.barcode, complexbarcode, generation +// Title: Generate HIBC LIC Barcodes with Custom Colors +// Description: Demonstrates creating HIBC Code 128 LIC barcodes with a blue foreground and light‑gray background for branding purposes. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It showcases the use of HIBCLICCombinedCodetext and HIBCLICSecondaryAndAdditionalDataCodetext classes to encode primary, secondary, and additional data for HIBC LIC symbology. Typical use cases include product labeling, inventory tracking, and brand‑consistent barcode rendering. Developers often need to customize colors, output formats, and combine multiple data fields, which this snippet illustrates. +/// Prompt: Generate HIBC LIC barcodes with custom foreground color (blue) and background color (light gray) for branding. +/// Tags: hibc, lic, barcode, color, branding, png, aspose.barcode, complexbarcode using System; using System.IO; -using Aspose.BarCode.ComplexBarcode; +using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.BarCode.ComplexBarcode; using Aspose.Drawing; -using Aspose.Drawing.Imaging; /// -/// Demonstrates generating a HIBC LIC barcode with custom foreground and background colors using Aspose.BarCode. +/// Example program that creates HIBC LIC barcodes with custom foreground and background colors. /// class Program { /// - /// Entry point. Creates secondary data, builds complex codetext, generates the barcode image, and saves it as PNG. + /// Entry point. Generates a combined HIBC LIC barcode and a secondary‑only HIBC LIC barcode, + /// applies branding colors, and saves them as PNG files. /// static void Main() { - // Define secondary data for the HIBC LIC barcode (lot and serial numbers) - var secondaryData = new SecondaryAndAdditionalData + // -------------------------------------------------------------------- + // Prepare output directory + // -------------------------------------------------------------------- + string outputDir = Path.Combine(Directory.GetCurrentDirectory(), "Output"); + if (!Directory.Exists(outputDir)) { - LotNumber = "LOT123", - SerialNumber = "SN456" - }; + Directory.CreateDirectory(outputDir); + } - // Create the complex codetext object that includes barcode type, link character, and secondary data - var complexCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext + // -------------------------------------------------------------------- + // Example 1: Combined HIBC LIC (primary + secondary data) + // -------------------------------------------------------------------- + var combinedCodetext = new HIBCLICCombinedCodetext { - BarcodeType = EncodeTypes.HIBCCode128LIC, // Use Code128 LIC symbology - LinkCharacter = '+', // Required link character for HIBC LIC - Data = secondaryData + BarcodeType = EncodeTypes.HIBCCode128LIC, + PrimaryData = new PrimaryData + { + ProductOrCatalogNumber = "12345", + LabelerIdentificationCode = "A999", + UnitOfMeasureID = 1 + }, + SecondaryAndAdditionalData = new SecondaryAndAdditionalData + { + LotNumber = "LOT123", + SerialNumber = "SERIAL123", + Quantity = 30, + ExpiryDate = DateTime.Now.AddMonths(6), + ExpiryDateFormat = HIBCLICDateFormat.MMDDYY, + DateOfManufacture = DateTime.Now.AddMonths(-2) + } }; - // Generate the barcode image with custom colors using ComplexBarcodeGenerator - using (var generator = new ComplexBarcodeGenerator(complexCodetext)) + string combinedPath = Path.Combine(outputDir, "HIBC_LIC_Combined.png"); + using (var generator = new ComplexBarcodeGenerator(combinedCodetext)) { - // Set foreground (bars) color to blue for branding - generator.Parameters.Barcode.BarColor = Color.Blue; + // Apply branding colors: blue bars on light gray background + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Blue; + generator.Parameters.BackColor = Aspose.Drawing.Color.LightGray; - // Set background color to light gray for contrast - generator.Parameters.BackColor = Color.LightGray; + // Save the barcode image to file + generator.Save(combinedPath); + } - // Define output file path and save the barcode as PNG - string outputPath = "hibc_lic_custom.png"; - generator.Save(outputPath, BarCodeImageFormat.Png); + Console.WriteLine($"Combined HIBC LIC barcode saved to: {combinedPath}"); - // Inform the user where the file was saved - Console.WriteLine($"HIBC LIC barcode saved to: {Path.GetFullPath(outputPath)}"); + // -------------------------------------------------------------------- + // Example 2: Secondary‑only HIBC LIC (requires LinkCharacter) + // -------------------------------------------------------------------- + var secondaryCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext + { + BarcodeType = EncodeTypes.HIBCCode128LIC, + LinkCharacter = '+', // mandatory for secondary‑only codetext + Data = new SecondaryAndAdditionalData + { + LotNumber = "LOT456", + SerialNumber = "SERIAL456", + Quantity = 15, + ExpiryDate = DateTime.Now.AddMonths(12), + ExpiryDateFormat = HIBCLICDateFormat.MMDDYY, + DateOfManufacture = DateTime.Now.AddMonths(-1) + } + }; + + string secondaryPath = Path.Combine(outputDir, "HIBC_LIC_Secondary.png"); + using (var generator = new ComplexBarcodeGenerator(secondaryCodetext)) + { + // Apply the same branding colors + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Blue; + generator.Parameters.BackColor = Aspose.Drawing.Color.LightGray; + + // Save the barcode image to file + generator.Save(secondaryPath); } + + Console.WriteLine($"Secondary‑only HIBC LIC barcode saved to: {secondaryPath}"); } } \ No newline at end of file diff --git a/hibc-lic-barcode/handle-decoding-failures-by-checking-barcodereaderiscodetextvalid-and-recording-error-details-to-log-file.cs b/hibc-lic-barcode/handle-decoding-failures-by-checking-barcodereaderiscodetextvalid-and-recording-error-details-to-log-file.cs index 67069ae..eeab0b7 100644 --- a/hibc-lic-barcode/handle-decoding-failures-by-checking-barcodereaderiscodetextvalid-and-recording-error-details-to-log-file.cs +++ b/hibc-lic-barcode/handle-decoding-failures-by-checking-barcodereaderiscodetextvalid-and-recording-error-details-to-log-file.cs @@ -1,91 +1,93 @@ // Title: Barcode decoding with error handling and logging -// Description: Demonstrates generating a Code128 barcode, decoding it, and handling decoding failures by checking the decoded text validity, then logging error details to a file. -// Category-Description: This example belongs to the Aspose.BarCode barcode recognition category, illustrating how to use BarCodeGenerator, BarCodeReader, DecodeType, and related classes to read barcodes, verify decoded text validity, and log issues. Developers often need to detect unreadable or corrupted barcodes and record diagnostic information for troubleshooting. +// Description: Demonstrates generating a Code128 barcode, reading it, checking for decoding validity, and logging results or errors to a file. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation and recognition category. It shows how to use BarcodeGenerator to create a barcode image and BarCodeReader to decode it, while handling failures by inspecting the decoded result and recording details. Developers often need to validate decoded text, handle missing or unreadable barcodes, and log outcomes for diagnostics. // Prompt: Handle decoding failures by checking BarCodeReader.IsCodeTextValid and recording error details to a log file. -// Tags: barcode, decoding, error handling, logging, code128, aspose.barcode, barcodereader, iscodetextvalid +// Tags: barcode, code128, decoding, error-handling, logging, aspose.barcode, generation, recognition using System; using System.IO; using Aspose.BarCode.Generation; using Aspose.BarCode.BarCodeRecognition; -using Aspose.Drawing; /// -/// Example program that generates a barcode, attempts to decode it, -/// and logs any decoding failures with detailed information. +/// Demonstrates barcode generation, decoding, and error logging using Aspose.BarCode. /// class Program { /// - /// Entry point of the application. Generates a sample barcode, reads it, - /// checks for decoding validity, and records errors to a log file. + /// Generates a barcode image, attempts to decode it, and writes success or error information to a log file. /// static void Main() { // Paths for the generated barcode image and the log file - const string barcodePath = "sample.png"; - const string logPath = "decode_log.txt"; + string imagePath = "barcode.png"; + string logPath = "decode_log.txt"; - // Ensure any previous log is cleared + // Ensure previous log is cleared if (File.Exists(logPath)) { File.Delete(logPath); } - // Generate a sample barcode image using Code128 symbology - using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "Sample123")) + // Step 1: Generate a sample barcode image + using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "123ABC")) { - generator.Save(barcodePath, BarCodeImageFormat.Png); + // Optional: set visual parameters for better readability + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; + + // Save the barcode to a file + generator.Save(imagePath); } - // Prepare the log writer (overwrite existing log) - using (var logWriter = new StreamWriter(logPath, append: false)) + // Step 2: Verify the image file exists before attempting to read + if (!File.Exists(imagePath)) { - // Verify that the barcode image file exists before attempting to read - if (!File.Exists(barcodePath)) - { - logWriter.WriteLine($"Error: Barcode image file '{barcodePath}' not found."); - return; - } + File.AppendAllText(logPath, $"Error: Barcode image not found at '{imagePath}'.{Environment.NewLine}"); + return; + } - // Create a BarCodeReader for all supported types - using (var reader = new BarCodeReader(barcodePath, DecodeType.AllSupportedTypes)) + // Step 3: Read the barcode and handle decoding failures + try + { + using (var reader = new BarCodeReader(imagePath, DecodeType.AllSupportedTypes)) { - // Perform recognition and obtain an array of results var results = reader.ReadBarCodes(); - // If no barcodes were detected, log the failure - if (results == null || results.Length == 0) + // No barcodes detected + if (results.Length == 0) { - logWriter.WriteLine($"Decoding failed: No barcodes detected in '{barcodePath}'."); + File.AppendAllText(logPath, "Error: No barcode detected in the image." + Environment.NewLine); } else { // Process each detected barcode foreach (var result in results) { - // Check if the decoded text is valid (non‑null and non‑empty) - // In practice, BarCodeResult.IsCodeTextValid can be used for this purpose - if (string.IsNullOrEmpty(result.CodeText)) + // BarCodeResult does not expose IsCodeTextValid; treat non‑empty CodeText as valid + bool isValid = !string.IsNullOrEmpty(result.CodeText); + if (isValid) { - // Record details of the failure to the log file - logWriter.WriteLine("Decoding failure:"); - logWriter.WriteLine($" Type: {result.CodeTypeName}"); - logWriter.WriteLine($" Confidence: {result.Confidence}"); - logWriter.WriteLine($" ReadingQuality: {result.ReadingQuality}"); - logWriter.WriteLine($" Region: {result.Region.Rectangle}"); + File.AppendAllText(logPath, + $"Decoded successfully: Type={result.CodeTypeName}, Text={result.CodeText}{Environment.NewLine}"); } else { - // Successful decode – write info to console (optional) - Console.WriteLine($"Decoded [{result.CodeTypeName}]: {result.CodeText}"); + File.AppendAllText(logPath, + $"Decoding failure: Barcode detected but CodeText is empty or null.{Environment.NewLine}"); } } } } } + catch (Exception ex) + { + // Log any unexpected exceptions during reading + File.AppendAllText(logPath, + $"Exception during barcode reading: {ex.GetType().Name} - {ex.Message}{Environment.NewLine}"); + } - // Indicate completion to the user - Console.WriteLine("Processing completed. See decode_log.txt for details."); + // Output log location to console for quick verification + Console.WriteLine($"Decoding process completed. Log written to '{logPath}'."); } } \ No newline at end of file diff --git a/hibc-lic-barcode/implement-asynchronous-barcode-generation-for-hibc-lic-using-taskrun-to-improve-ui-responsiveness.cs b/hibc-lic-barcode/implement-asynchronous-barcode-generation-for-hibc-lic-using-taskrun-to-improve-ui-responsiveness.cs index 521c6d3..ac35823 100644 --- a/hibc-lic-barcode/implement-asynchronous-barcode-generation-for-hibc-lic-using-taskrun-to-improve-ui-responsiveness.cs +++ b/hibc-lic-barcode/implement-asynchronous-barcode-generation-for-hibc-lic-using-taskrun-to-improve-ui-responsiveness.cs @@ -1,82 +1,65 @@ -// Title: Asynchronous HIBC LIC Barcode Generation Example -// Description: Demonstrates generating a HIBC Code 128 LIC barcode with secondary data asynchronously to keep UI responsive. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on complex barcode types such as HIBC LIC. It showcases the use of ComplexBarcodeGenerator, HIBCLICSecondaryAndAdditionalDataCodetext, and related data classes to create barcodes with additional information. Developers often need to generate such barcodes in background threads to avoid blocking UI threads in desktop or web applications. +// Title: Asynchronous HIBC LIC Barcode Generation Example +// Description: Demonstrates generating a HIBC LIC barcode image asynchronously using Aspose.BarCode and saving it as a PNG file. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It showcases the use of ComplexBarcodeGenerator, EncodeTypes, and related classes to create HIBC symbology barcodes, a common requirement in healthcare and logistics for encoding product information. Developers often need to generate such barcodes on background threads to keep UI responsive. // Prompt: Implement asynchronous barcode generation for HIBC LIC using Task.Run to improve UI responsiveness. -// Tags: hibc, lic, barcode, asynchronous, task.run, complexbarcode, generation, png, aspnet, aspnetcore +// Tags: barcode, hibc, lic, asynchronous, task.run, png, aspose.barcode, complexbarcode, generation using System; using System.IO; using System.Threading.Tasks; using Aspose.BarCode.ComplexBarcode; using Aspose.BarCode.Generation; -using Aspose.Drawing; -using Aspose.Drawing.Imaging; /// -/// Demonstrates asynchronous generation of a HIBC Code 128 LIC barcode with secondary and additional data. +/// Provides an example of generating a HIBC LIC barcode asynchronously. /// class Program { /// - /// Entry point. Generates the barcode asynchronously and saves it to the specified path. + /// Entry point. Generates the barcode asynchronously and writes the output path. /// - /// Command‑line arguments; first argument can specify output file path. + /// Command‑line arguments (not used). /// A task representing the asynchronous operation. static async Task Main(string[] args) { - // Determine output file path (use default if not provided) - string outputPath = args.Length > 0 ? args[0] : "hibc_secondary.png"; + // Generate the HIBC LIC barcode asynchronously and wait for completion. + string outputPath = await GenerateHibcLicBarcodeAsync(); - // Ensure the target directory exists - string directory = Path.GetDirectoryName(Path.GetFullPath(outputPath)); - if (!Directory.Exists(directory)) - { - Directory.CreateDirectory(directory); - } - - // Generate the barcode on a background thread - await GenerateHibcLicBarcodeAsync(outputPath); - - // Inform the user where the file was saved - Console.WriteLine($"Barcode saved to: {outputPath}"); + // Inform the user where the barcode image was saved. + Console.WriteLine($"Barcode image saved to: {outputPath}"); } - /// - /// Generates a HIBC LIC barcode with secondary data on a background thread. - /// - /// Full path where the PNG image will be saved. - /// A task that completes when the barcode image has been saved. - private static Task GenerateHibcLicBarcodeAsync(string outputPath) + // Asynchronously creates a HIBC LIC barcode image and saves it to a PNG file. + private static Task GenerateHibcLicBarcodeAsync() { - // Offload the CPU‑intensive barcode generation to a thread‑pool thread return Task.Run(() => { - // Prepare secondary‑and‑additional data codetext - var secondaryCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext + // Prepare the complex codetext for HIBC LIC (secondary data only). + var complexCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext { + // Use HIBC Code128 LIC symbology. BarcodeType = EncodeTypes.HIBCCode128LIC, + // The link character is mandatory; '+' is the default. LinkCharacter = '+', + // Populate secondary data (e.g., lot number). Data = new SecondaryAndAdditionalData { - LotNumber = "LOT123", - SerialNumber = "SN001", - ExpiryDate = DateTime.Today.AddMonths(6), - ExpiryDateFormat = HIBCLICDateFormat.MMDDYY, - Quantity = 10, - DateOfManufacture = DateTime.Today + LotNumber = "LOT123" } }; - // Create the generator with the prepared codetext - using (var generator = new ComplexBarcodeGenerator(secondaryCodetext)) + // Define output file path. + string fileName = "HibcLicBarcode.png"; + string outputPath = Path.Combine(Directory.GetCurrentDirectory(), fileName); + + // Generate and save the barcode image. + using (var generator = new ComplexBarcodeGenerator(complexCodetext)) { - // Generate the barcode image - using (Bitmap bitmap = generator.GenerateBarCodeImage()) - { - // Save the image as PNG to the specified path - bitmap.Save(outputPath, ImageFormat.Png); - } + generator.Save(outputPath, BarCodeImageFormat.Png); } + + // Return the full path of the saved image. + return outputPath; }); } } \ No newline at end of file diff --git a/hibc-lic-barcode/integrate-barcode-generation-into-web-api-endpoint-that-receives-json-payload-and-returns-barcode-image.cs b/hibc-lic-barcode/integrate-barcode-generation-into-web-api-endpoint-that-receives-json-payload-and-returns-barcode-image.cs index f31cbf8..d9d51fa 100644 --- a/hibc-lic-barcode/integrate-barcode-generation-into-web-api-endpoint-that-receives-json-payload-and-returns-barcode-image.cs +++ b/hibc-lic-barcode/integrate-barcode-generation-into-web-api-endpoint-that-receives-json-payload-and-returns-barcode-image.cs @@ -1,90 +1,96 @@ // Title: Barcode generation from JSON payload in a console demo -// Description: Demonstrates how to parse a JSON request, map the symbology to Aspose.BarCode EncodeTypes, generate a barcode image, and output it as Base64. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and BarCodeImageFormat classes. Typical use cases include creating barcodes from client‑provided data in web APIs or services. Developers often need to convert JSON input into barcode images for printing, labeling, or embedding in responses. +// Description: Demonstrates how to deserialize a JSON request, map its properties to Aspose.BarCode settings, and generate a PNG barcode image. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and rendering options. Developers often need to create barcodes dynamically from client data in web APIs or services, and this snippet shows the typical workflow of parsing input, configuring parameters, and producing an image. // Prompt: Integrate barcode generation into a web API endpoint that receives JSON payload and returns the barcode image. -// Tags: barcode generation, json, code128, png, base64, aspose.barcode, encode types +// Tags: barcode, generation, json, deserialization, aspose.barcode, aspnet core, api, png, image using System; using System.IO; using System.Text.Json; using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.Drawing.Imaging; +using Aspose.Drawing; /// -/// Demonstrates barcode generation from a JSON payload. +/// Demonstrates barcode generation based on a JSON request payload. /// class Program { - // Simple model matching the expected JSON payload - private class BarcodeRequest + // Model representing the expected JSON payload + public class BarcodeRequest { - public string symbology { get; set; } - public string codeText { get; set; } + public string Symbology { get; set; } + public string CodeText { get; set; } + public float? XDimension { get; set; } + public float? BarHeight { get; set; } + public string BarColor { get; set; } } /// - /// Entry point that parses a sample JSON request, generates a barcode, saves it, and prints a Base64 representation. + /// Entry point that simulates receiving a JSON payload, creates a barcode, and outputs the image. /// static void Main() { - // NOTE: The original task describes a web API endpoint. - // The snippet runner cannot host an HTTP server, so we demonstrate the core logic - // by using a hard‑coded JSON payload, generating the barcode, and saving it to a file. + // Simulated incoming JSON request + string json = @"{ + ""Symbology"": ""Code128"", + ""CodeText"": ""123ABC"", + ""XDimension"": 2.0, + ""BarHeight"": 50.0, + ""BarColor"": ""Blue"" + }"; - // Sample JSON payload - string jsonPayload = "{\"symbology\":\"Code128\",\"codeText\":\"123ABC\"}"; - - // Parse JSON into the request model - BarcodeRequest request; - try - { - request = JsonSerializer.Deserialize(jsonPayload); - if (request == null || - string.IsNullOrWhiteSpace(request.symbology) || - string.IsNullOrWhiteSpace(request.codeText)) - { - throw new ArgumentException("Invalid JSON payload."); - } - } - catch (Exception ex) + // Deserialize the JSON payload + BarcodeRequest request = JsonSerializer.Deserialize(json); + if (request == null) { - Console.WriteLine($"Failed to parse request: {ex.Message}"); + Console.WriteLine("Invalid request payload."); return; } - // Resolve symbology name to EncodeTypes field via reflection - var field = typeof(EncodeTypes).GetField(request.symbology); + // Resolve the symbology name to a BaseEncodeType using reflection + var field = typeof(EncodeTypes).GetField(request.Symbology); if (field == null) { - Console.WriteLine($"Unknown symbology: {request.symbology}"); + Console.WriteLine($"Unknown symbology: {request.Symbology}"); return; } - BaseEncodeType encodeType = (BaseEncodeType)field.GetValue(null); - // Generate barcode and save as PNG - string outputPath = "barcode.png"; - using (var generator = new BarcodeGenerator(encodeType, request.codeText)) + // Create the barcode generator with the resolved type and provided code text + using (var generator = new BarcodeGenerator(encodeType, request.CodeText ?? string.Empty)) { - // Example of setting a parameter (optional) - generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial"; - generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f; + // Apply optional parameters if they are present + if (request.XDimension.HasValue) + generator.Parameters.Barcode.XDimension.Point = request.XDimension.Value; - // Save directly to file - generator.Save(outputPath, BarCodeImageFormat.Png); - } + if (request.BarHeight.HasValue && request.BarHeight.Value > 0) + generator.Parameters.Barcode.BarHeight.Point = request.BarHeight.Value; - // Optionally, output the image as a Base64 string (simulating an API response) - if (File.Exists(outputPath)) - { - byte[] imageBytes = File.ReadAllBytes(outputPath); - string base64 = Convert.ToBase64String(imageBytes); - Console.WriteLine($"Barcode image (Base64): {base64}"); - } - else - { - Console.WriteLine("Failed to generate barcode image."); + if (!string.IsNullOrEmpty(request.BarColor)) + { + // Map color name to Aspose.Drawing.Color static property (e.g., Color.Blue) + var colorProp = typeof(Color).GetProperty(request.BarColor); + if (colorProp != null) + { + generator.Parameters.Barcode.BarColor = (Color)colorProp.GetValue(null); + } + } + + // Generate the barcode image into a memory stream as PNG + using (var ms = new MemoryStream()) + { + generator.Save(ms, BarCodeImageFormat.Png); + ms.Position = 0; + + // Output the image as a Base64 string (simulating an HTTP response body) + string base64 = Convert.ToBase64String(ms.ToArray()); + Console.WriteLine("Barcode image (Base64 PNG):"); + Console.WriteLine(base64); + + // Also write the image to a file for local verification + File.WriteAllBytes("output.png", ms.ToArray()); + } } } } \ No newline at end of file diff --git a/hibc-lic-barcode/iterate-over-directory-of-barcode-images-decode-each-hibc-lic-and-log-primary-product-ids.cs b/hibc-lic-barcode/iterate-over-directory-of-barcode-images-decode-each-hibc-lic-and-log-primary-product-ids.cs index 5905050..070df4d 100644 --- a/hibc-lic-barcode/iterate-over-directory-of-barcode-images-decode-each-hibc-lic-and-log-primary-product-ids.cs +++ b/hibc-lic-barcode/iterate-over-directory-of-barcode-images-decode-each-hibc-lic-and-log-primary-product-ids.cs @@ -1,110 +1,112 @@ -// Title: Decode HIBC LIC barcodes from image files -// Description: Demonstrates how to iterate through a folder of images, decode HIBC LIC barcodes, and output primary product identifiers. -// Category-Description: This example belongs to the Aspose.BarCode barcode recognition category, focusing on HIBC (Health Industry Bar Code) LIC symbologies. It showcases the BarCodeReader and ComplexCodetextReader classes to extract primary product data, a common requirement for healthcare and pharmaceutical inventory systems. Developers can use this pattern to batch‑process barcode images and integrate product identification into their applications. +// Title: Decode HIBC LIC Barcodes from a Directory and Log Product IDs +// Description: Demonstrates how to generate sample HIBC LIC barcode images, iterate through a folder, decode each barcode, and output the primary product identifier. +// Category-Description: This example belongs to the Aspose.BarCode barcode decoding category, focusing on complex barcode types such as HIBC Code 128 LIC. It showcases the use of ComplexBarcodeGenerator, BarCodeReader, and ComplexCodetextReader to create, read, and parse HIBC LIC barcodes. Developers working with healthcare or logistics labeling often need to extract product or catalog numbers from HIBC barcodes, and this snippet provides a clear pattern for batch processing image files. // Prompt: Iterate over a directory of barcode images, decode each HIBC LIC, and log primary product IDs. -// Tags: hibc, lic, barcode, decode, console, aspose.barcode, barcodereader, complexcodetextreader +// Tags: hibc, lic, barcode, decoding, csharp, aspose.barcode, complexbarcode, batch-processing using System; using System.IO; -using System.Linq; +using Aspose.BarCode; +using Aspose.BarCode.Generation; using Aspose.BarCode.BarCodeRecognition; using Aspose.BarCode.ComplexBarcode; /// -/// Program that scans a directory for image files, decodes any HIBC LIC barcodes, -/// and writes the primary product information to the console. +/// Sample program that generates HIBC LIC barcodes (if none exist), scans a directory for image files, +/// decodes each barcode, and writes the primary product ID to the console. /// class Program { /// - /// Entry point. Accepts an optional folder path argument; defaults to "Barcodes". + /// Entry point. Creates sample barcodes, then reads and decodes all supported image files in the + /// "Barcodes" subfolder, outputting the extracted product identifiers. /// - /// Command‑line arguments; first argument is the folder path. - static void Main(string[] args) + static void Main() { - // Determine the folder containing barcode images (use argument if provided). - string folderPath = args.Length > 0 ? args[0] : "Barcodes"; - - // Verify that the folder exists before proceeding. + // Define the folder that will contain barcode images + string folderPath = Path.Combine(Directory.GetCurrentDirectory(), "Barcodes"); if (!Directory.Exists(folderPath)) { - Console.WriteLine($"Folder not found: {folderPath}"); - return; + Directory.CreateDirectory(folderPath); } - // Retrieve up to 10 image files with supported extensions. - var imageFiles = Directory.GetFiles(folderPath) - .Where(f => f.EndsWith(".png", StringComparison.OrdinalIgnoreCase) || - f.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || - f.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase) || - f.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase) || - f.EndsWith(".tif", StringComparison.OrdinalIgnoreCase) || - f.EndsWith(".tiff", StringComparison.OrdinalIgnoreCase)) - .Take(10) - .ToArray(); + // Seed sample HIBC LIC barcodes if the folder is empty + bool folderEmpty = Directory.GetFiles(folderPath, "*.png").Length == 0 && + Directory.GetFiles(folderPath, "*.jpg").Length == 0 && + Directory.GetFiles(folderPath, "*.bmp").Length == 0; - // If no images were found, inform the user and exit. - if (imageFiles.Length == 0) + if (folderEmpty) { - Console.WriteLine("No image files found in the specified folder."); - return; + var samples = new[] + { + new { Product = "12345", Labeler = "A999", Unit = 1 }, + new { Product = "67890", Labeler = "B123", Unit = 2 }, + new { Product = "54321", Labeler = "C456", Unit = 3 } + }; + + int index = 1; + foreach (var s in samples) + { + // Build primary data codetext for HIBC LIC + var primaryData = new PrimaryData + { + ProductOrCatalogNumber = s.Product, + LabelerIdentificationCode = s.Labeler, + UnitOfMeasureID = s.Unit + }; + + var complexCodetext = new HIBCLICPrimaryDataCodetext + { + BarcodeType = EncodeTypes.HIBCCode128LIC, + Data = primaryData + }; + + // Save the generated barcode image + string fileName = Path.Combine(folderPath, $"HIBC_{index}.png"); + using (var generator = new ComplexBarcodeGenerator(complexCodetext)) + { + generator.Save(fileName, BarCodeImageFormat.Png); + } + + index++; + } } - // Process each image file individually. - foreach (string filePath in imageFiles) + // Process each image file in the folder + string[] patterns = new[] { "*.png", "*.jpg", "*.bmp" }; + foreach (string pattern in patterns) { - // Initialize BarCodeReader to detect all HIBC LIC symbologies. - using (var reader = new BarCodeReader( - filePath, - DecodeType.HIBCCode128LIC, - DecodeType.HIBCAztecLIC, - DecodeType.HIBCDataMatrixLIC, - DecodeType.HIBCQRLIC)) + foreach (string filePath in Directory.GetFiles(folderPath, pattern)) { - // Read all barcodes present in the image. - var results = reader.ReadBarCodes(); - - // If no HIBC LIC barcode is detected, report and continue to next file. - if (results.Length == 0) + if (!File.Exists(filePath)) { - Console.WriteLine($"{Path.GetFileName(filePath)}: No HIBC LIC barcode detected."); + Console.WriteLine($"File not found: {filePath}"); continue; } - // Iterate through each detected barcode result. - foreach (var result in results) + // Read and decode HIBC LIC barcodes from the current image + using (var reader = new BarCodeReader(filePath, DecodeType.HIBCCode128LIC)) { - // Attempt to parse the HIBC LIC codetext using the complex reader. - var hibcCodetext = ComplexCodetextReader.TryDecodeHIBCLIC(result.CodeText); - if (hibcCodetext == null) + bool anyFound = false; + foreach (var result in reader.ReadBarCodes()) { - Console.WriteLine($"{Path.GetFileName(filePath)}: Unable to decode HIBC LIC codetext."); - continue; - } + anyFound = true; - // Handle primary data (primary only or combined with secondary data). - if (hibcCodetext is HIBCLICPrimaryDataCodetext primary) - { - Console.WriteLine($"{Path.GetFileName(filePath)}: ProductOrCatalogNumber={primary.Data.ProductOrCatalogNumber}, " + - $"LabelerIdentificationCode={primary.Data.LabelerIdentificationCode}, " + - $"UnitOfMeasureID={primary.Data.UnitOfMeasureID}"); + // Decode the complex HIBC LIC codetext + var complex = ComplexCodetextReader.TryDecodeHIBCLIC(result.CodeText); + if (complex is HIBCLICPrimaryDataCodetext primary) + { + Console.WriteLine($"File: {Path.GetFileName(filePath)} - Product ID: {primary.Data.ProductOrCatalogNumber}"); + } + else + { + Console.WriteLine($"File: {Path.GetFileName(filePath)} - Unable to extract primary product ID."); + } } - else if (hibcCodetext is HIBCLICCombinedCodetext combined) - { - var pd = combined.PrimaryData; - Console.WriteLine($"{Path.GetFileName(filePath)}: ProductOrCatalogNumber={pd.ProductOrCatalogNumber}, " + - $"LabelerIdentificationCode={pd.LabelerIdentificationCode}, " + - $"UnitOfMeasureID={pd.UnitOfMeasureID}"); - } - else if (hibcCodetext is HIBCLICSecondaryAndAdditionalDataCodetext) - { - // No primary data present; only secondary or additional data. - Console.WriteLine($"{Path.GetFileName(filePath)}: Barcode contains only secondary data."); - } - else + + if (!anyFound) { - // Unexpected codetext type. - Console.WriteLine($"{Path.GetFileName(filePath)}: Unrecognized HIBC LIC codetext type."); + Console.WriteLine($"File: {Path.GetFileName(filePath)} - No barcode detected."); } } } diff --git a/hibc-lic-barcode/read-hibc-lic-barcode-from-file-stream-and-decode-it-using-complexcodetextreader.cs b/hibc-lic-barcode/read-hibc-lic-barcode-from-file-stream-and-decode-it-using-complexcodetextreader.cs index ba4b7a5..0c78706 100644 --- a/hibc-lic-barcode/read-hibc-lic-barcode-from-file-stream-and-decode-it-using-complexcodetextreader.cs +++ b/hibc-lic-barcode/read-hibc-lic-barcode-from-file-stream-and-decode-it-using-complexcodetextreader.cs @@ -1,100 +1,84 @@ // Title: Read and Decode HIBC LIC Barcode Using ComplexCodetextReader -// Description: Demonstrates reading a HIBC LIC barcode from an image file stream and decoding its complex data fields. -// Category-Description: This example belongs to the Aspose.BarCode recognition and complex barcode decoding category. It showcases the BarCodeReader (for image scanning) together with ComplexCodetextReader (for parsing HIBC LIC codetext). Typical use cases include healthcare and pharmaceutical labeling where detailed product, lot, and expiry information must be extracted from HIBC LIC barcodes. Developers often need to read barcode images, identify the symbology, and map the raw codetext to strongly‑typed objects for further processing. +// Description: Demonstrates how to read a HIBC LIC barcode from an image file stream and decode its complex codetext into primary or secondary data fields. +// Category-Description: This example belongs to the Aspose.BarCode barcode reading and complex codetext decoding category. It showcases the use of BarCodeReader to detect HIBC Code128 LIC barcodes and ComplexCodetextReader to parse the structured information contained in the codetext. Developers working with healthcare or logistics barcodes often need to extract product, lot, serial, and expiry details, making this pattern a common requirement in inventory and compliance applications. // Prompt: Read a HIBC LIC barcode from a file stream and decode it using ComplexCodetextReader. -// Tags: hibc, lic, barcode, read, complexcodetextreader, aspnet, aspnetcore, csharp +// Tags: hibc, lic, barcode, reading, decoding, complexcodetextreader, aspose.barcode using System; using System.IO; +using Aspose.BarCode; using Aspose.BarCode.BarCodeRecognition; using Aspose.BarCode.ComplexBarcode; /// -/// Example program that reads a HIBC LIC barcode from an image file, -/// decodes the raw codetext using , -/// and prints the extracted fields to the console. +/// Example program that reads a HIBC LIC barcode from an image file and decodes its complex codetext. /// class Program { /// - /// Entry point of the application. + /// Entry point of the example. Opens the image, reads HIBC LIC barcodes, and prints decoded data. /// static void Main() { - // Path to the image file containing the HIBC LIC barcode. - const string imagePath = "hibc_lic.png"; + // Path to the barcode image file + string imagePath = "hibc_lic.png"; - // Verify that the file exists before attempting to read it. + // Verify that the file exists before attempting to read it if (!File.Exists(imagePath)) { Console.WriteLine($"File not found: {imagePath}"); return; } - // Open the file as a read‑only stream. - using (FileStream fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read)) - // Create a BarCodeReader for the HIBC Code128 LIC symbology. - using (BarCodeReader reader = new BarCodeReader(fileStream, DecodeType.HIBCCode128LIC)) + // Open the image file as a read‑only stream + using (FileStream stream = new FileStream(imagePath, FileMode.Open, FileAccess.Read)) { - // Perform the recognition and obtain all detected barcodes. - var results = reader.ReadBarCodes(); - - // If no barcodes were found, inform the user and exit. - if (results == null || results.Length == 0) + // Initialize a BarCodeReader for HIBC Code128 LIC symbology + using (BarCodeReader reader = new BarCodeReader(stream, DecodeType.HIBCCode128LIC)) { - Console.WriteLine("No barcode detected in the image."); - return; - } + bool anyFound = false; - // Iterate over all detected barcodes. - foreach (var result in results) - { - // Decode the raw codetext into a complex HIBC LIC object. - var complex = ComplexCodetextReader.TryDecodeHIBCLIC(result.CodeText); - - // If decoding fails, report and continue with the next result. - if (complex == null) + // Iterate through all detected barcodes in the image + foreach (BarCodeResult result in reader.ReadBarCodes()) { - Console.WriteLine("Failed to decode complex HIBC LIC codetext."); - continue; - } + anyFound = true; + Console.WriteLine($"Raw CodeText: {result.CodeText}"); - // Determine the concrete type of the decoded object and output its fields. - switch (complex) - { - case HIBCLICPrimaryDataCodetext primary: - Console.WriteLine("=== Primary Data ==="); - Console.WriteLine($"Product or Catalog Number: {primary.Data.ProductOrCatalogNumber}"); - Console.WriteLine($"Labeler Identification Code: {primary.Data.LabelerIdentificationCode}"); - Console.WriteLine($"Unit of Measure ID: {primary.Data.UnitOfMeasureID}"); - break; - - case HIBCLICSecondaryAndAdditionalDataCodetext secondary: - Console.WriteLine("=== Secondary and Additional Data ==="); - Console.WriteLine($"Lot Number: {secondary.Data.LotNumber}"); - Console.WriteLine($"Serial Number: {secondary.Data.SerialNumber}"); - Console.WriteLine($"Expiry Date: {secondary.Data.ExpiryDate}"); - Console.WriteLine($"Expiry Date Format: {secondary.Data.ExpiryDateFormat}"); - Console.WriteLine($"Quantity: {secondary.Data.Quantity}"); - Console.WriteLine($"Date of Manufacture: {secondary.Data.DateOfManufacture}"); - break; + // Attempt to decode the complex HIBC LIC codetext + var complex = ComplexCodetextReader.TryDecodeHIBCLIC(result.CodeText); + if (complex == null) + { + Console.WriteLine("Failed to decode complex HIBC LIC codetext."); + continue; + } - case HIBCLICCombinedCodetext combined: - Console.WriteLine("=== Combined Data ==="); - Console.WriteLine($"Product or Catalog Number: {combined.PrimaryData.ProductOrCatalogNumber}"); - Console.WriteLine($"Labeler Identification Code: {combined.PrimaryData.LabelerIdentificationCode}"); - Console.WriteLine($"Unit of Measure ID: {combined.PrimaryData.UnitOfMeasureID}"); - Console.WriteLine($"Lot Number: {combined.SecondaryAndAdditionalData.LotNumber}"); - Console.WriteLine($"Serial Number: {combined.SecondaryAndAdditionalData.SerialNumber}"); - Console.WriteLine($"Expiry Date: {combined.SecondaryAndAdditionalData.ExpiryDate}"); - Console.WriteLine($"Expiry Date Format: {combined.SecondaryAndAdditionalData.ExpiryDateFormat}"); - Console.WriteLine($"Quantity: {combined.SecondaryAndAdditionalData.Quantity}"); - Console.WriteLine($"Date of Manufacture: {combined.SecondaryAndAdditionalData.DateOfManufacture}"); - break; + // Process the decoded result based on its concrete type + if (complex is HIBCLICPrimaryDataCodetext primary) + { + Console.WriteLine("Decoded as Primary Data:"); + Console.WriteLine($"Product or Catalog Number: {primary.Data?.ProductOrCatalogNumber}"); + Console.WriteLine($"Labeler Identification Code: {primary.Data?.LabelerIdentificationCode}"); + Console.WriteLine($"Unit of Measure ID: {primary.Data?.UnitOfMeasureID}"); + } + else if (complex is HIBCLICSecondaryAndAdditionalDataCodetext secondary) + { + Console.WriteLine("Decoded as Secondary and Additional Data:"); + Console.WriteLine($"Lot Number: {secondary.Data?.LotNumber}"); + Console.WriteLine($"Serial Number: {secondary.Data?.SerialNumber}"); + Console.WriteLine($"Quantity: {secondary.Data?.Quantity}"); + Console.WriteLine($"Expiry Date: {secondary.Data?.ExpiryDate}"); + } + else + { + // Fallback for any other complex codetext types + Console.WriteLine($"Decoded complex type: {complex.GetType().Name}"); + } + } - default: - Console.WriteLine("Detected HIBC LIC barcode, but type is unrecognized."); - break; + // Inform the user if no barcodes were detected + if (!anyFound) + { + Console.WriteLine("No barcodes detected in the image."); } } } diff --git a/hibc-lic-barcode/read-hibc-lic-barcodes-from-multi-page-pdf-file-and-extract-combined-data-for-each-page.cs b/hibc-lic-barcode/read-hibc-lic-barcodes-from-multi-page-pdf-file-and-extract-combined-data-for-each-page.cs index ee6a14b..bae90f0 100644 --- a/hibc-lic-barcode/read-hibc-lic-barcodes-from-multi-page-pdf-file-and-extract-combined-data-for-each-page.cs +++ b/hibc-lic-barcode/read-hibc-lic-barcodes-from-multi-page-pdf-file-and-extract-combined-data-for-each-page.cs @@ -1,123 +1,79 @@ -// Title: Read HIBC LIC Barcodes from Multi‑Page PDF and Extract Combined Data -// Description: Demonstrates how to read HIBC LIC barcodes from each page of a PDF file and output the combined primary and secondary data. -// Category-Description: This example belongs to the Aspose.BarCode barcode reading category, focusing on extracting complex HIBC LIC symbology from PDF documents. It showcases the use of Aspose.Pdf for page rendering and Aspose.BarCode.BarCodeRecognition for barcode detection, along with ComplexCodetextReader for parsing combined HIBC data. Developers working with healthcare or logistics barcode standards can use this pattern to process multi‑page PDFs and retrieve detailed product information. +// Title: Read HIBC LIC Barcodes from Multi‑Page PDF and Combine Page Data +// Description: Demonstrates how to load a multi‑page PDF, render each page to an image, and use Aspose.BarCode to read HIBC LIC Code128 barcodes, then concatenate the results per page. +// Category-Description: This example belongs to the Aspose.BarCode for .NET PDF barcode extraction category. It shows how to combine Aspose.Pdf (Document, PdfConverter) with Aspose.BarCode (BarCodeReader, DecodeType) to recognize HIBC LIC barcodes on each page of a PDF. Typical use cases include processing shipping documents, medical labels, or inventory forms where each page may contain one or more HIBC LIC barcodes that need to be aggregated. Developers often need to render PDF pages to images, configure barcode optimization, and collect decoded text for further processing. // Prompt: Read HIBC LIC barcodes from a multi‑page PDF file and extract combined data for each page. -// Tags: hibc, lic, barcode, pdf, read, extraction, aspose.barcode, aspose.pdf, complexcodetext +// Tags: barcode, hibc, lic, pdf, aspnet, aspnet-core, aspose.barcode, aspose.pdf, barcode-recognition, code128, multi-page using System; -using System.IO; using System.Collections.Generic; -using System.Text; +using System.IO; +using Aspose.BarCode; +using Aspose.BarCode.BarCodeRecognition; using Aspose.Pdf; using Aspose.Pdf.Facades; -using Aspose.BarCode.BarCodeRecognition; -using Aspose.BarCode.ComplexBarcode; /// -/// Example program that reads HIBC LIC barcodes from each page of a PDF file -/// and prints the extracted combined data (primary and secondary) to the console. +/// Demonstrates reading HIBC LIC Code128 barcodes from each page of a multi‑page PDF and outputting combined data per page. /// class Program { /// - /// Entry point of the application. - /// Accepts an optional PDF file path argument; defaults to "sample.pdf" if none provided. + /// Entry point of the example. Loads the PDF, renders pages, reads barcodes, and prints combined results. /// - /// Command‑line arguments. - static void Main(string[] args) + static void Main() { - // Determine PDF file path from arguments or use default. - string pdfPath = args.Length > 0 ? args[0] : "sample.pdf"; + // Path to the multi‑page PDF containing HIBC LIC barcodes. + string pdfPath = "input.pdf"; - // Verify that the specified PDF file exists. + // Verify that the PDF file exists before attempting to process it. if (!File.Exists(pdfPath)) { - Console.WriteLine($"PDF file not found: {pdfPath}"); + Console.WriteLine($"File not found: {pdfPath}"); return; } - // Load the PDF document. - using (Document pdfDocument = new Document(pdfPath)) + // Load the PDF document into Aspose.Pdf. + using (var pdfDocument = new Document(pdfPath)) { - // Initialize a PDF converter to render pages as images. - using (PdfConverter pdfConverter = new PdfConverter(pdfDocument)) + // Initialize the PDF converter which will render PDF pages to images. + var pdfConverter = new PdfConverter(pdfDocument); + // Enable barcode optimization to improve recognition speed and accuracy. + pdfConverter.RenderingOptions.BarcodeOptimization = true; + + // Iterate through each page in the PDF document. + for (int pageNumber = 1; pageNumber <= pdfDocument.Pages.Count; pageNumber++) { - // Enable barcode optimization for better detection. - pdfConverter.RenderingOptions.BarcodeOptimization = true; - int pageCount = pdfDocument.Pages.Count; + // Configure the converter to process only the current page. + pdfConverter.StartPage = pageNumber; + pdfConverter.EndPage = pageNumber; + pdfConverter.DoConvert(); - // Process each page individually. - for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++) + // Render the current page to an in‑memory image stream. + using (var pageImageStream = new MemoryStream()) { - // Configure converter to work on the current page only. - pdfConverter.StartPage = pageNumber; - pdfConverter.EndPage = pageNumber; - pdfConverter.DoConvert(); + pdfConverter.GetNextImage(pageImageStream); + pageImageStream.Position = 0; // Reset stream position for reading. - // Retrieve the rendered page image into a memory stream. - using (MemoryStream pageStream = new MemoryStream()) + // Create a barcode reader for HIBC LIC Code128 barcodes using the rendered image. + using (var reader = new BarCodeReader(pageImageStream, DecodeType.HIBCCode128LIC)) { - pdfConverter.GetNextImage(pageStream); - pageStream.Position = 0; + var barcodesOnPage = new List(); - // Initialize barcode reader for all supported types. - using (BarCodeReader reader = new BarCodeReader(pageStream, DecodeType.AllSupportedTypes)) + // Read all barcodes found on the page and collect their decoded text. + foreach (var result in reader.ReadBarCodes()) { - List hibcDataPerPage = new List(); - - // Iterate through all detected barcodes on the page. - foreach (BarCodeResult result in reader.ReadBarCodes()) - { - // Filter for HIBC symbology. - if (!string.IsNullOrEmpty(result.CodeTypeName) && result.CodeTypeName.Contains("HIBC")) - { - // Attempt to decode the HIBC LIC complex codetext. - var complex = ComplexCodetextReader.TryDecodeHIBCLIC(result.CodeText); - - // Handle combined primary and secondary data. - if (complex is HIBCLICCombinedCodetext combined) - { - StringBuilder sb = new StringBuilder(); - sb.Append($"ProductOrCatalogNumber={combined.PrimaryData.ProductOrCatalogNumber};"); - sb.Append($"LabelerIdentificationCode={combined.PrimaryData.LabelerIdentificationCode};"); - sb.Append($"UnitOfMeasureID={combined.PrimaryData.UnitOfMeasureID};"); - - if (combined.SecondaryAndAdditionalData != null) - { - var sec = combined.SecondaryAndAdditionalData; - sb.Append($"LotNumber={sec.LotNumber};"); - sb.Append($"SerialNumber={sec.SerialNumber};"); - sb.Append($"Quantity={sec.Quantity};"); - sb.Append($"ExpiryDate={sec.ExpiryDate:yyyy-MM-dd};"); - } - - hibcDataPerPage.Add(sb.ToString()); - } - // Handle primary data only (no secondary information). - else if (complex is HIBCLICPrimaryDataCodetext primary) - { - StringBuilder sb = new StringBuilder(); - sb.Append($"ProductOrCatalogNumber={primary.Data.ProductOrCatalogNumber};"); - sb.Append($"LabelerIdentificationCode={primary.Data.LabelerIdentificationCode};"); - sb.Append($"UnitOfMeasureID={primary.Data.UnitOfMeasureID};"); - hibcDataPerPage.Add(sb.ToString()); - } - } - } - - // Output collected HIBC data for the current page, if any. - if (hibcDataPerPage.Count > 0) - { - Console.WriteLine($"Page {pageNumber}:"); - foreach (string line in hibcDataPerPage) - { - Console.WriteLine(line); - } - } + barcodesOnPage.Add(result.CodeText); } + + // Combine the decoded barcode texts for the current page. + string combinedData = string.Join("; ", barcodesOnPage); + Console.WriteLine($"Page {pageNumber}: {combinedData}"); } } } + + // Release resources used by the PDF converter. + pdfConverter.Dispose(); } } } \ No newline at end of file diff --git a/hibc-lic-barcode/rotate-generated-code-128-hibc-lic-barcode-by-90-degrees-and-save-it-as-jpeg-image.cs b/hibc-lic-barcode/rotate-generated-code-128-hibc-lic-barcode-by-90-degrees-and-save-it-as-jpeg-image.cs index 4321996..45279d2 100644 --- a/hibc-lic-barcode/rotate-generated-code-128-hibc-lic-barcode-by-90-degrees-and-save-it-as-jpeg-image.cs +++ b/hibc-lic-barcode/rotate-generated-code-128-hibc-lic-barcode-by-90-degrees-and-save-it-as-jpeg-image.cs @@ -1,53 +1,53 @@ // Title: Rotate Code 128 HIBC LIC barcode and save as JPEG -// Description: Generates a HIBC Code 128 LIC barcode with secondary data, rotates the image 90 degrees, and saves it as a JPEG file. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It showcases the use of ComplexBarcodeGenerator, HIBCLICSecondaryAndAdditionalDataCodetext, and SecondaryAndAdditionalData classes to create HIBC‑based barcodes, apply image transformations, and export to common image formats. Developers working with healthcare or logistics barcodes often need to embed additional data, rotate barcodes for label orientation, and produce JPEG outputs for web or print workflows. +// Description: Demonstrates generating a HIBC LIC Code 128 barcode, rotating it 90 degrees, and saving the result as a JPEG image. +// Category-Description: This example belongs to the Aspose.BarCode generation category, focusing on complex barcode creation (HIBC LIC) and image manipulation. It showcases the use of ComplexBarcodeGenerator, EncodeTypes, and barcode parameter settings such as rotation, colors, and output format. Developers working with healthcare or logistics barcodes often need to customize orientation and export images for labeling systems. // Prompt: Rotate the generated Code 128 HIBC LIC barcode by 90 degrees and save it as a JPEG image. -// Tags: barcode, code128, hibc, rotation, jpeg, aspose.barcode, complexbarcode, generation +// Tags: barcode, code128, hibc, rotation, jpeg, aspose.barcode, complexbarcode, image generation using System; -using Aspose.BarCode.ComplexBarcode; using Aspose.BarCode.Generation; +using Aspose.BarCode.ComplexBarcode; using Aspose.Drawing; -using Aspose.Drawing.Imaging; /// -/// Demonstrates how to generate a HIBC Code 128 LIC barcode with secondary data, -/// rotate the resulting image by 90 degrees, and save it as a JPEG file. +/// Generates a HIBC LIC Code 128 barcode, rotates it 90 degrees, and saves it as a JPEG image. /// class Program { /// - /// Entry point of the example. Performs barcode generation, rotation, and saving. + /// Entry point of the example. Prepares the HIBC LIC codetext, configures barcode parameters, + /// applies a 90‑degree rotation, and writes the image to disk. /// static void Main() { - // Prepare secondary data (lot number and serial number) for the HIBC LIC barcode. - var secondaryData = new SecondaryAndAdditionalData - { - LotNumber = "LOT123", - SerialNumber = "SER123" - }; - - // Configure the complex codetext, specifying the barcode type, link character, and secondary data. - var complexCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext + // Prepare HIBC LIC Code 128 complex codetext with required primary data + var hibcCodetext = new HIBCLICPrimaryDataCodetext { BarcodeType = EncodeTypes.HIBCCode128LIC, - LinkCharacter = '+', - Data = secondaryData + Data = new PrimaryData + { + ProductOrCatalogNumber = "12345", + LabelerIdentificationCode = "A999", + UnitOfMeasureID = 1 + } }; - // Create a generator for the complex barcode using the configured codetext. - using (var generator = new ComplexBarcodeGenerator(complexCodetext)) + // Create the generator, set rotation and colors, then save as JPEG + using (var generator = new ComplexBarcodeGenerator(hibcCodetext)) { - // Generate the barcode image as a bitmap. - using (Bitmap bitmap = generator.GenerateBarCodeImage()) - { - // Rotate the bitmap 90 degrees clockwise without flipping. - bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone); + // Rotate the barcode image by 90 degrees + generator.Parameters.RotationAngle = 90f; - // Save the rotated bitmap to a JPEG file. - bitmap.Save("hibc_code128_lic_rotated.jpg", ImageFormat.Jpeg); - } + // Set foreground (barcode) and background colors + generator.Parameters.Barcode.BarColor = Color.Black; + generator.Parameters.BackColor = Color.White; + + // Define output file path and save the image + const string outputPath = "HIBC_Code128_LIC.jpg"; + generator.Save(outputPath, BarCodeImageFormat.Jpeg); + + // Inform the user where the file was saved + Console.WriteLine($"Barcode saved to {outputPath}"); } } } \ No newline at end of file diff --git a/hibc-lic-barcode/save-generated-hibc-lic-barcode-to-memorystream-and-return-its-byte-array-for-api-response.cs b/hibc-lic-barcode/save-generated-hibc-lic-barcode-to-memorystream-and-return-its-byte-array-for-api-response.cs index 902af8d..aaf7211 100644 --- a/hibc-lic-barcode/save-generated-hibc-lic-barcode-to-memorystream-and-return-its-byte-array-for-api-response.cs +++ b/hibc-lic-barcode/save-generated-hibc-lic-barcode-to-memorystream-and-return-its-byte-array-for-api-response.cs @@ -1,59 +1,59 @@ -// Title: Generate HIBC LIC Barcode and Return PNG Byte Array -// Description: Demonstrates creating a HIBC Code128 LIC barcode with secondary data, saving it to a MemoryStream, and obtaining the PNG byte array for API responses. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It showcases the use of ComplexBarcodeGenerator, HIBCLICSecondaryAndAdditionalDataCodetext, and related data classes to produce HIBC LIC barcodes. Developers often need to embed secondary information such as lot numbers, serial numbers, and dates, then deliver the barcode image as a byte array for web APIs or other services. +// Title: Generate HIBC LIC barcode and return PNG byte array +// Description: Demonstrates creating a HIBC LIC barcode with Aspose.BarCode, saving it as a PNG image into a MemoryStream, and obtaining the byte array for API responses. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on complex barcode types such as HIBC LIC. It showcases the use of ComplexBarcodeGenerator, HIBCLICSecondaryAndAdditionalDataCodetext, and related data classes to encode secondary and additional data. Developers commonly need to generate HIBC barcodes for healthcare product labeling and return the image data via web APIs. // Prompt: Save the generated HIBC LIC barcode to a MemoryStream and return its byte array for an API response. -// Tags: hibc, lic, barcode generation, png, memory stream, aspose.barcode, complexbarcode +// Tags: hibc, lic, barcode generation, png, memorystream, aspose.barcode, complexbarcodegenerator using System; using System.IO; -using Aspose.BarCode.ComplexBarcode; using Aspose.BarCode.Generation; -using Aspose.BarCode.Generation; // for BarCodeImageFormat -using Aspose.Drawing.Imaging; // for ImageFormat if needed (not used here) +using Aspose.BarCode.ComplexBarcode; +using Aspose.BarCode; /// -/// Example program that creates a HIBC LIC barcode with secondary data, -/// saves it to a MemoryStream, and outputs the resulting byte array. +/// Example program that generates a HIBC LIC barcode and returns its PNG byte array. /// class Program { /// - /// Entry point of the example. Generates the barcode and writes diagnostic information to the console. + /// Generates the barcode, saves it to a MemoryStream, and outputs the byte array length. /// static void Main() { - // Prepare secondary and additional data for the HIBC LIC barcode. - var secondaryCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext + // Prepare HIBC LIC secondary and additional data codetext + var hibcCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext { - // Select the HIBC Code128 LIC symbology. + // Set the barcode symbology (Code128 LIC in this example) BarcodeType = EncodeTypes.HIBCCode128LIC, - // The link character is required by the HIBC specification. + // Link character is mandatory; '+' is the default LinkCharacter = '+', - // Populate the secondary data fields. + // Populate secondary data (example fields) Data = new SecondaryAndAdditionalData { LotNumber = "LOT123", - SerialNumber = "SER123", + SerialNumber = "SERIAL123", Quantity = 10, - ExpiryDate = DateTime.Now.AddMonths(6), + ExpiryDate = DateTime.Today.AddMonths(6), ExpiryDateFormat = HIBCLICDateFormat.MMDDYY, - DateOfManufacture = DateTime.Now.AddMonths(-1) + DateOfManufacture = DateTime.Today.AddMonths(-1) } }; - // Generate the barcode and write it to a MemoryStream in PNG format. - using (var generator = new ComplexBarcodeGenerator(secondaryCodetext)) - using (var memoryStream = new MemoryStream()) + // Generate the barcode and save it to a MemoryStream + byte[] barcodeBytes; + using (var generator = new ComplexBarcodeGenerator(hibcCodetext)) { - // Save the barcode image to the stream. - generator.Save(memoryStream, BarCodeImageFormat.Png); - - // Retrieve the raw PNG bytes from the stream. - byte[] barcodeBytes = memoryStream.ToArray(); - - // Output diagnostic information (length and Base64 representation) for verification. - Console.WriteLine($"Barcode byte array length: {barcodeBytes.Length}"); - Console.WriteLine($"Base64: {Convert.ToBase64String(barcodeBytes)}"); + using (var ms = new MemoryStream()) + { + // Save as PNG image into the stream + generator.Save(ms, BarCodeImageFormat.Png); + // Retrieve the byte array for API response + barcodeBytes = ms.ToArray(); + } } + + // Example output: display the size of the generated byte array + Console.WriteLine($"Generated HIBC LIC barcode byte array length: {barcodeBytes.Length}"); + // The 'barcodeBytes' variable now contains the PNG image data ready for an API response. } } \ No newline at end of file diff --git a/hibc-lic-barcode/set-barcodereaderdecodetype-to-hibclic-and-verify-iscodetextvalid-after-decoding-scanned-image.cs b/hibc-lic-barcode/set-barcodereaderdecodetype-to-hibclic-and-verify-iscodetextvalid-after-decoding-scanned-image.cs index 6bde1c5..9c08c57 100644 --- a/hibc-lic-barcode/set-barcodereaderdecodetype-to-hibclic-and-verify-iscodetextvalid-after-decoding-scanned-image.cs +++ b/hibc-lic-barcode/set-barcodereaderdecodetype-to-hibclic-and-verify-iscodetextvalid-after-decoding-scanned-image.cs @@ -1,29 +1,29 @@ -// Title: Decode HIBC Code128 LIC and Validate Code Text -// Description: Demonstrates setting BarCodeReader.DecodeType to HIBCLIC and checking IsCodeTextValid after decoding a generated barcode image. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation and recognition category. It showcases the use of ComplexBarcodeGenerator to create a HIBC Code128 LIC barcode and BarCodeReader to decode it. Developers commonly use these APIs to generate complex symbologies, read scanned images, and validate decoded data in healthcare and logistics applications. +// Title: Decode HIBC Code128 LIC barcode and validate decoded text +// Description: Demonstrates generating a HIBC LIC barcode, decoding it with BarCodeReader using the HIBCCode128LIC decode type, and checking that the decoded text is present. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation and recognition category. It showcases the ComplexBarcodeGenerator for creating HIBC (Health Industry Bar Code) LIC (Labeler Identification Code) barcodes and the BarCodeReader for decoding them. Developers working with medical or pharmaceutical labeling often need to generate HIBC barcodes, scan them from images, and verify the extracted data using classes such as HIBCLICPrimaryDataCodetext, ComplexBarcodeGenerator, BarCodeReader, and DecodeType. // Prompt: Set BarCodeReader.DecodeType to HIBCLIC and verify IsCodeTextValid after decoding a scanned image. -// Tags: hibc, lic, decode, barcode, barcodereader, complexbarcodegenerator, hibclicprimarydatacodetext +// Tags: hibc, lic, barcode, decode, validation, aspose.barcode, complexbarcode, generation, recognition using System; +using System.IO; using Aspose.BarCode.ComplexBarcode; using Aspose.BarCode.Generation; using Aspose.BarCode.BarCodeRecognition; -using Aspose.Drawing; -using Aspose.Drawing.Imaging; /// /// Example program that generates a HIBC Code128 LIC barcode, decodes it, -/// and validates the decoded text using Aspose.BarCode APIs. +/// and simulates validation of the decoded text. /// class Program { /// - /// Entry point of the example. Generates a barcode, reads it, and prints validation results. + /// Entry point of the example. Generates a barcode, reads it back, + /// and prints the decoded text along with a simple validity check. /// static void Main() { - // Define primary HIBC LIC data (product number, labeler ID, unit of measure) - var primaryCodetext = new HIBCLICPrimaryDataCodetext + // Create HIBC LIC primary data codetext (Code128 variant) + var hibcCodetext = new HIBCLICPrimaryDataCodetext { BarcodeType = EncodeTypes.HIBCCode128LIC, Data = new PrimaryData @@ -34,29 +34,31 @@ static void Main() } }; - // Generate the barcode image using ComplexBarcodeGenerator - using (var generator = new ComplexBarcodeGenerator(primaryCodetext)) - using (Bitmap bitmap = generator.GenerateBarCodeImage()) + // Generate the barcode image into a memory stream + using (var barcodeStream = new MemoryStream()) { - // Initialize BarCodeReader with the specific decode type for HIBC Code128 LIC - using (var reader = new BarCodeReader(bitmap, DecodeType.HIBCCode128LIC)) + // Use ComplexBarcodeGenerator to create the barcode + using (var generator = new ComplexBarcodeGenerator(hibcCodetext)) { - // Decode all barcodes found in the image + generator.Save(barcodeStream, BarCodeImageFormat.Png); + } + + // Reset stream position to the beginning for reading + barcodeStream.Position = 0; + + // Create BarCodeReader configured for HIBC Code128 LIC decoding + using (var reader = new BarCodeReader(barcodeStream, DecodeType.HIBCCode128LIC)) + { + // Read all barcodes found in the stream var results = reader.ReadBarCodes(); - // Iterate through each decoding result + // Iterate through each detection result foreach (var result in results) { - // Determine if the decoded text is non‑empty (valid) - bool isValid = !string.IsNullOrEmpty(result.CodeText); + // Simulate IsCodeTextValid by checking that CodeText is not null or empty + bool isCodeTextValid = !string.IsNullOrEmpty(result.CodeText); Console.WriteLine($"Decoded Text: {result.CodeText}"); - Console.WriteLine($"Is Code Text Valid: {isValid}"); - } - - // Inform the user if no barcodes were detected - if (results.Length == 0) - { - Console.WriteLine("No barcode detected."); + Console.WriteLine($"IsCodeTextValid (simulated): {isCodeTextValid}"); } } } diff --git a/hibc-lic-barcode/set-barcodetype-property-to-aztec-before-assigning-hibclicprimarydatacodetext-for-generation.cs b/hibc-lic-barcode/set-barcodetype-property-to-aztec-before-assigning-hibclicprimarydatacodetext-for-generation.cs index f4491ca..e4bddf3 100644 --- a/hibc-lic-barcode/set-barcodetype-property-to-aztec-before-assigning-hibclicprimarydatacodetext-for-generation.cs +++ b/hibc-lic-barcode/set-barcodetype-property-to-aztec-before-assigning-hibclicprimarydatacodetext-for-generation.cs @@ -1,51 +1,51 @@ -// Title: Generate HIBC Aztec barcode with primary data -// Description: Demonstrates how to create a HIBC Aztec (HIBCAztecLIC) barcode by setting the barcode type before populating primary data fields, then generating and saving the image as PNG. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category, showcasing the use of ComplexBarcodeGenerator and HIBCLICPrimaryDataCodetext to produce HIBC-compliant barcodes. Developers often need to generate industry-specific barcodes (e.g., HIBC) with custom data for labeling and tracking, using EncodeTypes and image output classes. The snippet illustrates typical steps: configure barcode type, fill required data, generate image, and save to file. +// Title: Generate HIBC Aztec LIC Barcode with ComplexBarcodeGenerator +// Description: Demonstrates how to create a HIBC LIC barcode encoded as an Aztec symbol and save it as a PNG image. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category, showcasing the use of ComplexBarcodeGenerator, HIBCLICPrimaryDataCodetext, and PrimaryData classes. Typical use cases include generating HIBC (Health Industry Bar Code) Aztec symbols for product labeling in healthcare and logistics. Developers often need to configure barcode type, set primary data fields, and customize visual appearance before saving the image. // Prompt: Set the BarcodeType property to Aztec before assigning a HIBCLICPrimaryDataCodetext for generation. -// Tags: aztec, hibc, barcode generation, png, complexbarcodegenerator, aspose.barcode +// Tags: aztec, hibc, lic, barcode generation, png, complexbarcode, aspose.barcode using System; +using System.IO; using Aspose.BarCode.ComplexBarcode; using Aspose.BarCode.Generation; using Aspose.Drawing; -using Aspose.Drawing.Imaging; /// -/// Example program that generates a HIBC Aztec barcode using Aspose.BarCode. +/// Demonstrates generation of a HIBC Aztec LIC barcode and saving it as a PNG file. /// class Program { /// - /// Entry point. Creates primary data, sets barcode type, generates the barcode image, and saves it as PNG. + /// Entry point of the example. Prepares primary data, configures the barcode, and saves the image. /// static void Main() { - // Create a HIBCLICPrimaryDataCodetext instance to hold barcode configuration and data - var primaryCodetext = new HIBCLICPrimaryDataCodetext(); - - // Set the barcode type to Aztec (HIBCAztecLIC) BEFORE assigning primary data - primaryCodetext.BarcodeType = EncodeTypes.HIBCAztecLIC; + // Prepare primary data for the HIBC LIC barcode (product number, labeler ID, unit of measure) + var primaryData = new PrimaryData + { + ProductOrCatalogNumber = "12345", + LabelerIdentificationCode = "A999", + UnitOfMeasureID = 1 + }; - // Populate the required primary data fields for the HIBC barcode - primaryCodetext.Data = new PrimaryData + // Create HIBCLICPrimaryDataCodetext and set the barcode type to Aztec + var hibcCodetext = new HIBCLICPrimaryDataCodetext { - ProductOrCatalogNumber = "12345", // Example product/catalog number - LabelerIdentificationCode = "A999", // Example labeler ID - UnitOfMeasureID = 1 // Example unit of measure identifier + BarcodeType = EncodeTypes.HIBCAztecLIC, + Data = primaryData }; - // Initialize the ComplexBarcodeGenerator with the configured primary codetext - using (var generator = new ComplexBarcodeGenerator(primaryCodetext)) + // Generate the barcode using ComplexBarcodeGenerator + using (var generator = new ComplexBarcodeGenerator(hibcCodetext)) { - // Generate the barcode image as a Bitmap - using (Bitmap bitmap = generator.GenerateBarCodeImage()) - { - // Save the generated image to a PNG file - bitmap.Save("hibc_aztec.png", ImageFormat.Png); - } - } + // Optional visual settings: black bars on white background + generator.Parameters.Barcode.BarColor = Color.Black; + generator.Parameters.BackColor = Color.White; - // Inform the user that the barcode has been generated - Console.WriteLine("HIBC Aztec barcode generated: hibc_aztec.png"); + // Define output file name and save the barcode as PNG + string outputFile = "hibc_aztec.png"; + generator.Save(outputFile, BarCodeImageFormat.Png); + Console.WriteLine($"Barcode saved to: {Path.GetFullPath(outputFile)}"); + } } } \ No newline at end of file diff --git a/hibc-lic-barcode/set-linkcharacter-to-s-and-unitofmeasureid-to-1-before-generating-code-128-barcode.cs b/hibc-lic-barcode/set-linkcharacter-to-s-and-unitofmeasureid-to-1-before-generating-code-128-barcode.cs index 64ed690..3bbaa85 100644 --- a/hibc-lic-barcode/set-linkcharacter-to-s-and-unitofmeasureid-to-1-before-generating-code-128-barcode.cs +++ b/hibc-lic-barcode/set-linkcharacter-to-s-and-unitofmeasureid-to-1-before-generating-code-128-barcode.cs @@ -1,50 +1,42 @@ -// Title: Generate HIBC Code 128 LIC barcodes with LinkCharacter and UnitOfMeasureID settings -// Description: Demonstrates how to set the LinkCharacter to 'S' and UnitOfMeasureID to 1 when creating HIBC Code 128 LIC barcodes using Aspose.BarCode. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category, showcasing the use of HIBCLICSecondaryAndAdditionalDataCodetext and HIBCLICPrimaryDataCodetext classes. It illustrates typical scenarios where developers need to embed secondary data (e.g., lot numbers) and primary product information (e.g., unit of measure) into HIBC Code 128 LIC barcodes, a common requirement in healthcare and logistics labeling. +// Title: Generate HIBC Code 128 LIC barcodes with custom LinkCharacter and UnitOfMeasureID +// Description: Demonstrates how to set the LinkCharacter to 'S' for secondary data and UnitOfMeasureID to 1 for primary data when creating HIBC Code 128 LIC barcodes using Aspose.BarCode. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category, showcasing the use of ComplexBarcodeGenerator with HIBCLICSecondaryAndAdditionalDataCodetext and HIBCLICPrimaryDataCodetext. Developers commonly need to customize secondary and primary data fields such as LinkCharacter and UnitOfMeasureID for HIBC compliance, and this snippet illustrates the typical API pattern for those scenarios. // Prompt: Set LinkCharacter to 'S' and UnitOfMeasureID to 1 before generating a Code 128 barcode. -// Tags: barcode, code128, hibc, linkcharacter, unitofmeasureid, aspose.barcode, image generation +// Tags: barcode, hibc, code128, linkcharacter, unitofmeasure, complexbarcode, generation, png using System; -using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.BarCode.ComplexBarcode; using Aspose.Drawing; -using Aspose.Drawing.Imaging; /// -/// Example program that generates HIBC Code 128 LIC barcodes with specific LinkCharacter and UnitOfMeasureID settings. +/// Contains examples for generating HIBC Code 128 LIC barcodes with specific secondary and primary data settings. /// class Program { /// - /// Entry point of the application. Generates two barcode images: - /// 1. Uses secondary data codetext with LinkCharacter set to 'S'. - /// 2. Uses primary data codetext with UnitOfMeasureID set to 1. + /// Entry point of the example. Generates two barcodes: + /// 1. A secondary data barcode with LinkCharacter set to 'S'. + /// 2. A primary data barcode with UnitOfMeasureID set to 1. /// static void Main() { - // Example 1: Set LinkCharacter to 'S' using secondary data codetext + // Example 1: Configure secondary data with LinkCharacter = 'S' for a HIBC Code128 LIC barcode. var secondaryCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext { BarcodeType = EncodeTypes.HIBCCode128LIC, LinkCharacter = 'S', - Data = new SecondaryAndAdditionalData - { - // Populate at least one secondary field; otherwise generation may fail - LotNumber = "LOT123" - } + // At least one secondary data field must be populated; otherwise the generator throws an exception. + Data = new SecondaryAndAdditionalData { LotNumber = "LOT123" } }; - // Generate barcode image for secondary data and save as PNG + // Generate and save the secondary data barcode image. using (var generator = new ComplexBarcodeGenerator(secondaryCodetext)) { - using (var bitmap = generator.GenerateBarCodeImage()) - { - bitmap.Save("hibc_secondary.png", ImageFormat.Png); - } + generator.Save("hibc_code128_link.png"); } - // Example 2: Set UnitOfMeasureID to 1 using primary data codetext + // Example 2: Configure primary data with UnitOfMeasureID = 1 for a HIBC Code128 LIC barcode. var primaryCodetext = new HIBCLICPrimaryDataCodetext { BarcodeType = EncodeTypes.HIBCCode128LIC, @@ -56,15 +48,12 @@ static void Main() } }; - // Generate barcode image for primary data and save as PNG + // Generate and save the primary data barcode image. using (var generator = new ComplexBarcodeGenerator(primaryCodetext)) { - using (var bitmap = generator.GenerateBarCodeImage()) - { - bitmap.Save("hibc_primary.png", ImageFormat.Png); - } + generator.Save("hibc_code128_uom.png"); } - Console.WriteLine("Barcode images generated successfully."); + Console.WriteLine("Barcodes generated successfully."); } } \ No newline at end of file diff --git a/hibc-lic-barcode/use-complexbarcodegenerator-to-produce-qr-hibc-lic-barcode-and-write-image-directly-to-http-response-stream.cs b/hibc-lic-barcode/use-complexbarcodegenerator-to-produce-qr-hibc-lic-barcode-and-write-image-directly-to-http-response-stream.cs index 78111d4..ae6a603 100644 --- a/hibc-lic-barcode/use-complexbarcodegenerator-to-produce-qr-hibc-lic-barcode-and-write-image-directly-to-http-response-stream.cs +++ b/hibc-lic-barcode/use-complexbarcodegenerator-to-produce-qr-hibc-lic-barcode-and-write-image-directly-to-http-response-stream.cs @@ -1,77 +1,65 @@ -// Title: Generate QR HIBC LIC Barcode and Output as Base64 -// Description: Demonstrates using ComplexBarcodeGenerator to create a QR HIBC LIC barcode and encode the resulting PNG image as a Base64 string. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It showcases the ComplexBarcodeGenerator class together with HIBCLICSecondaryAndAdditionalDataCodetext to produce HIBC‑LIC barcodes, a common requirement in healthcare and pharmaceutical labeling. Developers often need to generate QR‑based HIBC LIC barcodes, customize error correction, and deliver the image directly to web clients via an HTTP response stream. -/// Prompt: Use ComplexBarcodeGenerator to produce a QR HIBC LIC barcode and write the image directly to an HTTP response stream. -/// Tags: barcode, hibc, qr, lic, complexbarcode, image, base64, aspnet, aspose.barcode +// Title: Generate QR HIBC LIC barcode and stream as PNG +// Description: Demonstrates creating a HIBC LIC QR barcode using Aspose.BarCode's ComplexBarcodeGenerator and writing the PNG image to a stream that can be sent in an HTTP response. +// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category. It shows how to use ComplexBarcodeGenerator with HIBCLICSecondaryAndAdditionalDataCodetext to produce QR HIBC LIC barcodes, configure parameters such as error correction level and colors, and output the result as an image format suitable for web delivery. Developers working with healthcare barcodes or needing to embed QR codes in HTTP responses will find this pattern useful. +// Prompt: Use ComplexBarcodeGenerator to produce a QR HIBC LIC barcode and write the image directly to an HTTP response stream. +// Tags: qr, hibc, lic, complexbarcode, aspose.barcode, generation, png, http, streaming using System; using System.IO; using Aspose.BarCode; -using Aspose.BarCode.ComplexBarcode; using Aspose.BarCode.Generation; +using Aspose.BarCode.ComplexBarcode; using Aspose.Drawing; using Aspose.Drawing.Imaging; /// -/// Example program that generates a QR HIBC LIC barcode using Aspose.BarCode -/// and writes the PNG image as a Base64 string (simulating an HTTP response). +/// Demonstrates generating a QR HIBC LIC barcode and writing it to a stream for HTTP response. /// class Program { /// - /// Entry point of the example. Generates the barcode, encodes it to Base64, - /// and writes the result to the console. In a real web application the - /// MemoryStream would be written directly to the HttpResponse output stream. + /// Entry point that creates the barcode, configures it, and writes the PNG image to a memory stream. /// static void Main() { - // NOTE: The original request was to write the barcode image directly to an HTTP response stream. - // The snippet runner executes as a console application, so we cannot provide an actual HttpResponse. - // Instead, we generate the QR HIBC LIC barcode, encode the image as Base64, and output it to the console. - // In a real ASP.NET environment you would write the MemoryStream directly to the response output stream. - - // Prepare secondary and additional data for the HIBC LIC barcode - var secondaryData = new SecondaryAndAdditionalData - { - LotNumber = "LOT123", - SerialNumber = "SERIAL123", - Quantity = 10, - ExpiryDate = DateTime.Today.AddMonths(6), - ExpiryDateFormat = HIBCLICDateFormat.MMDDYY, - DateOfManufacture = DateTime.Today - }; - - // Create the complex codetext for a QR HIBC LIC barcode + // Create HIBC LIC QR complex codetext. var hibcCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext { + // Specify QR HIBC LIC symbology. BarcodeType = EncodeTypes.HIBCQRLIC, + // Link character is mandatory for HIBC LIC. LinkCharacter = '+', - Data = secondaryData + // Populate secondary data (example fields). + Data = new SecondaryAndAdditionalData + { + LotNumber = "LOT123", + SerialNumber = "SN12345" + } }; - // Generate the barcode image using ComplexBarcodeGenerator + // Generate the barcode and write it to a simulated HTTP response stream. using (var generator = new ComplexBarcodeGenerator(hibcCodetext)) { - // Set high error correction level for QR (Level H) + // Set QR error correction level (optional). generator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelH; - // Produce the bitmap image - using (Bitmap bitmap = generator.GenerateBarCodeImage()) + // Set colors (optional). + generator.Parameters.Barcode.BarColor = Color.Black; + generator.Parameters.BackColor = Color.White; + + // Simulated HTTP response stream. + using (var responseStream = new MemoryStream()) { - // Store the image in a memory stream as PNG - using (var memoryStream = new MemoryStream()) - { - bitmap.Save(memoryStream, Aspose.Drawing.Imaging.ImageFormat.Png); - memoryStream.Position = 0; + // Save the barcode image directly to the stream as PNG. + generator.Save(responseStream, BarCodeImageFormat.Png); - // Convert the PNG bytes to a Base64 string (simulating HTTP response output) - string base64Image = Convert.ToBase64String(memoryStream.ToArray()); - Console.WriteLine("Base64 PNG Image:"); - Console.WriteLine(base64Image); - } + // In a real HTTP scenario, the stream would be written to the response. + // Here we just output the size and optionally save to a file for verification. + Console.WriteLine($"Generated QR HIBC LIC barcode PNG size: {responseStream.Length} bytes"); + + // Optional: write to a file to inspect the result. + File.WriteAllBytes("hibc_qr.png", responseStream.ToArray()); } } - - // Exit successfully } } \ No newline at end of file diff --git a/hibc-lic-barcode/use-custom-barcode-margin-of-five-pixels-when-generating-qr-hibc-lic-barcode-for-label-printing.cs b/hibc-lic-barcode/use-custom-barcode-margin-of-five-pixels-when-generating-qr-hibc-lic-barcode-for-label-printing.cs index c3897cb..bc238aa 100644 --- a/hibc-lic-barcode/use-custom-barcode-margin-of-five-pixels-when-generating-qr-hibc-lic-barcode-for-label-printing.cs +++ b/hibc-lic-barcode/use-custom-barcode-margin-of-five-pixels-when-generating-qr-hibc-lic-barcode-for-label-printing.cs @@ -1,53 +1,55 @@ -// Title: Generate QR HIBC LIC barcode with custom 5-pixel margin for label printing -// Description: Demonstrates how to create a HIBC QR LIC barcode using Aspose.BarCode and apply a uniform 5-pixel margin, suitable for label printing scenarios. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation category, focusing on HIBC symbology. It showcases the use of ComplexBarcodeGenerator, HIBCLICPrimaryDataCodetext, and barcode padding settings. Developers creating product labels, medical device tags, or inventory stickers often need to customize barcode margins for printer alignment and readability. +// Title: Generate QR HIBC LIC Barcode with Custom 5‑Pixel Margin +// Description: Demonstrates how to create a QR HIBC LIC barcode using Aspose.BarCode, apply a five‑pixel margin on all sides, and save the result as a PNG image. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on complex barcode types such as HIBC LIC QR. It showcases the use of ComplexBarcodeGenerator, HIBCLICSecondaryAndAdditionalDataCodetext, and padding configuration. Developers creating label‑printing solutions often need to customize barcode margins for scanner readability and aesthetic layout. // Prompt: Use a custom barcode margin of five pixels when generating a QR HIBC LIC barcode for label printing. -// Tags: hibc, qr, lic, barcode, margin, padding, label printing, aspose.barcode, complexbarcode +// Tags: qr, hibc, lic, barcode, margin, png, aspose.barcode, complexbarcode using System; -using Aspose.BarCode.ComplexBarcode; +using System.IO; +using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.Drawing; +using Aspose.BarCode.ComplexBarcode; /// -/// Program demonstrating QR HIBC LIC barcode generation with custom margins. +/// Example program that generates a QR HIBC LIC barcode with a custom 5‑pixel margin. /// class Program { /// - /// Entry point. Generates a QR HIBC LIC barcode, applies a 5‑pixel margin on all sides, and saves it as PNG. + /// Entry point of the example. Creates secondary data, configures the barcode, applies padding, and saves the image. /// static void Main() { - // Prepare primary data for HIBC QR LIC barcode - var primaryCodetext = new HIBCLICPrimaryDataCodetext + // Prepare secondary data required for the HIBC LIC QR barcode (lot and serial numbers). + var secondaryData = new SecondaryAndAdditionalData + { + LotNumber = "LOT123", + SerialNumber = "SN456" + }; + + // Build the HIBC LIC QR codetext object, specifying the symbology and link character. + var hibcCodetext = new HIBCLICSecondaryAndAdditionalDataCodetext { - BarcodeType = EncodeTypes.HIBCQRLIC, - Data = new PrimaryData - { - ProductOrCatalogNumber = "12345", - LabelerIdentificationCode = "A999", - UnitOfMeasureID = 1 - } + BarcodeType = EncodeTypes.HIBCQRLIC, // QR HIBC LIC symbology + LinkCharacter = '+', // Required link character + Data = secondaryData }; - // Create generator for the complex barcode - using (var generator = new ComplexBarcodeGenerator(primaryCodetext)) + // Create the barcode generator with the prepared codetext. + using (var generator = new ComplexBarcodeGenerator(hibcCodetext)) { - // Set custom margin (padding) of 5 pixels on all sides + // Apply a uniform margin of five pixels on all sides of the barcode. generator.Parameters.Barcode.Padding.Left.Pixels = 5f; generator.Parameters.Barcode.Padding.Top.Pixels = 5f; generator.Parameters.Barcode.Padding.Right.Pixels = 5f; generator.Parameters.Barcode.Padding.Bottom.Pixels = 5f; - // Define output file path - string outputPath = "hibc_qr.png"; - - // Save the barcode image to the specified path - generator.Save(outputPath); + // Define the output file path and save the barcode as a PNG image. + string outputPath = "qr_hibc_lic.png"; + generator.Save(outputPath, BarCodeImageFormat.Png); - // Inform the user that the barcode has been saved - Console.WriteLine($"QR HIBC LIC barcode saved to {outputPath}"); + // Inform the user where the file was saved. + Console.WriteLine($"Barcode saved to {Path.GetFullPath(outputPath)}"); } } } \ No newline at end of file diff --git a/hibc-lic-barcode/validate-that-generated-barcode-complies-with-hibc-specifications-by-checking-its-checksum-after-creation.cs b/hibc-lic-barcode/validate-that-generated-barcode-complies-with-hibc-specifications-by-checking-its-checksum-after-creation.cs index 1f2967b..b0ef1e3 100644 --- a/hibc-lic-barcode/validate-that-generated-barcode-complies-with-hibc-specifications-by-checking-its-checksum-after-creation.cs +++ b/hibc-lic-barcode/validate-that-generated-barcode-complies-with-hibc-specifications-by-checking-its-checksum-after-creation.cs @@ -1,80 +1,78 @@ -// Title: HIBC Code 128 LIC Barcode Generation and Checksum Validation -// Description: Demonstrates creating a HIBC Code 128 LIC barcode, decoding it, and verifying its checksum by comparing decoded fields with the original data. -// Category-Description: This example belongs to the Aspose.BarCode complex barcode generation and recognition category. It showcases the use of ComplexBarcodeGenerator, ComplexCodetextReader, and BarCodeReader classes to produce and validate HIBC symbology, a common requirement in healthcare and logistics for accurate product identification. Developers often need to generate HIBC barcodes, read them back, and ensure data integrity via checksum verification. +// Title: Generate and Validate HIBC Code128 LIC Barcode with Checksum +// Description: Demonstrates creating a HIBC Code128 LIC barcode, saving it as an image, and verifying its checksum by decoding and comparing the generated codetext. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation and recognition category. It showcases the use of ComplexBarcodeGenerator to construct HIBC barcodes and BarCodeReader to decode them, a common workflow for developers needing to ensure barcode compliance and data integrity in healthcare and logistics applications. Typical use cases include label creation, automated scanning validation, and regulatory compliance checks. // Prompt: Validate that the generated barcode complies with HIBC specifications by checking its checksum after creation. -// Tags: hibc, code128, lic, barcode, generation, validation, checksum, aspnet, aspnetcore, aspnetmvc, aspnetwebapi +// Tags: hibc, code128, lic, barcode generation, barcode validation, checksum, aspose.barcode using System; using System.IO; -using Aspose.BarCode.ComplexBarcode; using Aspose.BarCode.Generation; using Aspose.BarCode.BarCodeRecognition; -using Aspose.Drawing; -using Aspose.Drawing.Imaging; +using Aspose.BarCode.ComplexBarcode; /// -/// Generates a HIBC Code 128 LIC barcode, reads it back, and validates the checksum -/// by ensuring the decoded data matches the original input. +/// Example program that generates a HIBC Code128 LIC barcode, saves it to a file, +/// and validates its checksum by decoding the image and comparing the codetext. /// class Program { /// - /// Entry point of the example. Performs barcode creation, decoding, and checksum validation. + /// Entry point of the example. Performs barcode creation, saving, and checksum validation. /// static void Main() { - // Define primary HIBC data to encode - var primaryCodetext = new HIBCLICPrimaryDataCodetext + // Prepare primary data for HIBC Code128 LIC barcode + var primaryData = new PrimaryData + { + ProductOrCatalogNumber = "12345", + LabelerIdentificationCode = "A999", + UnitOfMeasureID = 1 + }; + + // Construct the codetext object that defines the barcode type and data + var hibcCodetext = new HIBCLICPrimaryDataCodetext { BarcodeType = EncodeTypes.HIBCCode128LIC, - Data = new PrimaryData - { - ProductOrCatalogNumber = "12345", - LabelerIdentificationCode = "A999", - UnitOfMeasureID = 1 - } + Data = primaryData }; - // Generate the barcode image in memory using ComplexBarcodeGenerator - using (var generator = new ComplexBarcodeGenerator(primaryCodetext)) - using (Bitmap bitmap = generator.GenerateBarCodeImage()) - using (var ms = new MemoryStream()) + // Define the output image path + string imagePath = "hibc_lic.png"; + + // Generate the barcode image and save it to the specified file + using (var generator = new ComplexBarcodeGenerator(hibcCodetext)) + { + // Optional: set colors or other parameters here if needed + generator.Save(imagePath); + } + + // Read the generated barcode image and verify checksum by comparing decoded text + using (var reader = new BarCodeReader(imagePath, DecodeType.HIBCCode128LIC)) { - // Save the bitmap to a memory stream in PNG format - bitmap.Save(ms, ImageFormat.Png); - ms.Position = 0; // Reset stream position for reading + // Ensure checksum validation is enabled (default for HIBC) + reader.BarcodeSettings.ChecksumValidation = ChecksumValidation.On; - // Decode the barcode from the memory stream - using (var reader = new BarCodeReader(ms, DecodeType.HIBCCode128LIC)) - { - var results = reader.ReadBarCodes(); + bool valid = false; - // Ensure at least one barcode was detected - if (results.Length == 0) + // Iterate through all detected barcodes (should be one in this case) + foreach (var result in reader.ReadBarCodes()) + { + // If the decoded text matches the original codetext, checksum is correct + if (!string.IsNullOrEmpty(result.CodeText) && result.CodeText == hibcCodetext.GetConstructedCodetext()) { - Console.WriteLine("No barcode detected."); - return; + valid = true; + Console.WriteLine($"Decoded CodeText: {result.CodeText}"); } - - // Retrieve the decoded text and attempt to parse it as HIBCLICPrimaryDataCodetext - var decodedText = results[0].CodeText; - var decodedCodetext = ComplexCodetextReader.TryDecodeHIBCLIC(decodedText) as HIBCLICPrimaryDataCodetext; - - // Verify that decoding succeeded - if (decodedCodetext == null) + else { - Console.WriteLine("Failed to decode HIBC LIC codetext."); - return; + Console.WriteLine($"Decoded CodeText does not match expected value: {result.CodeText}"); } - - // Validate that decoded fields match the original data (checksum validation) - bool isValid = - decodedCodetext.Data.ProductOrCatalogNumber == primaryCodetext.Data.ProductOrCatalogNumber && - decodedCodetext.Data.LabelerIdentificationCode == primaryCodetext.Data.LabelerIdentificationCode && - decodedCodetext.Data.UnitOfMeasureID == primaryCodetext.Data.UnitOfMeasureID; - - Console.WriteLine(isValid ? "Checksum validation passed." : "Checksum validation failed."); } + + // Output the overall validation result + Console.WriteLine(valid + ? "HIBC barcode checksum validation succeeded." + : "HIBC barcode checksum validation failed."); } } } \ No newline at end of file