diff --git a/gs1-barcode-types/apply-10-pixel-margin-around-gs1-code-128-barcode-and-save-as-jpeg.cs b/gs1-barcode-types/apply-10-pixel-margin-around-gs1-code-128-barcode-and-save-as-jpeg.cs index 87df954..167da94 100644 --- a/gs1-barcode-types/apply-10-pixel-margin-around-gs1-code-128-barcode-and-save-as-jpeg.cs +++ b/gs1-barcode-types/apply-10-pixel-margin-around-gs1-code-128-barcode-and-save-as-jpeg.cs @@ -1,37 +1,43 @@ // Title: Apply 10‑pixel margin to GS1 Code 128 barcode and save as JPEG // Description: Demonstrates how to generate a GS1 Code 128 barcode, add a uniform 10‑pixel margin, and export it as a JPEG image. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and barcode padding parameters. Typical use cases include creating GS1‑compliant barcodes for product labeling with custom margins for better readability. Developers often need to adjust padding, size, and output format when integrating barcodes into documents or images. -// Prompt: Apply a 10‑pixel margin around a GS1 Code 128 barcode and save as JPEG. -// Tags: gs1, code128, barcode, margin, padding, jpeg, aspose.barcode, generation +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and BarCodeImageFormat classes. Typical use cases include creating printable barcodes with custom padding for layout requirements. Developers often need to adjust margins to fit design constraints or scanning guidelines. +/// Prompt: Apply a 10‑pixel margin around a GS1 Code 128 barcode and save as JPEG. +/// Tags: gs1, code128, margin, jpeg, aspose.barcode, barcodegenerator using System; using Aspose.BarCode.Generation; using Aspose.BarCode; /// -/// Generates a GS1 Code 128 barcode, applies a 10‑pixel margin on all sides, and saves the result as a JPEG image. +/// Demonstrates generating a GS1 Code 128 barcode with a 10‑pixel margin and saving it as a JPEG image. /// class Program { /// - /// Entry point of the example. Creates the barcode, configures padding, and writes the JPEG file. + /// Entry point that creates the barcode, applies padding, and writes the image to disk. /// static void Main() { - // Sample GS1 Code 128 data (AI (01) for GTIN) - const string codeText = "(01)12345678901231"; + // GS1 Code 128 codetext: AI (01) with a 14‑digit GTIN + string codeText = "(01)00123456789012"; - // Initialize the barcode generator with the GS1 Code 128 symbology and the sample data + // Output JPEG file path + string outputPath = "gs1code128_margin.jpg"; + + // Initialize the barcode generator for GS1 Code 128 using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) { - // Apply a uniform 10‑pixel margin (padding) around the barcode - generator.Parameters.Barcode.Padding.Left.Pixels = 10f; - generator.Parameters.Barcode.Padding.Top.Pixels = 10f; - generator.Parameters.Barcode.Padding.Right.Pixels = 10f; + // Apply a uniform 10‑pixel margin on all sides via padding + generator.Parameters.Barcode.Padding.Left.Pixels = 10f; + generator.Parameters.Barcode.Padding.Top.Pixels = 10f; + generator.Parameters.Barcode.Padding.Right.Pixels = 10f; generator.Parameters.Barcode.Padding.Bottom.Pixels = 10f; - // Save the generated barcode as a JPEG image file - generator.Save("gs1code128.jpg"); + // Save the generated barcode as a JPEG image + 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/gs1-barcode-types/batch-convert-list-of-ai-strings-to-gs1-datamatrix-png-files-using-parallel-processing.cs b/gs1-barcode-types/batch-convert-list-of-ai-strings-to-gs1-datamatrix-png-files-using-parallel-processing.cs index 3cf1ec5..8ee2baf 100644 --- a/gs1-barcode-types/batch-convert-list-of-ai-strings-to-gs1-datamatrix-png-files-using-parallel-processing.cs +++ b/gs1-barcode-types/batch-convert-list-of-ai-strings-to-gs1-datamatrix-png-files-using-parallel-processing.cs @@ -1,8 +1,8 @@ -// Title: Batch convert AI strings to GS1 DataMatrix PNG files using parallel processing -// Description: Demonstrates how to encode a list of GS1 Application Identifier strings into DataMatrix barcodes and save them as PNG images in parallel. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on GS1 DataMatrix encoding. It showcases the use of BarcodeGenerator, EncodeTypes, and image format classes to create high‑resolution PNG files. Developers often need to batch‑process multiple barcode values efficiently, and this pattern illustrates parallel execution with safe file naming. +// Title: Batch conversion of AI strings to GS1 DataMatrix PNG files using parallel processing +// Description: Demonstrates how to generate GS1 DataMatrix barcodes from a list of Application Identifier (AI) strings and save them as PNG images in parallel. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating the use of the BarcodeGenerator class with EncodeTypes.GS1DataMatrix. It shows typical scenarios such as bulk barcode creation for inventory or logistics, where developers need to efficiently produce multiple barcode images with proper file naming. The snippet highlights parallel processing with Parallel.ForEach to speed up large‑scale barcode generation tasks. // Prompt: Batch convert a list of AI strings to GS1 DataMatrix PNG files using parallel processing. -// Tags: gs1 datamatrix, batch, parallel, png, barcode generation, aspose.barcode, encode types, image output +// Tags: gs1datamatrix, barcode generation, parallel processing, png output, aspose.barcode, encode types, bulk conversion using System; using System.Collections.Generic; @@ -12,67 +12,55 @@ using Aspose.BarCode.Generation; /// -/// Provides an entry point that batch‑processes a collection of GS1 Application Identifier strings, -/// generating GS1 DataMatrix barcodes and saving each as a PNG file using parallel execution. +/// Provides an entry point for generating GS1 DataMatrix barcodes from a collection of AI strings +/// and saving them as PNG files using parallel processing. /// class Program { /// - /// Main method that orchestrates the barcode generation workflow. + /// Main method that orchestrates the batch barcode generation. /// static void Main() { - // Define a sample list of AI (Application Identifier) strings to encode as GS1 DataMatrix. + // Define a sample list of GS1 AI strings (each must contain AI (01) with 14 digits) List aiStrings = new List { - "(01)01234567890128(10)ABC123", - "(01)09876543210987(21)XYZ789", - "(01)12345678901231(17)221231", - "(01)55555555555555(3103)001500", - "(01)99999999999999(3102)000750" + "(01)00123456789012", // GTIN-12 padded to 14 digits + "(01)01234567890123", // GTIN-13 padded to 14 digits + "(01)12345678901231", // GTIN-14 with valid check digit + "(01)00012345678905", // GTIN-12 padded + "(01)00001234567890" // GTIN-13 padded }; - // Ensure the output directory exists. - string outputFolder = "OutputDataMatrix"; + // Prepare the output directory for generated PNG files + string outputFolder = Path.Combine(Directory.GetCurrentDirectory(), "GS1DataMatrixOutput"); if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } - // Process each AI string in parallel to improve performance on multi‑core systems. - Parallel.ForEach(aiStrings, aiString => + // Perform barcode generation in parallel to improve performance + Parallel.ForEach(aiStrings, (codeText) => { - // Generate a file‑system‑safe name from the AI string (remove invalid characters). - string safeFileName = GetSafeFileName(aiString) + ".png"; + // Create a safe file name by stripping characters illegal in file names + string safeFileName = codeText.Replace("(", "").Replace(")", "").Replace(" ", "") + ".png"; string outputPath = Path.Combine(outputFolder, safeFileName); - // Create and configure the barcode generator for GS1 DataMatrix. - using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, aiString)) + // Initialize the barcode generator for GS1 DataMatrix with the current AI string + using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Set image size using interpolation mode for high‑quality scaling. - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; - generator.Parameters.ImageWidth.Point = 300f; - generator.Parameters.ImageHeight.Point = 300f; + // Optional: adjust module size if required + // generator.Parameters.Barcode.XDimension.Point = 2f; - // Save the generated barcode as a PNG file. + // Save the generated barcode as a PNG image generator.Save(outputPath, BarCodeImageFormat.Png); } - // Output the result to the console for tracking. - Console.WriteLine($"Generated: {outputPath}"); + // Log the successful generation of the file + Console.WriteLine($"Generated {outputPath}"); }); - } - - // Helper method to create a file‑system‑safe name from the AI string. - private static string GetSafeFileName(string input) - { - // Replace any characters that are invalid in file names. - foreach (char c in Path.GetInvalidFileNameChars()) - { - input = input.Replace(c, '_'); - } - // Remove parentheses and spaces that are unnecessary for the file name. - return input.Replace("(", "").Replace(")", "").Replace(" ", "_"); + // Indicate that the batch process has finished + Console.WriteLine("Batch conversion completed."); } } \ No newline at end of file diff --git a/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-compress-png-outputs-into-single-zip-archive-for-distribution.cs b/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-compress-png-outputs-into-single-zip-archive-for-distribution.cs index eb51586..8c6d30d 100644 --- a/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-compress-png-outputs-into-single-zip-archive-for-distribution.cs +++ b/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-compress-png-outputs-into-single-zip-archive-for-distribution.cs @@ -1,75 +1,78 @@ -// Title: Batch generate GS1 Code 128 barcodes and zip them -// Description: Generates multiple GS1 Code 128 barcodes as PNG files and compresses them into a single ZIP archive for easy distribution. -// Category-Description: This example belongs to the Aspose.BarCode generation category, demonstrating how to use the BarcodeGenerator class with EncodeTypes.GS1Code128 to create barcodes, customize parameters (e.g., checksum display), and save them in PNG format. It also shows how to package the generated images using System.IO.Compression.ZipArchive. Developers working with product identification, inventory, or logistics often need to produce GS1-compliant barcodes in bulk and deliver them as a single archive. +// Title: Batch generate GS1 Code 128 barcodes and package them into a ZIP archive +// Description: Demonstrates creating multiple GS1‑128 (GS1 Code 128) barcodes from GTIN‑14 values, saving each as a PNG, and compressing all images into a single ZIP file for easy distribution. +// Category-Description: This example belongs to the Aspose.BarCode generation category, showcasing how to use the BarcodeGenerator class with EncodeTypes.GS1Code128. Typical use cases include bulk creation of product barcodes for inventory, labeling, or e‑commerce platforms, where developers need to automate image output and bundle results for downstream processing. The code illustrates setting visual parameters, exporting to PNG, and using .NET's ZipArchive to create a distributable archive. // Prompt: Batch generate GS1 Code 128 barcodes, compress PNG outputs into a single ZIP archive for distribution. -// Tags: gs1, code128, barcode, generation, png, zip, aspose.barcode +// Tags: gs1,code128,barcode,generation,png,zip,compression,aspose.barcode using System; -using System.Collections.Generic; using System.IO; using System.IO.Compression; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Demonstrates batch creation of GS1 Code 128 barcodes and compression of the resulting PNG files into a ZIP archive. +/// Demonstrates batch generation of GS1 Code 128 barcodes and zipping the PNG outputs. /// class Program { /// - /// Entry point of the example. Generates barcode images from predefined GS1 data strings, - /// saves them as PNG files, and archives them into a single ZIP file. + /// Entry point that creates barcodes for a set of GTIN‑14 values, saves them as PNG images, + /// and stores them in a ZIP archive. /// static void Main() { - // Define sample GS1 Code 128 data strings using Application Identifier (AI) format. - List gs1Data = new List + // Define a collection of sample GTIN‑14 values (14 digits, leading zeros preserved) + string[] gtins = new string[] { - "(01)12345678901231", // GTIN only - "(01)98765432109876(10)ABC123", // GTIN + Batch/Lot - "(01)55555555555555(21)SN001", // GTIN + Serial Number - "(01)11111111111111(17)230101", // GTIN + Expiration Date - "(01)22222222222222(3103)001500" // GTIN + Net weight (kg) + "00123456789012", + "01234567890123", + "12345678901234", + "23456789012345", + "34567890123456" }; - // Create an output directory for the generated PNG files. - string outputDir = Path.Combine(Directory.GetCurrentDirectory(), "Barcodes"); - Directory.CreateDirectory(outputDir); + // Target path for the resulting ZIP archive + string zipPath = "GS1Code128Barcodes.zip"; - // Iterate over each GS1 data string and generate a corresponding barcode image. - for (int i = 0; i < gs1Data.Count; i++) + // Create the ZIP archive and add each generated PNG as an entry + using (FileStream zipFile = new FileStream(zipPath, FileMode.Create)) + using (ZipArchive archive = new ZipArchive(zipFile, ZipArchiveMode.Create)) { - string codeText = gs1Data[i]; - string fileName = $"barcode_{i + 1}.png"; - string filePath = Path.Combine(outputDir, fileName); + int index = 1; // Simple counter for naming entries - // Initialize the barcode generator with GS1 Code 128 symbology and the current data string. - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) + foreach (string gtin in gtins) { - // Ensure the checksum is always displayed (optional visual requirement). - generator.Parameters.Barcode.ChecksumAlwaysShow = true; + // GS1 Code 128 requires the Application Identifier (01) followed by a 14‑digit GTIN + string codeText = $"(01){gtin}"; - // Save the generated barcode as a PNG file. - generator.Save(filePath); - } - } + // Initialise the barcode generator with the GS1 Code 128 symbology and the prepared text + using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) + { + // Optional visual settings: module size (X‑dimension) and bar height + generator.Parameters.Barcode.XDimension.Point = 2f; + generator.Parameters.Barcode.BarHeight.Point = 50f; - // Define the path for the ZIP archive that will contain all generated PNG files. - string zipPath = Path.Combine(Directory.GetCurrentDirectory(), "Barcodes.zip"); + // Render the barcode to a memory stream in PNG format + using (MemoryStream ms = new MemoryStream()) + { + generator.Save(ms, BarCodeImageFormat.Png); + ms.Position = 0; // Reset stream position before copying - // Create the ZIP archive and add each PNG file as an entry. - using (var zipStream = new FileStream(zipPath, FileMode.Create)) - using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Create, leaveOpen: false)) - { - foreach (string file in Directory.GetFiles(outputDir, "*.png")) - { - string entryName = Path.GetFileName(file); - archive.CreateEntryFromFile(file, entryName); + // Create a new entry in the ZIP archive for this barcode image + ZipArchiveEntry entry = archive.CreateEntry($"barcode_{index}.png", CompressionLevel.Optimal); + using (Stream entryStream = entry.Open()) + { + // Copy the PNG data into the ZIP entry + ms.CopyTo(entryStream); + } + } + } + + index++; } } - // Output summary information to the console. - Console.WriteLine($"Generated {gs1Data.Count} GS1 Code 128 barcodes in '{outputDir}'."); - Console.WriteLine($"Compressed into ZIP archive: {zipPath}"); + // Inform the user where the ZIP archive was created + Console.WriteLine($"ZIP archive created: {Path.GetFullPath(zipPath)}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-csv-list-of-ai-strings-and-output-png-files.cs b/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-csv-list-of-ai-strings-and-output-png-files.cs index 5d4c498..46ac32a 100644 --- a/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-csv-list-of-ai-strings-and-output-png-files.cs +++ b/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-csv-list-of-ai-strings-and-output-png-files.cs @@ -1,8 +1,8 @@ -// Title: Batch generate GS1 Code 128 barcodes from CSV -// Description: Reads a CSV file containing GS1 AI strings, creates a GS1 Code 128 barcode for each entry, and saves the images as PNG files. -// Category-Description: This example belongs to the Aspose.BarCode generation category, demonstrating how to use the BarcodeGenerator class with EncodeTypes.GS1Code128. Typical use cases include bulk barcode creation for inventory, shipping, or retail labeling where AI data is stored in CSV format. Developers often need to automate barcode production, handle file I/O, and manage output directories, which this snippet illustrates. +// Title: Batch generate GS1 Code 128 barcodes from CSV and save as PNG +// Description: Demonstrates reading a CSV file of GS1 AI strings, generating a GS1 Code 128 barcode for each entry, and saving the images as PNG files. +// Category-Description: This example belongs to the barcode generation category of Aspose.BarCode for .NET. It shows how to use the BarcodeGenerator class with EncodeTypes.GS1Code128 to create barcodes from data sources, configure visual parameters, and export to image formats. Developers often need to batch‑process data files to produce barcodes for labeling, inventory, or shipping applications. // Prompt: Batch generate GS1 Code 128 barcodes from a CSV list of AI strings and output PNG files. -// Tags: gs1,code128,barcode,generation,csv,output,png,aspose.barcode +// Tags: gs1code128, batch, png, aspose.barcode, generation using System; using System.IO; @@ -10,84 +10,72 @@ using Aspose.BarCode.Generation; /// -/// Demonstrates batch generation of GS1 Code 128 barcodes from a CSV file and saves each barcode as a PNG image. +/// Generates GS1 Code 128 barcodes from a list of AI strings stored in a CSV file +/// and saves each barcode as a PNG image in an output folder. /// class Program { /// - /// Entry point of the application. Reads AI strings from a CSV, generates barcodes, and writes PNG files. + /// Application entry point. Handles CSV input, creates sample data if needed, + /// configures barcode generation settings, and writes PNG files. /// - static void Main() + /// Optional command‑line argument specifying the CSV file path. + static void Main(string[] args) { - // Input CSV file containing GS1 AI strings (one per line) - const string inputCsv = "input.csv"; + // Determine CSV path (argument or default) + string csvPath = args.Length > 0 ? args[0] : "sample.csv"; - // Directory where generated PNG files will be saved - const string outputDir = "output"; - - // -------------------------------------------------------------------- - // Ensure the input file exists; if not, create a sample file with a few AI strings - // -------------------------------------------------------------------- - if (!File.Exists(inputCsv)) + // If CSV does not exist, create a small sample file with GS1 AI strings + if (!File.Exists(csvPath)) { - string[] sampleData = + string[] sampleData = new string[] { + "(01)00123456789012", "(01)12345678901231", - "(10)ABC123", - "(21)9876543210", - "(01)09876543210987(21)XYZ12345" + "(01)00012345678905", + "(01)98765432109876", + "(01)11111111111111" }; - File.WriteAllLines(inputCsv, sampleData); - Console.WriteLine($"Sample input file '{inputCsv}' created."); + File.WriteAllLines(csvPath, sampleData); + Console.WriteLine($"Sample CSV created at {Path.GetFullPath(csvPath)}"); } - // -------------------------------------------------------------------- - // Ensure the output directory exists - // -------------------------------------------------------------------- - if (!Directory.Exists(outputDir)) + // Prepare output folder for generated barcode images + string outputFolder = "Barcodes"; + if (!Directory.Exists(outputFolder)) { - Directory.CreateDirectory(outputDir); + Directory.CreateDirectory(outputFolder); } - // -------------------------------------------------------------------- - // Read all non‑empty lines from the CSV - // -------------------------------------------------------------------- - string[] lines = File.ReadAllLines(inputCsv); + // Read each line (AI string) from the CSV file + string[] lines = File.ReadAllLines(csvPath); int index = 1; - foreach (string rawLine in lines) { // Trim whitespace and skip empty lines - string line = rawLine.Trim(); - if (string.IsNullOrEmpty(line)) + string codeText = rawLine.Trim(); + if (string.IsNullOrEmpty(codeText)) continue; - // Create a safe file name based on the index (e.g., barcode_1.png) - string fileName = $"barcode_{index}.png"; - string outputPath = Path.Combine(outputDir, fileName); + // Build output file name (e.g., barcode_1.png) + string outputFile = Path.Combine(outputFolder, $"barcode_{index}.png"); - try + // Create a barcode generator for GS1 Code 128 with the current AI string + using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) { - // -------------------------------------------------------------------- - // Generate GS1 Code128 barcode for the AI string - // -------------------------------------------------------------------- - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, line)) - { - // Save as PNG (format inferred from file extension) - generator.Save(outputPath); - } + // Do not throw an exception if the code text has minor format issues + generator.Parameters.Barcode.ThrowExceptionWhenCodeTextIncorrect = false; - Console.WriteLine($"Generated: {outputPath}"); - } - catch (Exception ex) - { - // Log any errors that occur during barcode generation - Console.WriteLine($"Error processing line {index}: {ex.Message}"); + // Optional visual settings: filled bars and X-dimension + generator.Parameters.Barcode.FilledBars = true; + generator.Parameters.Barcode.XDimension.Point = 2f; + + // Save the barcode image; the file extension determines the format (PNG) + generator.Save(outputFile); } + Console.WriteLine($"Generated: {outputFile}"); index++; } - - Console.WriteLine("Barcode generation completed."); } } \ No newline at end of file diff --git a/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-database-table-saving-each-image-to-network-share.cs b/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-database-table-saving-each-image-to-network-share.cs index b11bb8e..78bb546 100644 --- a/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-database-table-saving-each-image-to-network-share.cs +++ b/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-database-table-saving-each-image-to-network-share.cs @@ -1,8 +1,8 @@ -// Title: Batch Generation of GS1 Code 128 Barcodes from a List -// Description: Demonstrates creating GS1 Code 128 barcodes for each record and saving them as PNG files to a network share. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use the BarcodeGenerator class with EncodeTypes.GS1Code128. Typical use cases include bulk barcode creation from database tables, exporting to shared locations, and integrating barcode assets into enterprise workflows. Developers often need to validate input, configure checksum display, and handle file system operations when automating barcode production. +// Title: Batch generate GS1 Code 128 barcodes and save as PNG files +// Description: Demonstrates how to generate multiple GS1 Code 128 barcodes from a list (simulating a database) and save each image to a specified folder, such as a network share. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category. It shows how to use the BarcodeGenerator class with EncodeTypes.GS1Code128, configure basic appearance settings, and output PNG images. Developers often need to batch‑create barcodes from data sources like databases for inventory, shipping, or retail applications, and this pattern illustrates the typical workflow. // Prompt: Batch generate GS1 Code 128 barcodes from a database table, saving each image to a network share. -// Tags: gs1,code128,barcode,generation,output,network,aspobarcodes,aspnet +// Tags: gs1,code128,barcode,generation,png,aspose.barcode,batch,database,network share using System; using System.Collections.Generic; @@ -11,93 +11,86 @@ using Aspose.BarCode.Generation; /// -/// Demonstrates batch generation of GS1 Code 128 barcodes and saving them to a network share. +/// Generates GS1 Code 128 barcodes in batch and saves them as PNG files to a target folder. /// class Program { /// - /// Entry point of the example. Generates barcodes for a set of GS1 codes and writes PNG files to the specified folder. + /// Entry point of the application. Creates the output directory, validates each code, + /// generates the barcode image, and writes it to disk. /// static void Main() { - // NOTE: In a real scenario, replace the sample data with a database query. - // Example of real implementation (requires a database provider): - // var connectionString = "your_connection_string"; - // using (var connection = new SqlConnection(connectionString)) - // { - // connection.Open(); - // var command = new SqlCommand("SELECT GS1Code FROM YourTable", connection); - // using (var reader = command.ExecuteReader()) - // { - // while (reader.Read()) - // { - // var codeText = reader.GetString(0); - // // Generate barcode... - // } - // } - // } + // Define the output folder (replace with actual network share UNC path in production) + string outputFolder = @"C:\Barcodes\Output"; - // Sample GS1 Code 128 data (AI format) for demonstration. - List gs1Codes = new List - { - "(01)12345678901231", - "(01)98765432109876", - "(01)55555555555555", - "(01)11111111111111", - "(01)22222222222222" - }; - - // Destination folder (network share or local path). Ensure the folder exists. - string outputFolder = @"\\networkshare\Barcodes"; // Replace with actual network share. - // For testing on a local machine, you may use: - // string outputFolder = Path.Combine(Environment.CurrentDirectory, "Barcodes"); - - // Create the output directory if it does not exist. + // Ensure the output directory exists if (!Directory.Exists(outputFolder)) { - try - { - Directory.CreateDirectory(outputFolder); - } - catch (Exception ex) - { - Console.WriteLine($"Failed to create output directory: {ex.Message}"); - return; - } + Directory.CreateDirectory(outputFolder); } + // ----------------------------------------------------------------- + // In a real scenario, replace the following hard‑coded list with a + // database query (e.g., using System.Data.SqlClient) that retrieves + // the GS1 Code 128 values to encode. + // ----------------------------------------------------------------- + List gs1Code128Values = new List + { + // AI (01) – GTIN (14 digits). Example GTIN‑14: 00123456789012 + "(01)00123456789012", + "(01)00123456789013", + "(01)00123456789014", + "(01)00123456789015", + "(01)00123456789016" + }; + // ----------------------------------------------------------------- + int index = 1; - foreach (string codeText in gs1Codes) + foreach (string codeText in gs1Code128Values) { - // Validate that the codetext follows GS1 format (basic check). - if (string.IsNullOrWhiteSpace(codeText) || !codeText.StartsWith("(")) + // Validate that the code text contains a valid (01) AI with 14 digits + if (!IsValidGs1Code128(codeText)) { - Console.WriteLine($"Skipping invalid GS1 code: {codeText}"); + Console.WriteLine($"Skipping invalid code text: {codeText}"); continue; } - try - { - // Initialize the barcode generator with GS1 Code 128 symbology. - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) - { - // Optional: always show checksum in human‑readable text. - generator.Parameters.Barcode.ChecksumAlwaysShow = true; - - // Build the full file path for the PNG image. - string fileName = Path.Combine(outputFolder, $"GS1Code128_{index}.png"); + // Build the output file name (e.g., Barcode_0001.png) + string fileName = $"Barcode_{index:D4}.png"; + string outputPath = Path.Combine(outputFolder, fileName); - // Save the barcode image as PNG. - generator.Save(fileName); - Console.WriteLine($"Saved barcode {index} to {fileName}"); - } - } - catch (Exception ex) + // Generate and save the barcode + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) { - Console.WriteLine($"Error generating barcode for '{codeText}': {ex.Message}"); + // Optional: configure appearance + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; + generator.Parameters.Barcode.XDimension.Point = 2f; // module size + generator.Parameters.Barcode.BarHeight.Point = 50f; // bar height + + // Save as PNG + generator.Save(outputPath); } + Console.WriteLine($"Saved barcode {index} to {outputPath}"); index++; } + + Console.WriteLine("Barcode generation completed."); + } + + // Simple validation for GS1 Code 128 with AI (01) – ensures 14 digits after the AI + static bool IsValidGs1Code128(string codeText) + { + if (string.IsNullOrEmpty(codeText)) + return false; + + const string prefix = "(01)"; + if (!codeText.StartsWith(prefix)) + return false; + + string digits = codeText.Substring(prefix.Length); + return digits.Length == 14 && long.TryParse(digits, out _); } } \ No newline at end of file diff --git a/gs1-barcode-types/batch-process-folder-of-ai-strings-generating-gs1-datamatrix-barcodes-and-storing-them-in-zip-archive.cs b/gs1-barcode-types/batch-process-folder-of-ai-strings-generating-gs1-datamatrix-barcodes-and-storing-them-in-zip-archive.cs index 0c0e3ab..a2e6156 100644 --- a/gs1-barcode-types/batch-process-folder-of-ai-strings-generating-gs1-datamatrix-barcodes-and-storing-them-in-zip-archive.cs +++ b/gs1-barcode-types/batch-process-folder-of-ai-strings-generating-gs1-datamatrix-barcodes-and-storing-them-in-zip-archive.cs @@ -1,116 +1,97 @@ -// Title: Batch generate GS1 DataMatrix barcodes from AI strings and zip them -// Description: Reads AI strings from text files, creates GS1 DataMatrix barcodes, and stores the PNG images in a ZIP archive. -// Category-Description: This example belongs to the Aspose.BarCode generation category, demonstrating how to use BarcodeGenerator with EncodeTypes.GS1DataMatrix for batch processing. It shows typical steps such as reading input data, configuring barcode parameters, rendering images, and packaging results into a ZIP file—common tasks for developers automating barcode creation workflows. +// Title: Generate GS1 DataMatrix barcodes from AI strings in batch and zip them +// Description: This example reads AI (Application Identifier) strings from text files, creates GS1 DataMatrix barcodes for each, and stores the PNG images in a ZIP archive. +// Category-Description: Demonstrates batch barcode generation using Aspose.BarCode. It covers reading input files, using BarcodeGenerator with EncodeTypes.GS1DataMatrix, configuring colors, saving images to streams, and packaging results with System.IO.Compression. Ideal for developers needing to automate barcode creation for inventory, shipping, or compliance scenarios. // Prompt: Batch process a folder of AI strings, generating GS1 DataMatrix barcodes and storing them in a ZIP archive. -// Tags: gs1, datamatrix, barcode, generation, batch processing, zip, png, aspose.barcode, aspose.barcode.generation +// Tags: gs1, datamatrix, barcode, generation, batch processing, zip, output, aspose.barcode, aspose.drawing using System; using System.IO; using System.IO.Compression; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing.Imaging; /// -/// Demonstrates batch processing of AI strings to generate GS1 DataMatrix barcodes -/// and archive the resulting PNG images into a ZIP file. +/// Demonstrates batch creation of GS1 DataMatrix barcodes from AI strings and packaging them into a ZIP file. /// class Program { /// - /// Entry point of the example. Accepts optional command‑line arguments for the input folder - /// and output ZIP file path, then performs the barcode generation and archiving workflow. + /// Entry point. Reads AI strings from text files, generates barcodes, and writes PNG images into a ZIP archive. /// - /// - /// args[0] – input folder containing AI string files (default: "InputAIs"). - /// args[1] – output ZIP file path (default: "Barcodes.zip"). - /// + /// Optional command‑line argument specifying the input folder path. static void Main(string[] args) { - // Determine input folder; fall back to default if not supplied. - string inputFolder = args.Length > 0 ? args[0] : "InputAIs"; - - // Determine output ZIP file path; fall back to default if not supplied. - string outputZipPath = args.Length > 1 ? args[1] : "Barcodes.zip"; - - // Ensure the input folder exists; if missing, create sample AI files for demonstration. + // Determine input folder (argument or default) + string inputFolder = args.Length > 0 ? args[0] : "InputAIStrings"; if (!Directory.Exists(inputFolder)) { Directory.CreateDirectory(inputFolder); + } - // Sample GS1 AI strings (must be wrapped in parentheses). - string[] sampleAIs = new string[] + // Seed sample AI strings if folder is empty (rule 110) + string[] txtFiles = Directory.GetFiles(inputFolder, "*.txt"); + if (txtFiles.Length == 0) + { + string[] sampleAi = new[] { - "(01)01234567890123", - "(01)09876543210987", - "(01)12345678901234", - "(01)56789012345678", - "(01)00011122233344" + "(01)00123456789012", // GTIN-14 + "(01)01234567890128", // GTIN-14 with valid check digit + "(01)00012345678905", // GTIN-14 + "(01)00001234567890", // GTIN-14 + "(01)00000123456789" // GTIN-14 }; - - // Write each sample AI string to a separate text file. - for (int i = 0; i < sampleAIs.Length; i++) + for (int i = 0; i < sampleAi.Length; i++) { string filePath = Path.Combine(inputFolder, $"Sample{i + 1}.txt"); - File.WriteAllText(filePath, sampleAIs[i]); + File.WriteAllText(filePath, sampleAi[i]); } + txtFiles = Directory.GetFiles(inputFolder, "*.txt"); } - // Retrieve all files (any extension) from the input folder. - string[] files = Directory.GetFiles(inputFolder); - if (files.Length == 0) + // Prepare output ZIP file + string outputZipPath = "GS1DataMatrixBarcodes.zip"; + using (var zipStream = new FileStream(outputZipPath, FileMode.Create)) + using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Create, leaveOpen: true)) { - Console.WriteLine("No AI files found in the input folder."); - return; - } - - // Create the ZIP archive that will hold the generated barcode images. - using (FileStream zipToCreate = new FileStream(outputZipPath, FileMode.Create)) - using (ZipArchive archive = new ZipArchive(zipToCreate, ZipArchiveMode.Create)) - { - // Process each file individually. - foreach (string file in files) + // Process each AI string file + foreach (string txtFile in txtFiles) { - // Read the AI string from the file and trim any surrounding whitespace. - string aiString = File.ReadAllText(file).Trim(); - - // Skip empty files and continue with the next iteration. + // Read AI string (trim whitespace) + string aiString = File.ReadAllText(txtFile).Trim(); if (string.IsNullOrEmpty(aiString)) { - Console.WriteLine($"Skipping empty file: {Path.GetFileName(file)}"); + Console.WriteLine($"Skipping empty file: {txtFile}"); continue; } - // Initialize the barcode generator for GS1 DataMatrix using the AI string. - using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, aiString)) + // Generate GS1 DataMatrix barcode + using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, aiString)) { - // Set a reasonable X-dimension (pixel size) for better readability. - generator.Parameters.Barcode.XDimension.Pixels = 3f; + // Optional: set colors or dimensions if needed + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Enable automatic sizing using interpolation mode. - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; - - // Render the barcode to a memory stream in PNG format. - using (MemoryStream imageStream = new MemoryStream()) + // Save barcode image to memory stream + using (var ms = new MemoryStream()) { - generator.Save(imageStream, BarCodeImageFormat.Png); - imageStream.Position = 0; // Reset stream position for copying. - - // Create a ZIP entry named after the source file but with a .png extension. - string entryName = Path.GetFileNameWithoutExtension(file) + ".png"; - ZipArchiveEntry entry = archive.CreateEntry(entryName, CompressionLevel.Optimal); + generator.Save(ms, BarCodeImageFormat.Png); + ms.Position = 0; - // Copy the PNG data into the ZIP entry. - using (Stream entryStream = entry.Open()) + // Add image to ZIP with same base name but .png extension + string entryName = Path.GetFileNameWithoutExtension(txtFile) + ".png"; + var entry = archive.CreateEntry(entryName, CompressionLevel.Optimal); + using (var entryStream = entry.Open()) { - imageStream.CopyTo(entryStream); + ms.CopyTo(entryStream); } } } - Console.WriteLine($"Processed: {Path.GetFileName(file)}"); + Console.WriteLine($"Processed: {Path.GetFileName(txtFile)}"); } } - Console.WriteLine($"All barcodes have been saved to '{outputZipPath}'."); + Console.WriteLine($"All barcodes have been saved to {outputZipPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/configure-barcode-generator-for-high-resolution-300-dpi-and-produce-tiff-images-for-printing.cs b/gs1-barcode-types/configure-barcode-generator-for-high-resolution-300-dpi-and-produce-tiff-images-for-printing.cs index e257579..8780c86 100644 --- a/gs1-barcode-types/configure-barcode-generator-for-high-resolution-300-dpi-and-produce-tiff-images-for-printing.cs +++ b/gs1-barcode-types/configure-barcode-generator-for-high-resolution-300-dpi-and-produce-tiff-images-for-printing.cs @@ -1,38 +1,43 @@ -// Title: High‑Resolution Barcode Generation and TIFF Export -// Description: Demonstrates configuring Aspose.BarCode to generate a Code128 barcode at 300 DPI and save it as a TIFF image suitable for printing. -// Category-Description: This example belongs to the Aspose.BarCode image generation category, illustrating how to set resolution and output format using the BarcodeGenerator class. Developers often need to produce high‑quality printable barcodes, adjust DPI, and export to formats like TIFF for integration into print workflows. +// Title: Generate High‑Resolution Code128 Barcode and Save as TIFF +// Description: Demonstrates configuring Aspose.BarCode to generate a Code128 barcode at 300 DPI and saving it as a TIFF image suitable for printing. +// Category-Description: This example belongs to the Aspose.BarCode image generation category, illustrating how to set resolution, colors, and output format using BarcodeGenerator, EncodeTypes, and BarCodeImageFormat. Developers often need to create high‑resolution barcodes for print media, requiring precise DPI settings and lossless image formats like TIFF. // Prompt: Configure the barcode generator for high resolution (300 DPI) and produce TIFF images for printing. -// Tags: barcode, code128, high resolution, tiff, generation, aspose.barcode, resolution, image format +// Tags: code128, barcode generation, high resolution, tiff, aspose.barcode, image output using System; -using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing; +using Aspose.Drawing.Imaging; /// -/// Example program that creates a high‑resolution Code128 barcode and saves it as a TIFF image. +/// Example program that creates a high‑resolution Code128 barcode and saves it as a TIFF file. /// class Program { /// - /// Entry point of the application. Generates the barcode and writes it to disk. + /// Entry point. Generates a barcode with 300 DPI resolution and writes it to disk. /// static void Main() { - // Define the barcode content and output file name + // Define the data to encode in the barcode. const string codeText = "1234567890"; - const string outputFile = "barcode.tiff"; - // Initialize the barcode generator with Code128 symbology + // Initialize the barcode generator for Code128 symbology. using (var generator = new BarcodeGenerator(EncodeTypes.Code128, codeText)) { - // Configure the generator for printing quality (300 DPI) + // Configure the generator to use a high printing resolution (300 DPI). generator.Parameters.Resolution = 300f; - // Export the barcode as a TIFF image - generator.Save(outputFile, BarCodeImageFormat.Tiff); - } + // Set barcode and background colors appropriate for print. + generator.Parameters.Barcode.BarColor = Color.Black; + generator.Parameters.BackColor = Color.White; + + // Define the output file path and format (TIFF for lossless printing). + const string outputPath = "barcode.tif"; + generator.Save(outputPath, BarCodeImageFormat.Tiff); - // Inform the user that the file has been created - Console.WriteLine($"Barcode saved to {outputFile}"); + // Inform the user where the file was saved. + Console.WriteLine($"Barcode saved to {outputPath} at 300 DPI."); + } } } \ No newline at end of file diff --git a/gs1-barcode-types/configure-barcode-generator-to-disable-quiet-zone-generate-gs1-datamatrix-and-save-as-png.cs b/gs1-barcode-types/configure-barcode-generator-to-disable-quiet-zone-generate-gs1-datamatrix-and-save-as-png.cs index aeb4995..11f0bf6 100644 --- a/gs1-barcode-types/configure-barcode-generator-to-disable-quiet-zone-generate-gs1-datamatrix-and-save-as-png.cs +++ b/gs1-barcode-types/configure-barcode-generator-to-disable-quiet-zone-generate-gs1-datamatrix-and-save-as-png.cs @@ -1,34 +1,40 @@ // Title: Generate GS1 DataMatrix barcode without quiet zone and save as PNG -// Description: Demonstrates configuring Aspose.BarCode to generate a GS1 DataMatrix barcode, attempts to disable the quiet zone, and saves the result as a PNG image. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on symbology configuration and image output. It showcases the use of BarcodeGenerator, EncodeTypes, and image saving methods, which developers commonly employ when creating DataMatrix or GS1 DataMatrix barcodes for inventory, shipping, or retail labeling. +// Description: Demonstrates how to create a GS1 DataMatrix barcode using Aspose.BarCode, configure resolution, and save the image as PNG. The quiet zone remains at its default because the GS1 DataMatrix standard mandates its presence. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, showcasing the use of EncodeTypes, BarcodeGenerator, and generator parameters. Typical use cases include creating GS1-compliant DataMatrix symbols for product identification, inventory tracking, and packaging. Developers often need to adjust resolution, format, and other settings while adhering to symbology standards. // Prompt: Configure the barcode generator to disable the quiet zone, generate a GS1 DataMatrix, and save as PNG. -// Tags: gs1datamatrix, barcode, generation, quietzone, png, aspnet, aspnetcore, aspose.barcode +// Tags: gs1, datamatrix, barcode, generation, png, aspose.barcode, encode types using System; -using Aspose.BarCode.Generation; using Aspose.BarCode; +using Aspose.BarCode.Generation; /// -/// Example program that generates a GS1 DataMatrix barcode, attempts to disable the quiet zone, -/// and saves the barcode image as a PNG file. +/// Demonstrates generation of a GS1 DataMatrix barcode and saving it as a PNG file. /// class Program { /// - /// Entry point of the application. + /// Entry point of the example. /// static void Main() { - // Define the GS1 DataMatrix code text (Application Identifier 01 - GTIN). - string codeText = "(01)12345678901231"; + // Define the GS1 DataMatrix payload (GTIN‑14 in AI (01)) + string codeText = "(01)00123456789012"; - // Initialize the barcode generator for GS1 DataMatrix. - // Note: For DataMatrix and GS1 DataMatrix the quiet zone is mandated by the standard - // and cannot be disabled, so we do not attempt to modify it. + // Initialize the barcode generator for GS1 DataMatrix with the specified text using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Save the generated barcode as a PNG image file. + // The quiet zone cannot be disabled for DataMatrix/GS1DataMatrix symbols + // because the standard requires its presence. No quiet‑zone configuration is applied. + + // Optionally increase the image resolution (e.g., 300 DPI) for higher quality output + generator.Parameters.Resolution = 300; // DPI + + // Save the generated barcode as a PNG image file generator.Save("gs1datamatrix.png"); } + + // Inform the user that the barcode has been generated + Console.WriteLine("GS1 DataMatrix barcode generated: gs1datamatrix.png"); } } \ No newline at end of file diff --git a/gs1-barcode-types/create-gs1-code-128-barcode-apply-custom-font-for-human-readable-text-and-save-as-png.cs b/gs1-barcode-types/create-gs1-code-128-barcode-apply-custom-font-for-human-readable-text-and-save-as-png.cs index ac4ebbc..79c28ba 100644 --- a/gs1-barcode-types/create-gs1-code-128-barcode-apply-custom-font-for-human-readable-text-and-save-as-png.cs +++ b/gs1-barcode-types/create-gs1-code-128-barcode-apply-custom-font-for-human-readable-text-and-save-as-png.cs @@ -1,39 +1,45 @@ -// Title: Generate GS1 Code 128 Barcode with Custom Font -// Description: Demonstrates creating a GS1 Code 128 barcode, customizing the human‑readable text font, and saving the result as a PNG image. -// Category-Description: This example belongs to the Aspose.BarCode generation category, showcasing how to use the BarcodeGenerator class with EncodeTypes.GS1Code128. Typical use cases include adding GS1-compliant barcodes to product packaging, applying branding through custom fonts for human‑readable text, and exporting the barcode to common image formats. Developers often need to adjust text appearance, alignment, and output settings when integrating barcodes into UI or print workflows. +// Title: Generate GS1 Code 128 barcode with custom font and save as PNG +// Description: Demonstrates creating a GS1 Code 128 barcode, applying a custom Helvetica font to the human‑readable text, and exporting the result as a PNG image. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating how to configure barcode parameters such as CodeText location, font, and alignment using the BarcodeGenerator class. Typical use cases include producing GS1‑compliant barcodes for retail and logistics, where custom text styling is required. Developers often need to customize human‑readable text appearance while generating barcodes programmatically. // Prompt: Create a GS1 Code 128 barcode, apply a custom font for human‑readable text, and save as PNG. -// Tags: gs1,code128,barcode,generation,font,png,aspose.barcode +// Tags: gs1, code128, barcode, generation, png, font using System; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing; /// -/// Example program that generates a GS1 Code 128 barcode, -/// applies a custom font to the human‑readable text, and saves it as a PNG file. +/// Demonstrates generating a GS1 Code 128 barcode with custom human‑readable text styling and saving it as a PNG file. /// class Program { /// - /// Entry point of the application. + /// Entry point of the example. Generates the barcode and writes a confirmation message to the console. /// static void Main() { - // Initialize the barcode generator with GS1 Code 128 symbology and sample GS1 data. - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, "(01)12345678901231")) + // GS1 Code 128 requires AI (01) with a 14‑digit GTIN. + const string codeText = "(01)12345678901231"; + + // Initialize the barcode generator for GS1 Code 128 with the specified code text. + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) { - // Set a custom font (Arial, 12pt) for the human‑readable text displayed below the barcode. - generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial"; + // Display human‑readable text below the barcode bars. + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; + + // Set a custom font (Helvetica, 12pt) for the human‑readable text. + generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Helvetica"; generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f; - // Align the human‑readable text to the center of the barcode. + // Center the human‑readable text horizontally under the barcode. generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center; - // Save the generated barcode image to a PNG file. + // Save the generated barcode image as a PNG file. generator.Save("gs1code128.png"); } - // Inform the user that the barcode has been created successfully. - Console.WriteLine("GS1 Code 128 barcode generated and saved as gs1code128.png"); + // Output a simple confirmation to the console. + Console.WriteLine("Barcode saved as gs1code128.png"); } } \ No newline at end of file diff --git a/gs1-barcode-types/create-gs1-code-128-barcode-rotate-image-90-degrees-clockwise-and-store-as-bmp.cs b/gs1-barcode-types/create-gs1-code-128-barcode-rotate-image-90-degrees-clockwise-and-store-as-bmp.cs index df332e8..7d2c27e 100644 --- a/gs1-barcode-types/create-gs1-code-128-barcode-rotate-image-90-degrees-clockwise-and-store-as-bmp.cs +++ b/gs1-barcode-types/create-gs1-code-128-barcode-rotate-image-90-degrees-clockwise-and-store-as-bmp.cs @@ -1,27 +1,26 @@ -// Title: Create and rotate a GS1 Code 128 barcode saved as BMP -// Description: Demonstrates generating a GS1 Code 128 barcode, rotating the image 90° clockwise, and saving it in BMP format. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, showcasing how to use the BarcodeGenerator class with EncodeTypes.GS1Code128. It illustrates typical tasks such as setting rotation angles and exporting to bitmap images, which developers often need when integrating barcodes into documents or printing workflows. +// Title: Generate GS1 Code 128 Barcode, Rotate 90°, Save as BMP +// Description: Demonstrates creating a GS1 Code 128 barcode, rotating the image 90 degrees clockwise, and saving it as a BMP file. +// Category-Description: This example is part of the Aspose.BarCode barcode generation collection, showcasing how to use the BarcodeGenerator class with EncodeTypes.GS1Code128 to produce GS1‑compliant barcodes, apply image rotation, and export to bitmap formats. Developers often need to generate GS1 barcodes for product identification, adjust orientation for printing layouts, and save in various image types such as BMP, PNG, or JPEG. // Prompt: Create a GS1 Code 128 barcode, rotate the image 90 degrees clockwise, and store as BMP. -// Tags: gs1, code128, barcode, generation, rotation, bmp, aspose.barcode +// Tags: gs1,code128,barcode,generation,rotation,bmp,aspose.barcode using System; -using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Example program that generates a GS1 Code 128 barcode, rotates it, and saves as BMP. +/// Demonstrates generating a GS1 Code 128 barcode, rotating it, and saving as BMP. /// class Program { /// - /// Entry point of the application. + /// Entry point that creates the barcode, applies rotation, and saves the image. /// static void Main() { - // Define sample GS1 Code 128 data (Application Identifier 01 - GTIN) - const string codeText = "(01)12345678901231"; + // Sample GS1 Code 128 codetext: AI (01) with a 14‑digit GTIN + const string codeText = "(01)00123456789012"; - // Initialize the barcode generator with GS1 Code 128 symbology and the data + // Initialize the barcode generator for GS1 Code 128 with the specified codetext using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) { // Set rotation angle to 90 degrees clockwise diff --git a/gs1-barcode-types/create-gs1-datamatrix-barcode-apply-grayscale-filter-and-save-result-as-tiff-image.cs b/gs1-barcode-types/create-gs1-datamatrix-barcode-apply-grayscale-filter-and-save-result-as-tiff-image.cs index d6048b5..4830cdb 100644 --- a/gs1-barcode-types/create-gs1-datamatrix-barcode-apply-grayscale-filter-and-save-result-as-tiff-image.cs +++ b/gs1-barcode-types/create-gs1-datamatrix-barcode-apply-grayscale-filter-and-save-result-as-tiff-image.cs @@ -1,72 +1,43 @@ -// Title: Create GS1 DataMatrix barcode with grayscale filter and save as TIFF -// Description: Demonstrates generating a GS1 DataMatrix barcode, converting it to grayscale, and saving the result as a TIFF image. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation and image processing category. It showcases the use of BarcodeGenerator for GS1 DataMatrix symbology, Aspose.Drawing for bitmap manipulation, and applying a grayscale ColorMatrix via ImageAttributes. Developers often need to customize barcode appearance, apply filters, and export to various image formats such as TIFF for printing or archival purposes. +// Title: Create GS1 DataMatrix barcode with grayscale filter saved as TIFF +// Description: Demonstrates generating a GS1 DataMatrix barcode, applying black‑on‑white grayscale colors, and exporting it to a TIFF image file. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on symbology configuration and image output. It showcases the use of BarcodeGenerator, EncodeTypes, and BarCodeImageFormat classes to create GS1 DataMatrix barcodes, set visual properties such as bar and background colors, and save the result in a raster format. Developers working with product identification, inventory, or logistics often need to generate GS1 DataMatrix codes and customize their appearance for printing or digital use. // Prompt: Create a GS1 DataMatrix barcode, apply a grayscale filter, and save the result as a TIFF image. -// Tags: gs1datamatrix, barcode, grayscale, tiff, imageprocessing, aspose.barcode, aspose.drawing +// Tags: gs1datamatrix, barcode, generation, grayscale, tiff, aspose.barcode, encode types, image format using System; using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.Drawing; -using Aspose.Drawing.Imaging; /// -/// Program demonstrating GS1 DataMatrix barcode generation, grayscale conversion, and TIFF output. +/// Demonstrates generating a GS1 DataMatrix barcode with grayscale colors and saving it as a TIFF image. /// class Program { /// - /// Entry point. Generates the barcode, applies grayscale filter, and saves as TIFF. + /// Entry point of the example. Generates the barcode and writes the output file path to the console. /// static void Main() { - // Define the output file path for the TIFF image - string outputPath = "gs1datamatrix.tiff"; + // Define the output file name + string outputPath = "gs1_datamatrix.tiff"; - // Initialize a barcode generator for GS1 DataMatrix with sample GS1 data - using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, "(01)12345678901231")) - { - // Generate the barcode as a bitmap image - using (Bitmap originalBitmap = generator.GenerateBarCodeImage()) - { - // Create a new bitmap to hold the grayscale version - using (Bitmap grayBitmap = new Bitmap(originalBitmap.Width, originalBitmap.Height)) - { - // Obtain a graphics object for drawing onto the grayscale bitmap - using (Graphics graphics = Graphics.FromImage(grayBitmap)) - { - // Define a grayscale color matrix (luminosity method) - var grayMatrix = new ColorMatrix(new float[][] - { - new float[] { 0.3f, 0.3f, 0.3f, 0, 0 }, - new float[] { 0.59f, 0.59f, 0.59f, 0, 0 }, - new float[] { 0.11f, 0.11f, 0.11f, 0, 0 }, - new float[] { 0, 0, 0, 1, 0 }, - new float[] { 0, 0, 0, 0, 1 } - }); + // GS1 DataMatrix requires an Application Identifier (AI) (01) followed by a 14‑digit GTIN + string gs1CodeText = "(01)00123456789012"; - // Apply the grayscale matrix using ImageAttributes - using (ImageAttributes attributes = new ImageAttributes()) - { - attributes.SetColorMatrix(grayMatrix); - // Draw the original bitmap onto the grayscale bitmap using the color matrix - graphics.DrawImage( - originalBitmap, - new Rectangle(0, 0, originalBitmap.Width, originalBitmap.Height), - 0, 0, originalBitmap.Width, originalBitmap.Height, - GraphicsUnit.Pixel, - attributes); - } - } + // Initialize the barcode generator for GS1 DataMatrix symbology + using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, gs1CodeText)) + { + // Configure the barcode to use black bars on a white background (grayscale) + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Save the resulting grayscale bitmap as a TIFF file - grayBitmap.Save(outputPath, ImageFormat.Tiff); - } - } + // Save the generated barcode as a TIFF image + generator.Save(outputPath, BarCodeImageFormat.Tiff); } - // Output the full path of the saved barcode image + // Output the full path of the saved image for verification Console.WriteLine($"Barcode saved to {Path.GetFullPath(outputPath)}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/create-gs1-datamatrix-barcode-set-background-transparency-and-export-as-png-with-alpha-channel.cs b/gs1-barcode-types/create-gs1-datamatrix-barcode-set-background-transparency-and-export-as-png-with-alpha-channel.cs index bc5502e..d8bd9d6 100644 --- a/gs1-barcode-types/create-gs1-datamatrix-barcode-set-background-transparency-and-export-as-png-with-alpha-channel.cs +++ b/gs1-barcode-types/create-gs1-datamatrix-barcode-set-background-transparency-and-export-as-png-with-alpha-channel.cs @@ -1,8 +1,8 @@ -// Title: Create GS1 DataMatrix barcode with transparent background and PNG output -// Description: Demonstrates generating a GS1 DataMatrix barcode, applying a fully transparent background, and saving it as a PNG that retains the alpha channel. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on GS1 DataMatrix symbology. It showcases the use of BarcodeGenerator, EncodeTypes, and drawing parameters to control visual appearance, a common requirement when integrating barcodes into UI designs that need transparent backgrounds. +// Title: Generate GS1 DataMatrix barcode with transparent background and PNG output +// Description: Demonstrates creating a GS1 DataMatrix barcode, applying a transparent background, and saving it as a PNG file that includes an alpha channel. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on GS1 DataMatrix symbology. It shows how to configure barcode appearance using the BarcodeGenerator class, set background colors with Aspose.Drawing, and export images in formats that support transparency such as PNG. Developers working with product identification, inventory, or logistics often need to generate GS1 DataMatrix codes and embed them in graphics with transparent backgrounds for seamless UI integration. // Prompt: Create a GS1 DataMatrix barcode, set background transparency, and export as PNG with an alpha channel. -// Tags: gs1 datamatrix, background transparency, png, aspose.barcode, barcode generation +// Tags: gs1datamatrix, barcode generation, transparent background, png, alpha channel, aspose.barcode, aspose.drawing using System; using Aspose.BarCode; @@ -10,26 +10,29 @@ using Aspose.Drawing; /// -/// Demonstrates creating a GS1 DataMatrix barcode with a transparent background and exporting it as a PNG image. +/// Demonstrates generating a GS1 DataMatrix barcode with a transparent background and saving it as a PNG image. /// class Program { /// - /// Entry point of the example. Generates the barcode, sets transparency, and saves the image. + /// Entry point. Generates the barcode, applies transparency, and writes the output file. /// static void Main() { - // Define the GS1 DataMatrix code text (Application Identifier (01) for GTIN) - string codeText = "(01)01234567890123"; + // Define the GS1 DataMatrix code text (AI 01 with a 14‑digit GTIN) + string codeText = "(01)00123456789012"; - // Initialize the barcode generator for GS1 DataMatrix with the specified text + // Initialize the barcode generator for GS1 DataMatrix using the specified text using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Configure the background color to be fully transparent (alpha = 0) - generator.Parameters.BackColor = Color.FromArgb(0, 255, 255, 255); + // Configure the background to be transparent so the saved PNG contains an alpha channel + generator.Parameters.BackColor = Aspose.Drawing.Color.Transparent; - // Save the barcode as a PNG file; the alpha channel preserves transparency - generator.Save("gs1_datamatrix.png"); + // Save the generated barcode as a PNG file (PNG supports alpha transparency) + generator.Save("gs1datamatrix.png"); } + + // Inform the user that the barcode image has been created + Console.WriteLine("GS1 DataMatrix barcode generated: gs1datamatrix.png"); } } \ No newline at end of file diff --git a/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-square-shape-and-export-as-high-resolution-tiff-for-printing.cs b/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-square-shape-and-export-as-high-resolution-tiff-for-printing.cs index c04e3a8..06052b8 100644 --- a/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-square-shape-and-export-as-high-resolution-tiff-for-printing.cs +++ b/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-square-shape-and-export-as-high-resolution-tiff-for-printing.cs @@ -1,47 +1,49 @@ -// Title: Generate GS1 DataMatrix Barcode and Export as High‑Resolution TIFF -// Description: Demonstrates creating a GS1 DataMatrix barcode with a square shape and saving it as a 300 DPI TIFF image for printing. -// Category-Description: This example belongs to the Aspose.BarCode generation category, focusing on DataMatrix symbology. It showcases the use of BarcodeGenerator, EncodeTypes, and DataMatrixVersion classes to produce print‑ready barcodes. Developers often need to control barcode dimensions, resolution, and output format for high‑quality print media, making this a typical use case for Aspose.BarCode. +// Title: Generate GS1 DataMatrix barcode and save as high‑resolution TIFF +// Description: Demonstrates creating a GS1 DataMatrix barcode with a 14‑digit GTIN, forcing a square shape, and exporting it as a 300 dpi TIFF image suitable for printing. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating how to configure barcode parameters such as resolution, shape, and colors using the BarcodeGenerator class. Typical use cases include producing machine‑readable GS1 DataMatrix symbols for packaging and printing high‑quality images with Aspose.Drawing.Imaging. Developers often need to customize DataMatrix versions, set DPI, and export to formats like TIFF for print workflows. // Prompt: Create a GS1 DataMatrix barcode, specify square shape, and export as high‑resolution TIFF for printing. -// Tags: gs1, datamatrix, barcode, generation, tiff, high-resolution, printing, aspose.barcode, aspose.drawing +// Tags: gs1 datamatrix, barcode generation, tiff, high resolution, aspose.barcodes, aspose.drawing using System; using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.Drawing; +using Aspose.Drawing.Imaging; /// -/// Example program that generates a GS1 DataMatrix barcode, -/// configures it as a square symbol, and saves it as a high‑resolution TIFF file. +/// Example program that generates a GS1 DataMatrix barcode and saves it as a high‑resolution TIFF image. /// class Program { /// - /// Entry point of the example. Creates the barcode, sets printing‑ready parameters, - /// and writes the result to disk. + /// Entry point of the application. /// static void Main() { - // Sample GS1 DataMatrix code text (Application Identifier 01 and 10) - string codeText = "(01)12345678901231(10)ABC123"; + // Define the output file path for the generated TIFF image. + string outputPath = "gs1_datamatrix.tif"; - // Initialize the barcode generator for GS1 DataMatrix with the provided text + // GS1 DataMatrix requires a 14‑digit GTIN wrapped in the (01) Application Identifier. + string codeText = "(01)00123456789012"; + + // Initialize the barcode generator for the GS1 DataMatrix symbology with the specified code text. using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Set high resolution (300 DPI) suitable for printing + // Set a high resolution (e.g., 300 dpi) for print‑quality output. generator.Parameters.Resolution = 300f; - // Configure DataMatrix to be square by selecting a square ECC200 version - generator.Parameters.Barcode.DataMatrix.DataMatrixVersion = DataMatrixVersion.ECC200_20x20; - generator.Parameters.Barcode.DataMatrix.AspectRatio = 1f; + // Force a square shape by selecting a specific DataMatrix version (32 × 32 modules). + generator.Parameters.Barcode.DataMatrix.Version = DataMatrixVersion.ECC200_32x32; - // Optional: define foreground (barcode) and background colors + // Optional: define foreground (barcode) and background colors. generator.Parameters.Barcode.BarColor = Color.Black; generator.Parameters.BackColor = Color.White; - // Save the barcode as a high‑resolution TIFF image - generator.Save("gs1_datamatrix.tiff"); + // Save the generated barcode as a TIFF image using the specified resolution. + generator.Save(outputPath, BarCodeImageFormat.Tiff); } - Console.WriteLine("GS1 DataMatrix barcode generated successfully."); + // Inform the user that the barcode image has been saved. + Console.WriteLine($"GS1 DataMatrix barcode saved to {outputPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-utf-8-encoding-mode-and-export-to-jpeg-with-quality-90.cs b/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-utf-8-encoding-mode-and-export-to-jpeg-with-quality-90.cs index 98f82bf..e2d3d4c 100644 --- a/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-utf-8-encoding-mode-and-export-to-jpeg-with-quality-90.cs +++ b/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-utf-8-encoding-mode-and-export-to-jpeg-with-quality-90.cs @@ -1,41 +1,40 @@ -// Title: Generate GS1 DataMatrix barcode and save as JPEG with UTF‑8 encoding -// Description: Demonstrates creating a GS1 DataMatrix barcode, setting UTF‑8 ECI encoding, and exporting it to a JPEG image. -// Category-Description: This example is part of the Aspose.BarCode generation collection, showing how to configure a specific symbology (GS1 DataMatrix), apply character set encoding (UTF‑8 via ECI), and output the result as a high‑quality JPEG. It utilizes the BarcodeGenerator, EncodeTypes, and BarCodeImageFormat classes—common tools for developers who need to produce product identification codes and integrate them into imaging workflows. +// Title: Generate GS1 DataMatrix Barcode and Save as JPEG +// Description: Demonstrates creating a GS1 DataMatrix barcode with UTF‑8 encoding and exporting it to a JPEG file. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating how to configure DataMatrix encoding options such as GS1 mode and ECI UTF‑8, and how to save the generated barcode as an image file. Developers working with product identification, inventory, or logistics often need to produce GS1 DataMatrix symbols for GTINs and other application identifiers, using classes like BarcodeGenerator, EncodeTypes, and DataMatrixEncodeMode. // Prompt: Create a GS1 DataMatrix barcode, specify UTF‑8 encoding mode, and export to JPEG with quality 90. -// Tags: gs1datamatrix, barcode, generation, jpeg, eci, utf-8, aspose.barcode, encodetypes, imageexport +// Tags: gs1, datamatrix, barcode, generation, utf-8, jpeg, aspose.barcode, aspose.drawing using System; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing.Imaging; /// -/// Example program that generates a GS1 DataMatrix barcode, -/// applies UTF‑8 ECI encoding, and saves it as a JPEG image. +/// Demonstrates creating a GS1 DataMatrix barcode with UTF‑8 encoding and saving it as a JPEG image. /// class Program { /// - /// Entry point of the example. Creates the barcode and writes the image file. + /// Entry point that generates the barcode and writes it to disk. /// static void Main() { - // Output file name for the generated JPEG image - const string outputPath = "gs1datamatrix.jpg"; + // Define the GS1 DataMatrix payload: Application Identifier (01) followed by a 14‑digit GTIN. + string codeText = "(01)00123456789012"; - // GS1 DataMatrix payload (Application Identifier 01 with a 14‑digit GTIN) - const string codeText = "(01)12345678901231"; - - // Initialize the barcode generator for GS1 DataMatrix symbology - using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix)) + // Initialize the barcode generator for GS1 DataMatrix with the specified text. + using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Assign the code text to be encoded - generator.CodeText = codeText; - - // Set the ECI (Extended Channel Interpretation) to UTF‑8 for proper character encoding + // Configure the DataMatrix to use ECI encoding mode with UTF‑8 for proper Unicode support. + generator.Parameters.Barcode.DataMatrix.EncodeMode = DataMatrixEncodeMode.ECI; generator.Parameters.Barcode.DataMatrix.ECIEncoding = ECIEncodings.UTF8; - // Save the barcode as a JPEG image (default quality; Aspose uses 90 if not specified) - generator.Save(outputPath, BarCodeImageFormat.Jpeg); + // Save the generated barcode as a JPEG image. + // Note: Aspose.BarCode uses the default JPEG quality; a specific quality setting is not exposed. + generator.Save("gs1_datamatrix.jpg"); } + + // Inform the user that the file has been created. + Console.WriteLine("GS1 DataMatrix barcode saved as gs1_datamatrix.jpg"); } } \ No newline at end of file diff --git a/gs1-barcode-types/create-gs1-datamatrix-barcode-using-multiple-application-identifiers-and-export-to-jpeg-format.cs b/gs1-barcode-types/create-gs1-datamatrix-barcode-using-multiple-application-identifiers-and-export-to-jpeg-format.cs index c33555d..93bcf65 100644 --- a/gs1-barcode-types/create-gs1-datamatrix-barcode-using-multiple-application-identifiers-and-export-to-jpeg-format.cs +++ b/gs1-barcode-types/create-gs1-datamatrix-barcode-using-multiple-application-identifiers-and-export-to-jpeg-format.cs @@ -1,39 +1,46 @@ -// Title: Generate GS1 DataMatrix Barcode with Multiple Application Identifiers and Save as JPEG -// Description: Demonstrates creating a GS1 DataMatrix barcode that encodes several Application Identifiers (GTIN, batch number, expiration date) and exporting the image to JPEG. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use the BarcodeGenerator class with EncodeTypes.GS1DataMatrix. Developers often need to embed GS1 data in DataMatrix symbols for supply‑chain labeling, requiring multiple Application Identifiers. The snippet shows typical steps: define GS1‑formatted text, instantiate the generator, and save the result in a common image format. +// Title: Generate GS1 DataMatrix barcode with multiple Application Identifiers and save as JPEG +// Description: Demonstrates creating a GS1 DataMatrix barcode that encodes several Application Identifiers and exporting the image to JPEG format. +// Category-Description: This example belongs to the Aspose.BarCode generation category, showcasing how to use the BarcodeGenerator class with EncodeTypes.GS1DataMatrix. It illustrates typical use cases such as encoding GS1 Application Identifiers, customizing barcode appearance, and saving the result in common image formats. Developers working with product identification, inventory tracking, or logistics often need to generate GS1 DataMatrix symbols programmatically. // Prompt: Create a GS1 DataMatrix barcode using multiple Application Identifiers and export to a JPEG format. -// Tags: gs1, datamatrix, barcode, generation, jpeg, aspose.barcode +// Tags: gs1 datamatrix, barcode generation, jpeg, aspose.barcodes, aspose.drawing using System; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing; /// -/// Example program that creates a GS1 DataMatrix barcode containing several Application Identifiers -/// and saves the generated image as a JPEG file. +/// Example program that generates a GS1 DataMatrix barcode with multiple Application Identifiers and saves it as a JPEG image. /// class Program { /// - /// Entry point of the example. Generates the barcode and writes the output file path to the console. + /// Entry point that creates the barcode, configures appearance, and writes the JPEG file. /// static void Main() { - // Define GS1 DataMatrix code text with multiple Application Identifiers (AIs): - // (01) – GTIN, (10) – Batch/Lot number, (17) – Expiration date (YYMMDD) - string codeText = "(01)12345678901231(10)ABC123(17)240731"; - - // Specify the output file path for the JPEG image + // Define the output file path for the generated JPEG image. string outputPath = "gs1_datamatrix.jpg"; - // Create the barcode generator for GS1 DataMatrix using the defined code text + // GS1 DataMatrix code text containing multiple Application Identifiers: + // (01) – GTIN-14, (10) – Batch/Lot, (21) – Serial Number. + string codeText = "(01)01234567890128(10)BATCH123(21)SN001"; + + // Initialize the barcode generator for GS1 DataMatrix with the specified code text. using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Save the generated barcode image as a JPEG file + // Adjust the module (X) dimension to control barcode size (optional). + generator.Parameters.Barcode.XDimension.Point = 2f; + + // Set the barcode foreground (bars) and background colors (optional). + generator.Parameters.Barcode.BarColor = Color.Black; + generator.Parameters.BackColor = Color.White; + + // Save the generated barcode image to the specified path in JPEG format. generator.Save(outputPath, BarCodeImageFormat.Jpeg); } - // Inform the user where the barcode image has been saved - Console.WriteLine($"GS1 DataMatrix barcode saved to: {outputPath}"); + // Inform the user that the barcode has been saved. + Console.WriteLine($"GS1 DataMatrix barcode saved to {outputPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/create-upc-barcode-with-databar-coupon-then-overlay-qr-code-using-graphics-library.cs b/gs1-barcode-types/create-upc-barcode-with-databar-coupon-then-overlay-qr-code-using-graphics-library.cs index cd80b78..30f231b 100644 --- a/gs1-barcode-types/create-upc-barcode-with-databar-coupon-then-overlay-qr-code-using-graphics-library.cs +++ b/gs1-barcode-types/create-upc-barcode-with-databar-coupon-then-overlay-qr-code-using-graphics-library.cs @@ -1,8 +1,8 @@ -// Title: Create UPC‑A barcode with DataBar coupon and overlay QR code -// Description: Demonstrates generating a UPC‑A barcode with a GS1 DataBar coupon and then compositing a QR code on top using Aspose.Drawing. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation and image composition category. It shows how to use BarcodeGenerator with EncodeTypes.UpcaGs1DatabarCoupon and EncodeTypes.QR, configure parameters, and combine images via Aspose.Drawing. Developers often need to create composite barcode images for packaging, marketing, or inventory applications, and this snippet illustrates the typical workflow. +// Title: Generate a UPC‑A barcode with a DataBar coupon and overlay a QR code +// Description: Demonstrates creating a UPC‑A barcode that includes a GS1‑128 coupon, then compositing a QR code on top using Aspose.Drawing. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation and image composition category. It shows how to use BarcodeGenerator with EncodeTypes.UpcaGs1Code128Coupon and EncodeTypes.QR, configure visual parameters, render images, and combine them via Aspose.Drawing.Graphics. Developers often need to combine multiple symbologies into a single image for packaging, marketing, or retail applications. // Prompt: Create a UPC‑A barcode with a DataBar coupon, then overlay a QR code using a graphics library. -// Tags: upc barcode, databar coupon, qr code, image overlay, aspose.barcode, aspose.drawing, png output +// Tags: upc-a, databar, coupon, qr, barcode generation, image composition, aspose.barcode, aspose.drawing, png using System; using System.IO; @@ -12,82 +12,69 @@ using Aspose.Drawing.Imaging; /// -/// Demonstrates creating a UPC‑A barcode with a GS1 DataBar coupon and overlaying a QR code. +/// Demonstrates generating a UPC‑A barcode with a GS1‑128 coupon and overlaying a QR code, +/// then saving the combined image as PNG. /// class Program { /// - /// Entry point. Generates the barcode images, composes them, and saves the result. + /// Entry point of the example. Generates the barcodes, composes them, and writes the result to disk. /// static void Main() { - // Define file names for the individual and combined images - string upcFile = "upc_databar.png"; - string combinedFile = "combined.png"; + // Define the output file path for the final combined image. + string outputPath = "combined.png"; - // ----------------------------------------------------------------- - // 1. Create UPC‑A barcode with a GS1 DataBar coupon - // ----------------------------------------------------------------- - // Sample codetext: UPCA part + DataBar part - string upcCodeText = "514141100906(8110)106141416543213500110000310123196000"; + // UPC‑A barcode text that includes a GS1‑128 coupon segment. + string upcCodeText = "514141100906(8102)03"; - using (var upcGenerator = new BarcodeGenerator(EncodeTypes.UpcaGs1DatabarCoupon, upcCodeText)) + // Create a generator for the UPC‑A barcode with a DataBar coupon. + using (var upcGenerator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, upcCodeText)) { - // Optional: set image size (auto‑size mode) - upcGenerator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; - upcGenerator.Parameters.ImageWidth.Point = 400f; - upcGenerator.Parameters.ImageHeight.Point = 200f; + // Set visual appearance for the UPC barcode. + upcGenerator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + upcGenerator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Save the UPC‑A barcode image to file - upcGenerator.Save(upcFile); - } - - // ----------------------------------------------------------------- - // 2. Create a QR code that will be overlaid on the UPC image - // ----------------------------------------------------------------- - string qrCodeText = "https://example.com"; - - using (var qrGenerator = new BarcodeGenerator(EncodeTypes.QR, qrCodeText)) - { - // Set high error correction level for better readability after overlay - qrGenerator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelH; - - // Define QR image size (auto‑size mode) - qrGenerator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; - qrGenerator.Parameters.ImageWidth.Point = 150f; - qrGenerator.Parameters.ImageHeight.Point = 150f; - - // Generate QR bitmap in memory - using (Bitmap qrBitmap = qrGenerator.GenerateBarCodeImage()) + // Render the UPC barcode to a bitmap image. + using (Bitmap upcBitmap = upcGenerator.GenerateBarCodeImage()) { - // ----------------------------------------------------------------- - // 3. Load the UPC image and overlay the QR code onto it - // ----------------------------------------------------------------- - if (!File.Exists(upcFile)) - { - Console.WriteLine($"Error: UPC image file '{upcFile}' not found."); - return; - } + // Text to encode in the QR code that will be overlaid. + string qrText = "https://example.com"; - using (Bitmap upcBitmap = new Bitmap(upcFile)) + // Create a generator for the QR code. + using (var qrGenerator = new BarcodeGenerator(EncodeTypes.QR, qrText)) { - // Determine position: bottom‑right corner with a 10‑pixel margin - int margin = 10; - int x = upcBitmap.Width - qrBitmap.Width - margin; - int y = upcBitmap.Height - qrBitmap.Height - margin; + // Use a high error correction level for better readability after overlay. + qrGenerator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelH; + qrGenerator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + qrGenerator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Draw the QR code onto the UPC image - using (Graphics graphics = Graphics.FromImage(upcBitmap)) + // Render the QR code to a bitmap image. + using (Bitmap qrBitmap = qrGenerator.GenerateBarCodeImage()) { - graphics.DrawImage(qrBitmap, new Rectangle(x, y, qrBitmap.Width, qrBitmap.Height)); - } + // Calculate position for the QR code: bottom‑right corner with a margin. + int margin = 10; + int qrX = upcBitmap.Width - qrBitmap.Width - margin; + int qrY = upcBitmap.Height - qrBitmap.Height - margin; - // Save the combined image to file - upcBitmap.Save(combinedFile, ImageFormat.Png); + // Ensure the QR code does not go outside the UPC image bounds. + if (qrX < 0) qrX = 0; + if (qrY < 0) qrY = 0; + + // Draw the QR bitmap onto the UPC bitmap using graphics. + using (Graphics graphics = Graphics.FromImage(upcBitmap)) + { + graphics.DrawImage(qrBitmap, qrX, qrY, qrBitmap.Width, qrBitmap.Height); + } + + // Save the combined image as a PNG file. + upcBitmap.Save(outputPath, ImageFormat.Png); + } } } } - Console.WriteLine($"Combined barcode image saved as '{combinedFile}'."); + // Inform the user where the combined image was saved. + Console.WriteLine($"Combined barcode saved to {Path.GetFullPath(outputPath)}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-gs1-code-128-barcode-embed-custom-human-readable-text-below-and-save-as-jpeg.cs b/gs1-barcode-types/generate-gs1-code-128-barcode-embed-custom-human-readable-text-below-and-save-as-jpeg.cs index 8946117..af26536 100644 --- a/gs1-barcode-types/generate-gs1-code-128-barcode-embed-custom-human-readable-text-below-and-save-as-jpeg.cs +++ b/gs1-barcode-types/generate-gs1-code-128-barcode-embed-custom-human-readable-text-below-and-save-as-jpeg.cs @@ -1,46 +1,47 @@ // Title: Generate GS1 Code 128 barcode with custom human‑readable text -// Description: Demonstrates creating a GS1 Code 128 barcode, adding centered human‑readable text below, and saving it as a JPEG image. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use BarcodeGenerator with EncodeTypes.GS1Code128, configure CodeTextParameters, and apply AutoSizeMode. Developers often need to produce GS1‑compliant barcodes for product identification, customize human‑readable text appearance, and export to common image formats like JPEG. +// Description: Demonstrates creating a GS1 Code 128 barcode, adding readable text below the bars, and saving the result as a JPEG image. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating how to use the BarcodeGenerator class with EncodeTypes.GS1Code128. Typical use cases include encoding product identifiers (GTIN) for retail, adding human‑readable text for scanning verification, and exporting to common image formats. Developers often need to customize text placement, font, and colors when integrating barcodes into packaging or documents. // Prompt: Generate a GS1 Code 128 barcode, embed custom human‑readable text below, and save as JPEG. -// Tags: gs1, code128, barcode, generation, human‑readable, jpeg, aspose.barcode +// Tags: gs1,code128,barcode,generation,human-readable,text,jpeg,aspose.barcode,aspose.drawing using System; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing; /// -/// Program demonstrating GS1 Code 128 barcode generation with custom human‑readable text. +/// Example program that creates a GS1 Code 128 barcode, +/// places custom human‑readable text below the barcode, +/// and saves the image as a JPEG file. /// class Program { /// - /// Entry point. Generates the barcode, configures text, and saves as JPEG. + /// Entry point of the application. + /// Generates the barcode and writes it to disk. /// static void Main() { - // Define GS1 Code 128 data: (01) – GTIN, (21) – Serial Number - const string gs1Data = "(01)12345678901231(21)ABC123"; + // Define the GS1 Code 128 data. + // GS1 Code 128 requires an Application Identifier (01) with a 14‑digit GTIN. + // Example GTIN: 01234567890123 + string gs1Code = "(01)01234567890123"; - // Initialize the barcode generator for GS1 Code 128 with the specified data - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, gs1Data)) + // Initialize the barcode generator with the GS1 Code 128 symbology and data. + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, gs1Code)) { - // Position human‑readable text below the barcode and center it horizontally + // Position the human‑readable text (the encoded value) below the barcode. generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; - generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center; - // Set the font family and size for the human‑readable text - generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial"; - generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f; + // Optionally adjust the font size of the human‑readable text for better readability. + generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 10f; - // Enable automatic sizing using interpolation (no explicit bar height required) - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; + // Set the colors: black bars on a white background. + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Define output file path and save the barcode as a JPEG image - const string outputPath = "gs1_code128.jpg"; - generator.Save(outputPath, BarCodeImageFormat.Jpeg); + // Save the generated barcode as a JPEG image file. + generator.Save("gs1code128.jpg"); } - - // Inform the user that the barcode has been saved - Console.WriteLine("GS1 Code 128 barcode saved successfully."); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-gs1-code-128-barcode-embed-it-in-pdf-document-and-save-pdf.cs b/gs1-barcode-types/generate-gs1-code-128-barcode-embed-it-in-pdf-document-and-save-pdf.cs index b801a8e..dad3263 100644 --- a/gs1-barcode-types/generate-gs1-code-128-barcode-embed-it-in-pdf-document-and-save-pdf.cs +++ b/gs1-barcode-types/generate-gs1-code-128-barcode-embed-it-in-pdf-document-and-save-pdf.cs @@ -1,17 +1,18 @@ // Title: Generate GS1 Code 128 Barcode and Embed in PDF -// Description: Demonstrates how to create a GS1 Code 128 barcode, place it into a PDF document, and save the result. -// Category-Description: This example belongs to the Aspose.BarCode PDF integration category, showcasing the use of BarcodeGenerator (Aspose.BarCode.Generation) to produce a barcode image and Aspose.Pdf (Document, Image) to embed that image into a PDF. Typical scenarios include generating product labels, shipping documents, or any printable material that requires a GS1-compliant barcode. +// Description: Demonstrates creating a GS1 Code 128 barcode, embedding it into a PDF document, and saving the file. +// Category-Description: This example belongs to the Aspose.BarCode and Aspose.Pdf integration category. It shows how to use the BarcodeGenerator class to produce a GS1 Code 128 symbology image and the Aspose.Pdf Document API to insert the image into a PDF page. Typical use cases include generating product labels, shipping documents, or any scenario where GS1 barcodes must be combined with PDF output. Developers often need to customize barcode appearance, size, and placement within PDF files. // Prompt: Generate a GS1 Code 128 barcode, embed it in a PDF document, and save the PDF. -// Tags: gs1 code 128, barcode generation, pdf output, aspose.barcode, aspose.pdf +// Tags: gs1,code128,barcode,pdf,generation,aspose.barcode,aspose.pdf using System; using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.Pdf; +using Aspose.Pdf.Text; /// -/// Example program that creates a GS1 Code 128 barcode, inserts it into a PDF, and saves the file. +/// Example program that creates a GS1 Code 128 barcode, embeds it into a PDF, and saves the result. /// class Program { @@ -20,33 +21,44 @@ class Program /// static void Main() { - // Define the output PDF file name - const string pdfPath = "GS1Code128.pdf"; + // Define the output PDF file path + const string pdfPath = "barcode.pdf"; - // Initialize a barcode generator for GS1 Code 128 with sample AI code text - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, "(01)12345678901231")) + // GS1 Code 128 requires a GTIN in AI (01) with exactly 14 digits. + // Example GTIN-14 (including check digit) + const string gs1CodeText = "(01)01234567890123"; + + // Generate the barcode image and store it in a memory stream + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, gs1CodeText)) { - // Render the barcode to a memory stream in PNG format + // Optional: set barcode and background colors + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; + using (var barcodeStream = new MemoryStream()) { + // Save the barcode as a PNG image into the stream generator.Save(barcodeStream, BarCodeImageFormat.Png); - // Reset stream position to the beginning for reading - barcodeStream.Position = 0; + barcodeStream.Position = 0; // Reset stream position for reading - // Create a new PDF document + // Create a new PDF document and add a page using (var pdfDoc = new Document()) { - // Add a new page to the PDF var page = pdfDoc.Pages.Add(); - // Create an image object from the barcode stream - var image = new Image + // Create an Image object that reads from the barcode stream + var pdfImage = new Image { - ImageStream = barcodeStream + ImageStream = barcodeStream, + // Set desired size (points). Adjust as needed. + FixWidth = 200, + FixHeight = 100, + HorizontalAlignment = HorizontalAlignment.Center, + Margin = new MarginInfo { Top = 20 } }; - // Insert the barcode image into the page's paragraph collection - page.Paragraphs.Add(image); + // Add the image to the page's paragraph collection + page.Paragraphs.Add(pdfImage); // Save the PDF document to the specified path pdfDoc.Save(pdfPath); @@ -54,7 +66,7 @@ static void Main() } } - // Inform the user that the PDF has been saved - Console.WriteLine($"PDF with GS1 Code 128 barcode saved to '{pdfPath}'."); + // Inform the user where the PDF was saved + Console.WriteLine($"PDF with GS1 Code 128 barcode saved to: {Path.GetFullPath(pdfPath)}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-gs1-code-128-barcode-with-ai-data-and-save-as-png-image-file.cs b/gs1-barcode-types/generate-gs1-code-128-barcode-with-ai-data-and-save-as-png-image-file.cs index a5cf97e..a28c8e2 100644 --- a/gs1-barcode-types/generate-gs1-code-128-barcode-with-ai-data-and-save-as-png-image-file.cs +++ b/gs1-barcode-types/generate-gs1-code-128-barcode-with-ai-data-and-save-as-png-image-file.cs @@ -1,37 +1,41 @@ -// Title: Generate GS1 Code 128 Barcode with AI Data and Save as PNG -// Description: Creates a GS1‑compliant Code 128 barcode containing Application Identifier data and writes it to a PNG file. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, demonstrating how to encode GS1 Application Identifier (AI) data using the BarcodeGenerator and EncodeTypes classes. Developers often need to create GS1‑compliant barcodes for product identification, inventory, and logistics, requiring correct AI formatting and optional checksum display. The snippet shows the essential steps to configure parameters and save the barcode as an image. +// Title: Generate GS1 Code 128 barcode with AI data and save as PNG +// Description: Demonstrates creating a GS1 Code 128 barcode that includes Application Identifiers (AI) for GTIN‑14 and batch/lot number, then saving it as a PNG image. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use the BarcodeGenerator class with EncodeTypes.GS1Code128 to embed AI data in a 1D barcode. Typical use cases include product labeling, inventory tracking, and compliance with GS1 standards. Developers often need to configure visual parameters such as X‑dimension, bar height, and colors before exporting the barcode to common image formats. // Prompt: Generate a GS1 Code 128 barcode with AI data and save as a PNG image file. -// Tags: gs1,code128,barcode,generation,png,aspose.barcode,applicationidentifier +// Tags: gs1, code128, barcode, generation, png, aspose.barcode using System; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing; /// -/// Demonstrates generation of a GS1 Code 128 barcode with AI data and saving it as a PNG image. +/// Example program that generates a GS1 Code 128 barcode containing AI data +/// and saves it as a PNG image file using Aspose.BarCode. /// class Program { /// - /// Entry point of the example. Generates the barcode and writes it to disk. + /// Entry point of the example. Creates the barcode, configures visual settings, + /// and writes the result to "gs1code128.png". /// static void Main() { - // Define GS1 AI data: (01) – GTIN, (21) – Serial number - string codeText = "(01)01234567890123(21)ABC123"; + // Define GS1 data string with Application Identifiers: + // (01) – GTIN‑14, (10) – Batch/Lot number + string codeText = "(01)00123456789012(10)ABC123"; - // Initialize the barcode generator with GS1 Code 128 symbology and the AI data + // Initialize the barcode generator for GS1 Code 128 with the data string using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) { - // Optional: display the checksum in the human‑readable text - generator.Parameters.Barcode.ChecksumAlwaysShow = true; + // Configure visual appearance of the barcode + generator.Parameters.Barcode.XDimension.Point = 2f; // Module (X) size in points + generator.Parameters.Barcode.BarHeight.Point = 100f; // Height of the bars for 1D barcode + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; // Bar color + generator.Parameters.BackColor = Aspose.Drawing.Color.White; // Background color // Save the generated barcode as a PNG image file generator.Save("gs1code128.png"); } - - // Inform the user that the barcode has been saved - Console.WriteLine("GS1 Code 128 barcode saved as gs1code128.png"); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-gs1-datamatrix-barcode-retrieve-its-byte-array-and-send-it-via-http-response.cs b/gs1-barcode-types/generate-gs1-datamatrix-barcode-retrieve-its-byte-array-and-send-it-via-http-response.cs index 68f2151..6a9dd2d 100644 --- a/gs1-barcode-types/generate-gs1-datamatrix-barcode-retrieve-its-byte-array-and-send-it-via-http-response.cs +++ b/gs1-barcode-types/generate-gs1-datamatrix-barcode-retrieve-its-byte-array-and-send-it-via-http-response.cs @@ -1,57 +1,61 @@ -// Title: Generate GS1 DataMatrix Barcode and Retrieve Byte Array -// Description: This example creates a GS1 DataMatrix barcode, extracts its PNG byte array, and demonstrates how it could be sent in an HTTP response. -// Category-Description: Aspose.BarCode barcode generation examples that illustrate creating various symbologies, configuring image parameters, and obtaining raw image data. Developers often need to generate barcodes on the fly for web APIs, embed them in documents, or transmit them over HTTP. This snippet showcases the BarcodeGenerator class, image format handling, and byte array extraction, which are common tasks in e‑commerce, logistics, and inventory systems. +// Title: Generate GS1 DataMatrix barcode and return as HTTP response +// Description: Demonstrates how to create a GS1 DataMatrix barcode, extract its PNG byte array, and embed it in an HTTP response. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, showcasing the use of BarcodeGenerator, EncodeTypes, and BarCodeImageFormat classes. Typical scenarios include creating machine-readable GS1 symbols for product identification and delivering them via web APIs. Developers often need to generate barcode images on the fly and send them directly to clients without persisting to disk. // Prompt: Generate a GS1 DataMatrix barcode, retrieve its byte array, and send it via HTTP response. -// Tags: gs1, datamatrix, barcode, generation, bytearray, http response, aspose.barcode, aspnet +// Tags: gs1, datamatrix, barcode, generation, http, response, bytearray, aspose.barcode using System; using System.IO; -using System.Text; +using System.Net.Http; +using System.Net.Http.Headers; using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.Drawing.Imaging; /// -/// Demonstrates how to generate a GS1 DataMatrix barcode, obtain its PNG byte array, -/// and illustrate the data that would be sent in an HTTP response. +/// Example program that creates a GS1 DataMatrix barcode, converts it to a PNG byte array, +/// and packages it into an HTTP response message. /// class Program { /// - /// Entry point of the console application. - /// Generates the barcode, extracts the byte array, and prints a Base64 representation. + /// Entry point of the application. /// static void Main() { - // NOTE: The snippet runner is a console application and cannot host an HTTP server. - // Therefore, the barcode byte array is generated and printed as a Base64 string, - // which represents the data that would be sent in an HTTP response. + // Define the GS1 DataMatrix payload (AI (01) with a 14‑digit GTIN) + string gs1CodeText = "(01)00123456789012"; - // Define a sample GS1 Application Identifier (AI) payload for the barcode. - const string gs1CodeText = "(01)12345678901231"; - - // Initialize the barcode generator for the GS1 DataMatrix symbology. + // Generate the barcode and capture the PNG image as a byte array + byte[] barcodeBytes; using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, gs1CodeText)) { - // Optional: adjust image dimensions and resolution to meet specific requirements. - generator.Parameters.ImageWidth.Point = 300f; - generator.Parameters.ImageHeight.Point = 300f; - generator.Parameters.Resolution = 96; + // Optional: increase image resolution for higher quality output + generator.Parameters.Resolution = 300; - // Generate the barcode image and write it into a memory stream. using (var ms = new MemoryStream()) { + // Save the barcode image to the memory stream in PNG format generator.Save(ms, BarCodeImageFormat.Png); - byte[] barcodeBytes = ms.ToArray(); // Retrieve the raw PNG byte array. + barcodeBytes = ms.ToArray(); // Extract the byte array from the stream + } + } - // Output the length of the generated byte array for verification. - Console.WriteLine($"Generated barcode byte array length: {barcodeBytes.Length}"); + // Build an HTTP response that carries the barcode image + using (var response = new HttpResponseMessage()) + { + // Attach the PNG byte array as the response content + response.Content = new ByteArrayContent(barcodeBytes); + response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); + response.StatusCode = System.Net.HttpStatusCode.OK; - // Convert the byte array to a Base64 string to simulate an HTTP response body. - string base64 = Convert.ToBase64String(barcodeBytes); - Console.WriteLine("Base64-encoded PNG barcode:"); - Console.WriteLine(base64); - } + // Output response metadata to the console for demonstration purposes + Console.WriteLine("HTTP Response prepared:"); + Console.WriteLine($"Status Code: {response.StatusCode}"); + Console.WriteLine($"Content-Type: {response.Content.Headers.ContentType}"); + Console.WriteLine($"Content Length: {barcodeBytes.Length} bytes"); } + + // End of program } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-gs1-datamatrix-barcode-set-module-size-to-5-pixels-and-export-as-bmp.cs b/gs1-barcode-types/generate-gs1-datamatrix-barcode-set-module-size-to-5-pixels-and-export-as-bmp.cs index 9631dfa..79069f4 100644 --- a/gs1-barcode-types/generate-gs1-datamatrix-barcode-set-module-size-to-5-pixels-and-export-as-bmp.cs +++ b/gs1-barcode-types/generate-gs1-datamatrix-barcode-set-module-size-to-5-pixels-and-export-as-bmp.cs @@ -1,35 +1,35 @@ -// Title: Generate GS1 DataMatrix barcode with custom module size and BMP output -// Description: Demonstrates creating a GS1 DataMatrix barcode, setting its module size to 5 pixels, and saving it as a BMP image. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use the BarcodeGenerator class with EncodeTypes.GS1DataMatrix. Typical use cases include encoding product identifiers (GTIN) and lot numbers for supply‑chain labeling, where developers need to control visual parameters like X‑dimension and export to raster formats such as BMP. +// Title: Generate GS1 DataMatrix Barcode and Export as BMP +// Description: Demonstrates creating a GS1 DataMatrix barcode with a specific module size and saving it as a BMP image. +// Category-Description: This example belongs to the Aspose.BarCode generation category, showcasing how to use the BarcodeGenerator class with EncodeTypes.GS1DataMatrix. It covers setting barcode parameters such as XDimension (module size) and exporting the result to a bitmap file. Developers working with product identification, inventory systems, or any scenario requiring GS1 DataMatrix symbols will find this pattern useful for creating compliant barcodes programmatically. // Prompt: Generate a GS1 DataMatrix barcode, set module size to 5 pixels, and export as BMP. -// Tags: gs1datamatrix, barcode generation, module size, bmp, aspose.barcode, csharp +// Tags: gs1, datamatrix, barcode, generation, module-size, bmp, aspose.barcode, aspose.barcode.generation using System; -using Aspose.BarCode.Generation; using Aspose.BarCode; +using Aspose.BarCode.Generation; /// -/// Example program that generates a GS1 DataMatrix barcode, -/// configures the module size, and saves the result as a BMP file. +/// Example program that creates a GS1 DataMatrix barcode, +/// configures its module size, and saves it as a BMP image. /// class Program { /// - /// Entry point of the application. + /// Entry point of the example. Generates the barcode and writes it to disk. /// static void Main() { - // Define the GS1 DataMatrix code text (GTIN and lot number) using Application Identifiers. - const string codeText = "(01)12345678901231(10)LOT123"; + // Define the GS1 DataMatrix payload: Application Identifier (01) + 14‑digit GTIN + string codeText = "(01)00123456789012"; - // Initialize the barcode generator for GS1 DataMatrix with the specified code text. + // Initialize the barcode generator for GS1 DataMatrix with the specified text using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Set the module (X‑dimension) size to 5 pixels to control barcode density. + // Configure the module (X‑dimension) size to 5 pixels generator.Parameters.Barcode.XDimension.Pixels = 5f; - // Save the generated barcode image as a BMP file. - generator.Save("gs1datamatrix.bmp"); + // Save the generated barcode as a BMP file + generator.Save("gs1_datamatrix.bmp"); } } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-gs1-datamatrix-barcode-with-error-correction-level-200-and-export-as-png.cs b/gs1-barcode-types/generate-gs1-datamatrix-barcode-with-error-correction-level-200-and-export-as-png.cs index f9b2e97..8ecbb15 100644 --- a/gs1-barcode-types/generate-gs1-datamatrix-barcode-with-error-correction-level-200-and-export-as-png.cs +++ b/gs1-barcode-types/generate-gs1-datamatrix-barcode-with-error-correction-level-200-and-export-as-png.cs @@ -1,16 +1,16 @@ // Title: Generate GS1 DataMatrix barcode with ECC200 and save as PNG -// Description: Demonstrates creating a GS1 DataMatrix barcode using Aspose.BarCode, setting error correction level ECC200, and exporting the image as a PNG file. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on GS1 DataMatrix symbology. It showcases the use of BarcodeGenerator, EncodeTypes, and DataMatrixEccType to configure error correction and save the result. Developers often need to generate GS1-compliant DataMatrix codes for product identification and require control over ECC levels for reliability. +// Description: Demonstrates creating a GS1 DataMatrix barcode using Aspose.BarCode, setting the error correction level to ECC200, and exporting the result as a PNG image. +// Category-Description: This example belongs to the Aspose.BarCode generation category, focusing on 2‑D symbologies such as DataMatrix. It showcases the use of BarcodeGenerator, EncodeTypes, and DataMatrixEccType to configure barcode parameters, a common requirement for developers who need to embed GS1‑compliant DataMatrix codes in packaging, inventory, or logistics applications. Typical use cases include generating high‑quality PNG images for printing or digital display. // Prompt: Generate a GS1 DataMatrix barcode with error correction level 200 and export as PNG. -// Tags: gs1datamatrix, barcode generation, error correction, png, aspose.barcode +// Tags: gs1, datamatrix, barcode, generation, png, ecc200, aspose.barcode using System; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Example program that generates a GS1 DataMatrix barcode with ECC200 error correction -/// and saves it as a PNG image using the Aspose.BarCode library. +/// Example program that creates a GS1 DataMatrix barcode, configures ECC200 error correction, +/// and saves the barcode as a PNG file using Aspose.BarCode. /// class Program { @@ -19,23 +19,23 @@ class Program /// static void Main() { - // Define the GS1 DataMatrix code text (GTIN) to encode. - const string codeText = "(01)12345678901231"; + // Define the GS1 DataMatrix payload: Application Identifier (01) followed by a 14‑digit GTIN. + const string codeText = "(01)01234567890123"; - // Specify the output file path for the generated PNG image. - const string outputPath = "gs1datamatrix.png"; - - // Initialize the barcode generator for GS1 DataMatrix with the provided text. + // Initialize the barcode generator for the GS1 DataMatrix symbology. using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Configure the DataMatrix error correction level to ECC200 (value 200). - generator.Parameters.Barcode.DataMatrix.DataMatrixEcc = DataMatrixEccType.Ecc200; + // Configure the DataMatrix error correction level to ECC200 (standard level 200). + generator.Parameters.Barcode.DataMatrix.EccType = DataMatrixEccType.Ecc200; + + // Optional: increase the image resolution to 300 DPI for higher visual quality. + generator.Parameters.Resolution = 300; - // Save the generated barcode image to the specified path in PNG format. - generator.Save(outputPath, BarCodeImageFormat.Png); + // Save the generated barcode as a PNG image file. + generator.Save("gs1datamatrix.png"); } - // Inform the user that the barcode has been successfully saved. - Console.WriteLine($"GS1 DataMatrix barcode saved to '{outputPath}'."); + // Inform the user that the barcode image has been created. + Console.WriteLine("GS1 DataMatrix barcode generated: gs1datamatrix.png"); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-retrieve-image-as-byte-array-and-attach-to-email.cs b/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-retrieve-image-as-byte-array-and-attach-to-email.cs index e5d1b6b..a064e1a 100644 --- a/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-retrieve-image-as-byte-array-and-attach-to-email.cs +++ b/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-retrieve-image-as-byte-array-and-attach-to-email.cs @@ -1,19 +1,19 @@ -// Title: Generate UPC‑A barcode with Code128 coupon and email attachment -// Description: Demonstrates creating a UPC‑A barcode that includes a Code128 coupon, converting it to a PNG byte array, and attaching it to an email message. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation and image handling category. It showcases the use of BarcodeGenerator with EncodeTypes.UpcaGs1Code128Coupon, saving the barcode to a memory stream, and integrating the resulting image into a System.Net.Mail email. Developers often need to generate barcodes on‑the‑fly and embed them in communications such as order confirmations or promotional emails. +// Title: Generate UPC‑A barcode with Code128 coupon and attach as PNG to email +// Description: Demonstrates creating a UPC‑A barcode that includes a GS1‑128 coupon segment, converting it to a PNG byte array, and attaching it to an email message. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, showcasing how to use BarcodeGenerator with EncodeTypes.UpcaGs1Code128Coupon, customize visual parameters, export the image to a memory stream, and integrate the result into .NET email APIs. Developers often need to embed barcodes in communications such as order confirmations or promotional emails, requiring image extraction and attachment handling. // Prompt: Generate a UPC‑A barcode with a Code128 coupon, retrieve image as byte array, and attach to email. -// Tags: upc-a, code128, barcode generation, image byte array, email attachment, aspose.barcode, system.net.mail +// Tags: upc-a, code128, coupon, barcode generation, image png, email attachment, aspose.barcode, aspose.drawing using System; using System.IO; -using System.Net; using System.Net.Mail; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing.Imaging; /// -/// Example program that generates a UPC‑A barcode with an embedded Code128 coupon, -/// converts the barcode image to a byte array, and attaches it to an email message. +/// Example program that creates a UPC‑A barcode with an embedded Code128 coupon, +/// converts the barcode to a PNG byte array, and prepares an email with the image attached. /// class Program { @@ -22,40 +22,50 @@ class Program /// static void Main() { - // Create a UPC‑A barcode that includes a Code128 coupon. - // Example codetext: "514141100906(8102)03" - using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, "514141100906(8102)03")) + // Define the UPC‑A code text that includes a Code128 coupon segment. + // Example format: "514141100906(8102)03" + string codeText = "514141100906(8102)03"; + + // Initialize the barcode generator for UPC‑A with GS1‑128 coupon symbology. + using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, codeText)) { - // Save the generated barcode image to a memory stream in PNG format. - using (var imageStream = new MemoryStream()) + // Optional visual customizations. + generator.Parameters.Barcode.XDimension.Point = 2f; // Set module (X) size. + generator.Parameters.Barcode.BarHeight.Point = 50f; // Set bar height for the linear part. + generator.Parameters.BackColor = Aspose.Drawing.Color.White; + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + + // Render the barcode to a memory stream in PNG format. + using (MemoryStream imageStream = new MemoryStream()) { generator.Save(imageStream, BarCodeImageFormat.Png); - byte[] imageBytes = imageStream.ToArray(); // Convert stream to byte array. + byte[] imageBytes = imageStream.ToArray(); // Retrieve the PNG image as a byte array. - // Prepare an email message and attach the barcode image. - using (var mailMessage = new MailMessage()) + // Compose an email message and attach the barcode image. + using (MailMessage mail = new MailMessage()) { - mailMessage.From = new MailAddress("sender@example.com"); - mailMessage.To.Add("recipient@example.com"); - mailMessage.Subject = "UPC‑A with Code128 Coupon Barcode"; - mailMessage.Body = "Please find the generated barcode attached."; + mail.From = new MailAddress("sender@example.com"); + mail.To.Add("recipient@example.com"); + mail.Subject = "UPC‑A Barcode with Code128 Coupon"; + mail.Body = "Please find the generated barcode attached."; - // Attach the image using a new memory stream based on the byte array. - using (var attachmentStream = new MemoryStream(imageBytes)) + // Create an attachment from the image byte array. + using (MemoryStream attachmentStream = new MemoryStream(imageBytes)) { - var attachment = new Attachment(attachmentStream, "barcode.png", "image/png"); - mailMessage.Attachments.Add(attachment); + Attachment attachment = new Attachment(attachmentStream, "barcode.png", "image/png"); + mail.Attachments.Add(attachment); - // Send the email using an SMTP client. - // Replace host, port, and credentials with real values when deploying. - using (var smtpClient = new SmtpClient("smtp.example.com")) + // Demonstrate email preparation. In CI environments, sending is omitted. + using (SmtpClient smtp = new SmtpClient()) { - smtpClient.Port = 25; - // smtpClient.Credentials = new NetworkCredential("username", "password"); - // smtpClient.EnableSsl = true; + // Uncomment and configure the following lines for real email sending. + // smtp.Host = "smtp.example.com"; + // smtp.Port = 587; + // smtp.Credentials = new System.Net.NetworkCredential("user", "password"); + // smtp.EnableSsl = true; + // smtp.Send(mail); - // Uncomment the line below to actually send the email. - // smtpClient.Send(mailMessage); + Console.WriteLine("Email prepared with barcode attachment (size: {0} bytes).", imageBytes.Length); } } } diff --git a/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-set-supplement-space-to-40-pixels-and-save-as-png.cs b/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-set-supplement-space-to-40-pixels-and-save-as-png.cs index c52d117..451d8e9 100644 --- a/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-set-supplement-space-to-40-pixels-and-save-as-png.cs +++ b/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-set-supplement-space-to-40-pixels-and-save-as-png.cs @@ -1,41 +1,41 @@ -// Title: Generate UPC‑A barcode with Code128 coupon and supplement space -// Description: Demonstrates creating a UPC‑A barcode that includes a Code128 coupon, configuring the supplement spacing, and saving the result as a PNG image. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on combined symbologies such as UPC‑A with GS1‑128 coupons. It showcases the use of BarcodeGenerator, EncodeTypes, and the Coupon settings to customize supplement spacing. Developers often need to generate composite barcodes for retail and promotional applications, adjusting visual parameters before exporting to common image formats. +// Title: Generate UPC‑A barcode with Code128 coupon and supplement spacing +// Description: Demonstrates how to create a UPC‑A barcode that includes a GS1‑128 coupon supplement, configure the supplement spacing, and save the result as a PNG image. +// Category-Description: Examples of barcode generation using Aspose.BarCode, focusing on composite symbologies that combine a primary barcode with a supplemental component such as a GS1‑128 coupon. The code shows how to use the BarcodeGenerator class, set EncodeTypes, adjust barcode parameters like Coupon.SupplementSpace, and export to common image formats. Developers often need these patterns to embed promotional data or additional product information alongside standard barcodes. // Prompt: Generate a UPC‑A barcode with a Code128 coupon, set supplement space to 40 pixels, and save as PNG. -// Tags: upc-a, code128, coupon, supplement-space, png, generation, aspose.barcode, encode-types +// Tags: upc-a, code128, coupon, supplement-space, png, aspose.barcode, generation using System; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Example program that creates a UPC‑A barcode with an embedded Code128 coupon, -/// sets the supplement (coupon) spacing, and saves the image as a PNG file. +/// Sample program that creates a UPC‑A barcode with a GS1‑128 coupon supplement, +/// configures the supplement spacing, and saves the image as PNG. /// class Program { /// - /// Entry point of the application. Generates the barcode and writes it to disk. + /// Entry point of the application. /// static void Main() { - // Define the output file path for the generated PNG image - const string outputPath = "upc_code128_coupon.png"; + // Define the output file name. + const string outputPath = "upc_a_coupon.png"; - // Sample codetext representing a UPC‑A value with a GS1‑128 coupon segment - const string codeText = "514141100906(8102)03"; - - // Initialize the barcode generator with the combined UPC‑A/GS1‑128 coupon symbology - using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, codeText)) + // Initialize the barcode generator for the composite UPC‑A / GS1‑128 coupon symbology. + using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon)) { - // Configure the supplement (coupon) space to 40 pixels + // Set the barcode text: 12‑digit UPC‑A value followed by the Code128 supplement in parentheses. + generator.CodeText = "514141100906(8102)03"; + + // Configure the space (in points) between the main barcode and the supplement. generator.Parameters.Barcode.Coupon.SupplementSpace.Point = 40f; - // Save the generated barcode image in PNG format to the specified path - generator.Save(outputPath); + // Render and save the barcode as a PNG image. + generator.Save(outputPath, BarCodeImageFormat.Png); } - // Inform the user that the barcode has been saved successfully + // Inform the user where the file was saved. Console.WriteLine($"Barcode saved to {outputPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-upc-barcode-with-databar-coupon-then-combine-it-with-logo-using-systemdrawing-graphics.cs b/gs1-barcode-types/generate-upc-barcode-with-databar-coupon-then-combine-it-with-logo-using-systemdrawing-graphics.cs index a5f437f..910c17e 100644 --- a/gs1-barcode-types/generate-upc-barcode-with-databar-coupon-then-combine-it-with-logo-using-systemdrawing-graphics.cs +++ b/gs1-barcode-types/generate-upc-barcode-with-databar-coupon-then-combine-it-with-logo-using-systemdrawing-graphics.cs @@ -1,8 +1,8 @@ -// Title: Generate UPC‑A DataBar Coupon barcode with logo overlay -// Description: Demonstrates creating a UPC‑A barcode with a GS1 DataBar coupon, then merging it with a simple logo using System.Drawing. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use BarcodeGenerator with EncodeTypes.UpcaGs1DatabarCoupon, customize colors, and combine the resulting bitmap with other graphics via Aspose.Drawing. Typical use cases include retail product labeling with promotional coupons and brand logos. Developers often need to create combined images for printing or digital display, making this pattern a common reference. +// Title: Generate UPC‑A DataBar Coupon Barcode and Merge with a Logo +// Description: Demonstrates how to create a UPC‑A barcode with a GS1 DataBar coupon payload using Aspose.BarCode, then combine it with a simple logo image using Aspose.Drawing graphics. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating the use of BarcodeGenerator with EncodeTypes.UpcaGs1DatabarCoupon, customizing visual parameters, and compositing the result with System.Drawing (Aspose.Drawing) graphics. Typical use cases include creating promotional barcodes that embed coupon data and branding them with a company logo. Developers often need to adjust dimensions, colors, and merge multiple images for printable assets. // Prompt: Generate a UPC‑A barcode with a DataBar coupon, then combine it with a logo using System.Drawing graphics. -// Tags: upc-a, databar, coupon, barcode generation, logo overlay, png, aspose.barcode, aspose.drawing +// Tags: barcode, upc-a, databar, coupon, logo, aspose.barcode, aspose.drawing, image composition, png, c# using System; using System.IO; @@ -12,89 +12,70 @@ using Aspose.Drawing.Imaging; /// -/// Example program that creates a UPC‑A barcode with a GS1 DataBar coupon, -/// generates a simple logo, and combines both images into a single PNG file. +/// Example program that generates a UPC‑A GS1 DataBar coupon barcode, +/// creates a placeholder logo, and merges both images side by side. /// class Program { /// - /// Entry point of the example. Generates the barcode, logo, and combined image, - /// then writes the output file locations to the console. + /// Entry point. Generates the barcode, builds a logo, combines them, + /// and saves the result as a PNG file. /// static void Main() { - // Paths for output images - const string barcodePath = "barcode.png"; - const string logoPath = "logo.png"; - const string combinedPath = "combined.png"; + // UPC‑A with DataBar coupon text (example from Aspose documentation) + const string barcodeText = "514141100906(8110)106141416543213500110000310123196000"; - // ----------------------------------------------------------------- - // 1. Create UPC‑A barcode with a DataBar coupon - // ----------------------------------------------------------------- - // Sample codetext: UPCA part + DataBar part (see EncodeTypes.UpcaGs1DatabarCoupon documentation) - const string couponCodeText = "514141100906(8110)106141416543213500110000310123196000"; - - using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1DatabarCoupon, couponCodeText)) + // Initialize the barcode generator for the specific symbology + using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1DatabarCoupon, barcodeText)) { // Optional visual tweaks - generator.Parameters.Barcode.BarColor = Color.Black; - generator.Parameters.BackColor = Color.White; + generator.Parameters.Barcode.XDimension.Point = 2f; // Module size (width of the smallest bar) + generator.Parameters.Barcode.BarHeight.Point = 100f; // Height of the linear part of the barcode + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Generate the barcode image - using (Bitmap barcodeBmp = generator.GenerateBarCodeImage()) + // Generate the barcode image as a bitmap + using (Bitmap barcodeBitmap = generator.GenerateBarCodeImage()) { - // Save the barcode for reference - barcodeBmp.Save(barcodePath, ImageFormat.Png); - - // ----------------------------------------------------------------- - // 2. Create a simple logo image programmatically - // ----------------------------------------------------------------- - using (var logoBmp = new Bitmap(100, 100)) + // Create a simple placeholder logo (blue square with a white inner rectangle) + const int logoSize = 100; + using (Bitmap logoBitmap = new Bitmap(logoSize, logoSize)) { - using (var gLogo = Graphics.FromImage(logoBmp)) + using (Graphics gLogo = Graphics.FromImage(logoBitmap)) { - // Fill background with light gray - gLogo.Clear(Color.LightGray); - using (var font = new Font("Arial", 12f)) + // Fill background with white + gLogo.Clear(Aspose.Drawing.Color.White); + // Draw a blue border rectangle + using (Pen pen = new Pen(Aspose.Drawing.Color.Blue, 3f)) { - // Draw the word "Logo" in the center area - gLogo.DrawString("Logo", font, Brushes.Black, new PointF(10f, 40f)); + gLogo.DrawRectangle(pen, 5, 5, logoSize - 10, logoSize - 10); } } - // Save the logo for reference - logoBmp.Save(logoPath, ImageFormat.Png); - - // ----------------------------------------------------------------- - // 3. Combine barcode and logo into a single image - // ----------------------------------------------------------------- - int combinedWidth = Math.Max(barcodeBmp.Width, logoBmp.Width); - int combinedHeight = barcodeBmp.Height + logoBmp.Height; - - using (var combinedBmp = new Bitmap(combinedWidth, combinedHeight)) + // Combine barcode and logo side by side + int combinedWidth = barcodeBitmap.Width + logoBitmap.Width; + int combinedHeight = Math.Max(barcodeBitmap.Height, logoBitmap.Height); + using (Bitmap combinedBitmap = new Bitmap(combinedWidth, combinedHeight)) { - using (var gCombined = Graphics.FromImage(combinedBmp)) + using (Graphics g = Graphics.FromImage(combinedBitmap)) { - // White background for the combined image - gCombined.Clear(Color.White); - - // Draw logo at the top - gCombined.DrawImage(logoBmp, 0, 0, logoBmp.Width, logoBmp.Height); - - // Draw barcode below the logo - gCombined.DrawImage(barcodeBmp, 0, logoBmp.Height, barcodeBmp.Width, barcodeBmp.Height); + // Fill the combined image background with white + g.Clear(Aspose.Drawing.Color.White); + // Draw barcode on the left + g.DrawImage(barcodeBitmap, 0, 0); + // Draw logo on the right, vertically centered + int logoY = (combinedHeight - logoBitmap.Height) / 2; + g.DrawImage(logoBitmap, barcodeBitmap.Width, logoY); } - // Save the final combined image - combinedBmp.Save(combinedPath, ImageFormat.Png); + // Save the final combined image as PNG + const string outputPath = "combined.png"; + combinedBitmap.Save(outputPath, ImageFormat.Png); + Console.WriteLine($"Combined image saved to: {Path.GetFullPath(outputPath)}"); } } } } - - // Inform the user where the files are saved - Console.WriteLine($"Barcode saved to: {Path.GetFullPath(barcodePath)}"); - Console.WriteLine($"Logo saved to: {Path.GetFullPath(logoPath)}"); - Console.WriteLine($"Combined image saved to: {Path.GetFullPath(combinedPath)}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-upc-barcode-with-databar-expanded-coupon-and-adjust-supplement-spacing-to-50-pixels.cs b/gs1-barcode-types/generate-upc-barcode-with-databar-expanded-coupon-and-adjust-supplement-spacing-to-50-pixels.cs index e87a6a6..13c00e2 100644 --- a/gs1-barcode-types/generate-upc-barcode-with-databar-expanded-coupon-and-adjust-supplement-spacing-to-50-pixels.cs +++ b/gs1-barcode-types/generate-upc-barcode-with-databar-expanded-coupon-and-adjust-supplement-spacing-to-50-pixels.cs @@ -1,36 +1,43 @@ -// Title: Generate UPC‑A Barcode with DataBar Expanded Coupon and Custom Supplement Spacing -// Description: This example creates a UPC‑A barcode that includes a DataBar Expanded coupon and sets the supplement spacing to 50 pixels. -// Category-Description: Demonstrates Aspose.BarCode generation of composite barcodes using EncodeTypes.UpcaGs1DatabarCoupon. It showcases configuring the Coupon.SupplementSpace property, a common requirement when integrating UPC‑A with DataBar Expanded for retail coupons. Developers working with composite symbologies, supplement adjustments, and image output will find this pattern useful. +// Title: Generate UPC‑A barcode with DataBar Expanded coupon and custom supplement spacing +// Description: Demonstrates how to create a UPC‑A barcode that includes a GS1 DataBar Expanded coupon and set the supplement spacing to 50 pixels. +// Category-Description: This example belongs to the Aspose.BarCode generation category, showcasing the use of BarcodeGenerator with EncodeTypes.UpcaGs1DatabarCoupon. It illustrates typical retail scenarios where a UPC‑A barcode is combined with a DataBar Expanded coupon, and developers often need to adjust supplement spacing for proper scanning. The key API classes include BarcodeGenerator, EncodeTypes, and the Barcode parameters hierarchy. // Prompt: Generate a UPC‑A barcode with a DataBar Expanded coupon and adjust supplement spacing to 50 pixels. -// Tags: upc-a, databar expanded, supplement spacing, barcode generation, aspose.barcode +// Tags: upc-a, databar expanded, supplement spacing, png, barcodegenerator, encode types using System; -using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.BarCode; /// -/// Example program that generates a UPC‑A barcode containing a DataBar Expanded coupon -/// and customizes the supplement spacing. +/// Example program that generates a UPC‑A barcode containing a GS1 DataBar Expanded coupon +/// and customizes the supplement spacing before saving it as a PNG image. /// class Program { /// - /// Entry point of the example. Creates the barcode, configures supplement spacing, - /// and saves the result as a PNG image. + /// Entry point of the application. Creates the barcode, configures supplement spacing, + /// saves the image, and writes the output path to the console. /// static void Main() { - // Initialize the barcode generator for UPC‑A with a DataBar Expanded coupon - using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1DatabarCoupon)) - { - // Define the composite code text (UPC‑A part followed by DataBar part) - generator.CodeText = "514141100906(8110)106141416543213500110000310123196000"; + // Define the output file name for the generated barcode image. + string outputPath = "upc_databar_coupon.png"; - // Adjust the supplement (coupon) spacing to 50 pixels + // UPC‑A data (12 digits) followed by DataBar Expanded coupon data enclosed in parentheses. + // The format complies with GS1 specifications for combined barcode types. + string codeText = "514141100906(8110)106141416543213500110000310123196000"; + + // Initialize the barcode generator for the UPC‑A with GS1 DataBar Expanded coupon symbology. + using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1DatabarCoupon, codeText)) + { + // Adjust the spacing between the main barcode and the supplement (coupon) to 50 pixels. generator.Parameters.Barcode.Coupon.SupplementSpace.Point = 50f; - // Save the generated barcode image to a file - generator.Save("upc_a_databar_coupon.png"); + // Save the generated barcode as a PNG file to the specified path. + generator.Save(outputPath); } + + // Inform the user where the barcode image has been saved. + Console.WriteLine($"Barcode image saved to: {outputPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/produce-gs1-code-128-barcode-apply-anti-aliasing-and-save-image-with-24-bit-color-depth.cs b/gs1-barcode-types/produce-gs1-code-128-barcode-apply-anti-aliasing-and-save-image-with-24-bit-color-depth.cs index 77e0482..cc46273 100644 --- a/gs1-barcode-types/produce-gs1-code-128-barcode-apply-anti-aliasing-and-save-image-with-24-bit-color-depth.cs +++ b/gs1-barcode-types/produce-gs1-code-128-barcode-apply-anti-aliasing-and-save-image-with-24-bit-color-depth.cs @@ -1,41 +1,46 @@ -// Title: Generate GS1 Code 128 barcode with anti-aliasing and 24-bit PNG output -// Description: Demonstrates creating a GS1 Code 128 barcode, applying anti-aliasing for smooth rendering, and saving it as a 24‑bit PNG image. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use the BarcodeGenerator class with EncodeTypes.GS1Code128. It shows typical tasks such as setting symbology, configuring rendering options like anti‑aliasing, and specifying colors before saving to a common image format. Developers looking for barcode creation, image quality tuning, and format-specific output will find similar examples useful. +// Title: Generate GS1 Code 128 Barcode with Anti-Aliasing and 24‑Bit PNG Output +// Description: Demonstrates how to create a GS1 Code 128 barcode, enable anti‑aliasing for smooth rendering, and save it as a 24‑bit PNG image. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and rendering parameters. Typical use cases include creating GS1‑compliant product barcodes for packaging, applying anti‑aliasing for high‑quality visuals, and exporting to common image formats with specific color depth. Developers often need to customize colors, rendering options, and output formats when integrating barcode generation into .NET applications. // Prompt: Produce a GS1 Code 128 barcode, apply anti‑aliasing, and save the image with 24‑bit color depth. -// Tags: gs1, code128, barcode, generation, anti-aliasing, png, 24-bit, aspose.barcode +// Tags: gs1, code128, barcode, generation, anti-aliasing, png, 24-bit, aspnet, aspose.barcode using System; -using Aspose.BarCode.Generation; using Aspose.BarCode; +using Aspose.BarCode.Generation; using Aspose.Drawing; -/// -/// Example program that generates a GS1 Code 128 barcode, -/// applies anti‑aliasing for smoother rendering, and saves it as a 24‑bit PNG image. -/// -class Program +namespace BarcodeSample { /// - /// Entry point of the example. Creates the barcode, configures rendering options, - /// and writes the output file. + /// Sample program that generates a GS1 Code 128 barcode, applies anti‑aliasing, + /// and saves the result as a 24‑bit PNG image. /// - static void Main() + class Program { - // GS1 Code 128 requires AI parentheses, e.g., (01) for GTIN - const string gs1Code128Text = "(01)12345678901231"; - - // Create a generator for the GS1 Code 128 symbology - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, gs1Code128Text)) + /// + /// Entry point of the application. + /// + static void Main() { - // Enable anti‑aliasing for smoother rendering - generator.Parameters.UseAntiAlias = true; + // Initialize a barcode generator for GS1 Code 128 with a sample GTIN (01) value. + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, "(01)01234567890123")) + { + // Enable anti‑aliasing to improve visual quality of the rendered barcode. + generator.Parameters.UseAntiAlias = true; + + // Set the bar (foreground) color to black. + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + + // Set the background color to white. + generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Set foreground (bars) and background colors – default PNG is 24‑bit - generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; - generator.Parameters.BackColor = Aspose.Drawing.Color.White; + // Save the generated barcode as a PNG file. + // PNG format uses 24‑bit color depth by default, meeting the requirement. + generator.Save("gs1code128.png"); + } - // Save the barcode as a PNG file (24‑bit color depth) - generator.Save("gs1code128.png"); + // Inform the user that the barcode has been generated. + Console.WriteLine("Barcode generated and saved as gs1code128.png"); } } } \ No newline at end of file diff --git a/gs1-barcode-types/produce-gs1-code-128-barcode-write-image-bytes-to-memorystream-and-return-as-api-response.cs b/gs1-barcode-types/produce-gs1-code-128-barcode-write-image-bytes-to-memorystream-and-return-as-api-response.cs index c5dd7ef..a9c3ea8 100644 --- a/gs1-barcode-types/produce-gs1-code-128-barcode-write-image-bytes-to-memorystream-and-return-as-api-response.cs +++ b/gs1-barcode-types/produce-gs1-code-128-barcode-write-image-bytes-to-memorystream-and-return-as-api-response.cs @@ -1,54 +1,45 @@ -// Title: Generate GS1 Code 128 barcode and return as API response -// Description: Demonstrates creating a GS1 Code 128 barcode, writing the PNG image to a MemoryStream, and returning the image bytes (as Base64) suitable for an API response. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating how to use BarcodeGenerator with EncodeTypes.GS1Code128, configure barcode parameters, and output the image in PNG format. Developers often need to generate GS1-compliant barcodes for product identification and return them via web APIs; this snippet shows the typical workflow using Aspose.BarCode classes such as BarcodeGenerator, BarCodeImageFormat, and related parameter settings. +// Title: Generate GS1 Code 128 Barcode and Return as Base64 String +// Description: Creates a GS1 Code 128 barcode image, writes it to a memory stream, and outputs the image as a Base64‑encoded string suitable for API responses. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category. It demonstrates using the BarcodeGenerator class with EncodeTypes.GS1Code128 to produce a barcode, saving it to a MemoryStream in PNG format, and retrieving the raw bytes. Developers often need to generate barcodes on‑the‑fly for web APIs, e‑commerce platforms, or inventory systems, and this pattern shows the typical workflow for image‑based barcode output. // Prompt: Produce a GS1 Code 128 barcode, write image bytes to a MemoryStream, and return as an API response. -// Tags: gs1, code128, barcode, generation, png, memorystream, api, response +// Tags: gs1, code128, barcode, generation, memory stream, base64, api, aspose.barcode using System; using System.IO; -using System.Text; using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.Drawing.Imaging; /// -/// Example program that generates a GS1 Code 128 barcode, -/// writes the PNG image to a , -/// and outputs the image bytes as a Base64 string (simulating an API response). +/// Demonstrates generating a GS1 Code 128 barcode and returning it as a Base64 string. /// class Program { /// - /// Entry point of the example. Generates the barcode and writes the result to the console. + /// Entry point that creates the barcode, writes it to a memory stream, and prints the Base64 image. /// static void Main() { - // Sample GS1 Code 128 data (AI (01) for GTIN) - const string gs1Code128Text = "(01)12345678901231"; + // Sample GS1 Code 128 codetext: AI (01) with a 14‑digit GTIN + const string gs1CodeText = "(01)01234567890123"; - // Create a memory stream to hold the generated barcode image - using (var imageStream = new MemoryStream()) + // Initialize the barcode generator with GS1 Code 128 symbology and the sample text + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, gs1CodeText)) { - // Initialize the barcode generator for GS1 Code 128 with the sample data - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, gs1Code128Text)) + // Create a memory stream to hold the generated image + using (var ms = new MemoryStream()) { - // Ensure the checksum is always shown (default for GS1 Code 128) - generator.Parameters.Barcode.ChecksumAlwaysShow = true; + // Save the barcode image as PNG into the stream + generator.Save(ms, BarCodeImageFormat.Png); - // Save the barcode image as PNG into the memory stream - generator.Save(imageStream, BarCodeImageFormat.Png); - } - - // Reset the stream position to the beginning for reading - imageStream.Position = 0; + // Reset the stream position to the beginning for reading + ms.Position = 0; - // In a real API you would return the stream directly. - // Here we demonstrate by converting the image bytes to a Base64 string. - byte[] imageBytes = imageStream.ToArray(); - string base64Image = Convert.ToBase64String(imageBytes); + // Convert the image bytes to a Base64 string (simulating an API response) + string base64Image = Convert.ToBase64String(ms.ToArray()); - // Output the Base64 string (simulating an API response body) - Console.WriteLine(base64Image); + // Output the Base64 string to the console + Console.WriteLine(base64Image); + } } } } \ No newline at end of file diff --git a/gs1-barcode-types/produce-upc-barcode-with-databar-coupon-then-programmatically-merge-it-with-product-label-image.cs b/gs1-barcode-types/produce-upc-barcode-with-databar-coupon-then-programmatically-merge-it-with-product-label-image.cs index 342bc42..7ce21d9 100644 --- a/gs1-barcode-types/produce-upc-barcode-with-databar-coupon-then-programmatically-merge-it-with-product-label-image.cs +++ b/gs1-barcode-types/produce-upc-barcode-with-databar-coupon-then-programmatically-merge-it-with-product-label-image.cs @@ -1,8 +1,8 @@ -// Title: Generate UPC‑A DataBar Coupon barcode and merge with product label -// Description: Demonstrates creating a UPC‑A barcode with a GS1 DataBar coupon payload and combining it with an existing product label image. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation and image manipulation category. It showcases the use of BarcodeGenerator with EncodeTypes.UpcaGs1DatabarCoupon, setting visual parameters, and merging the generated barcode bitmap onto a product label using Aspose.Drawing graphics. Developers often need to create combined label images for retail packaging, where a barcode is placed on top of product artwork. +// Title: Generate UPC‑A DataBar Coupon Barcode and Merge with Product Label +// Description: Demonstrates creating a UPC‑A barcode with a GS1 DataBar coupon symbology, then compositing it onto a product label image. +// Category-Description: This example belongs to the barcode generation and image manipulation category, showcasing how to use Aspose.BarCode's BarcodeGenerator with EncodeTypes.UpcaGs1DatabarCoupon, configure visual parameters, and combine the generated barcode with other graphics using Aspose.Drawing. Typical use cases include creating product labels, coupons, and packaging artwork where a barcode must be placed on a pre‑designed label. // Prompt: Produce a UPC‑A barcode with a DataBar coupon, then programmatically merge it with a product label image. -// Tags: upc-a, databar, coupon, barcode-generation, image-merge, png, aspose.barcode, aspose.drawing +// Tags: barcode, upc-a, databar, coupon, image merging, aspose.barcode, aspose.drawing, png, generation using System; using System.IO; @@ -12,81 +12,62 @@ using Aspose.Drawing.Imaging; /// -/// Example program that generates a UPC‑A DataBar coupon barcode, -/// saves it as an image, and merges it onto a product label picture. +/// Example program that generates a UPC‑A GS1 DataBar coupon barcode, +/// draws it onto a simple product label, and saves the merged image. /// class Program { /// - /// Entry point of the example. Creates the barcode, merges it with a label, - /// and writes the resulting images to disk. + /// Entry point. Generates the barcode, merges it with a label, and writes the result to disk. /// static void Main() { - // -------------------------------------------------------------------- - // Define file paths (adjust as needed for your environment) - // -------------------------------------------------------------------- - const string productLabelPath = "product_label.png"; - const string barcodePath = "barcode.png"; + // Output file path for the final merged label image const string mergedPath = "merged_label.png"; - // Verify that the product label image exists before proceeding - if (!File.Exists(productLabelPath)) - { - Console.WriteLine($"Error: Product label image not found at '{productLabelPath}'."); - return; - } - - // -------------------------------------------------------------------- - // Prepare the barcode data: UPC‑A with GS1 DataBar coupon payload - // -------------------------------------------------------------------- + // Text to encode – a UPC‑A code with GS1 DataBar coupon data const string couponCodeText = "514141100906(8110)106141416543213500110000310123196000"; - // Create a BarcodeGenerator for the UPC‑A DataBar coupon symbology + // Create a barcode generator for the UPC‑A GS1 DataBar coupon symbology using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1DatabarCoupon, couponCodeText)) { // Optional visual customizations - generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; - generator.Parameters.BackColor = Aspose.Drawing.Color.White; - - // Enable automatic sizing using interpolation - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; // barcode bars color + generator.Parameters.BackColor = Aspose.Drawing.Color.White; // background color + generator.Parameters.Barcode.XDimension.Point = 2f; // module (X) size - // Set desired image dimensions (points) - generator.Parameters.ImageWidth.Point = 300f; - generator.Parameters.ImageHeight.Point = 150f; - - // ---------------------------------------------------------------- - // Generate the barcode bitmap - // ---------------------------------------------------------------- - using (Bitmap barcodeBitmap = generator.GenerateBarCodeImage()) + // Store the generated barcode image in a memory stream + using (var barcodeStream = new MemoryStream()) { - // Save the standalone barcode image (optional) - barcodeBitmap.Save(barcodePath, ImageFormat.Png); + generator.Save(barcodeStream, BarCodeImageFormat.Png); + barcodeStream.Position = 0; // reset stream position for reading - // Load the existing product label image - using (Image productImage = Image.FromFile(productLabelPath)) + // Load the barcode image from the memory stream + using (var barcodeImage = Image.FromStream(barcodeStream)) { - // Prepare a graphics object for drawing onto the label - using (Graphics graphics = Graphics.FromImage(productImage)) + // Create a blank product label canvas (400 px × 300 px, white background) + using (var labelImage = new Bitmap(400, 300)) { - // Define placement margin and calculate position (bottom‑left) - int margin = 50; - int posX = margin; - int posY = productImage.Height - barcodeBitmap.Height - margin; + // Fill the label background with white + using (var gfx = Graphics.FromImage(labelImage)) + { + gfx.Clear(Aspose.Drawing.Color.White); + } - // Draw the barcode onto the label at the calculated coordinates - graphics.DrawImage(barcodeBitmap, posX, posY, barcodeBitmap.Width, barcodeBitmap.Height); - } + // Draw the barcode onto the label in the bottom‑right corner with a 10 px margin + using (var gfx = Graphics.FromImage(labelImage)) + { + int x = labelImage.Width - barcodeImage.Width - 10; + int y = labelImage.Height - barcodeImage.Height - 10; + gfx.DrawImage(barcodeImage, x, y, barcodeImage.Width, barcodeImage.Height); + } - // Save the combined label image - productImage.Save(mergedPath, ImageFormat.Png); + // Save the combined label image as PNG + labelImage.Save(mergedPath, ImageFormat.Png); + Console.WriteLine($"Merged label saved to: {mergedPath}"); + } } } } - - // Inform the user where the output files are located - Console.WriteLine($"Barcode image saved to: {barcodePath}"); - Console.WriteLine($"Merged label image saved to: {mergedPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/produce-upc-barcode-with-embedded-gs1-code128-coupon-and-define-30-pixel-supplement-space.cs b/gs1-barcode-types/produce-upc-barcode-with-embedded-gs1-code128-coupon-and-define-30-pixel-supplement-space.cs index 0173a76..2455bc7 100644 --- a/gs1-barcode-types/produce-upc-barcode-with-embedded-gs1-code128-coupon-and-define-30-pixel-supplement-space.cs +++ b/gs1-barcode-types/produce-upc-barcode-with-embedded-gs1-code128-coupon-and-define-30-pixel-supplement-space.cs @@ -1,42 +1,38 @@ -// Title: Generate UPC‑A barcode with embedded GS1 Code128 coupon and 30‑pixel supplement -// Description: Demonstrates creating a UPC‑A barcode that includes a GS1 Code128 coupon and sets a 30‑pixel supplement space. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on composite symbologies that combine UPC‑A with GS1‑Code128 coupons. It showcases the use of BarcodeGenerator, EncodeTypes, and coupon parameters to embed supplemental data, a common requirement for retail and promotional barcode creation. Developers often need to generate such combined barcodes for product labeling and coupon integration. -// Prompt: Produce a UPC‑A barcode with an embedded GS1 Code128 coupon and define 30‑pixel supplement space. -// Tags: upc-a, gs1-code128, coupon, supplement, barcode generation, aspnet, png +// Title: Generate UPC‑A barcode with GS1 Code128 coupon and supplement space +// Description: Demonstrates creating a UPC‑A barcode that includes an embedded GS1 Code128 coupon and sets a 30‑pixel supplement spacing. +// Category-Description: This example belongs to the Aspose.BarCode generation category, showcasing how to use the BarcodeGenerator with EncodeTypes.UpcaGs1Code128Coupon. It illustrates typical retail scenarios where a UPC‑A product barcode is combined with a GS1 Code128 coupon, and how to control the visual layout by defining supplement space. Developers working with barcode creation, coupon integration, or custom barcode formatting will find this pattern useful. +/// Prompt: Produce a UPC‑A barcode with an embedded GS1 Code128 coupon and define 30‑pixel supplement space. +/// Tags: upc-a, gs1, code128, coupon, supplement, barcode, generation, aspose.barcode, image using System; -using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.BarCode; /// -/// Example program that creates a UPC‑A barcode with an embedded GS1‑Code128 coupon -/// and configures a 30‑pixel supplement space. +/// Example program that generates a UPC‑A barcode containing a GS1 Code128 coupon +/// and configures a 30‑pixel supplement space between the main barcode and its supplement. /// class Program { /// - /// Entry point. Generates the barcode and saves it as a PNG file. + /// Entry point of the application. Generates the barcode and saves it as a PNG file. /// static void Main() { - // Define the barcode text. - // Format: "UPCA part (GS1Code128 part)" - const string codeText = "514141100906(8102)03"; - - // Define the output file name. - const string outputPath = "upc_gs1code128_coupon.png"; + // Define the barcode text: UPC‑A part (12 digits) followed by GS1 Code128 coupon part. + string codeText = "514141100906(8102)03"; - // Initialize the generator for the composite UPC‑A with GS1‑Code128 coupon symbology. + // Initialize the barcode generator for UPC‑A with an embedded GS1 Code128 coupon. using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, codeText)) { - // Set the supplement (coupon) space to 30 pixels. - generator.Parameters.Barcode.Coupon.SupplementSpace.Pixels = 30f; + // Set a 30‑pixel space between the main barcode and its supplement. + generator.Parameters.Barcode.Coupon.SupplementSpace.Point = 30f; - // Save the generated barcode image as PNG. - generator.Save(outputPath, BarCodeImageFormat.Png); + // Save the generated barcode image to a file. + generator.Save("upc_coupon.png"); } - // Inform the user where the barcode image was saved. - Console.WriteLine($"Barcode saved to {outputPath}"); + // Inform the user that the barcode has been generated. + Console.WriteLine("Barcode generated: upc_coupon.png"); } } \ No newline at end of file diff --git a/gs1-barcode-types/produce-upc-barcode-with-gs1-code128-coupon-then-embed-image-into-html-page.cs b/gs1-barcode-types/produce-upc-barcode-with-gs1-code128-coupon-then-embed-image-into-html-page.cs index f43faf3..961d774 100644 --- a/gs1-barcode-types/produce-upc-barcode-with-gs1-code128-coupon-then-embed-image-into-html-page.cs +++ b/gs1-barcode-types/produce-upc-barcode-with-gs1-code128-coupon-then-embed-image-into-html-page.cs @@ -1,52 +1,71 @@ // Title: Generate UPC‑A barcode with GS1 Code128 coupon and embed in HTML -// Description: Demonstrates creating a UPC‑A barcode that includes a GS1 Code128 coupon, converting it to PNG, and embedding the image directly into an HTML page using a data URI. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, showcasing the use of BarcodeGenerator with EncodeTypes.UpcaGs1Code128Coupon. It illustrates typical scenarios such as creating combined symbologies for retail packaging, generating barcode images, and embedding them in web content. Developers often need to produce barcode graphics for e‑commerce, inventory, or promotional coupons, and this snippet provides a concise reference. +// Description: Demonstrates creating a UPC‑A barcode that includes a GS1 Code128 coupon, saving it as a PNG image, and embedding the image directly into an HTML page using a data URI. +// Category-Description: This example belongs to the Aspose.BarCode generation and rendering category, showcasing how to use the BarcodeGenerator class with composite symbologies (UPC‑A with GS1 Code128 coupon) to produce barcode images. Typical use cases include retail product labeling and coupon integration where a single barcode encodes both product and promotional data. Developers often need to render barcodes to image formats and embed them in web pages or documents, which this sample illustrates. // Prompt: Produce a UPC‑A barcode with a GS1 Code128 coupon, then embed the image into an HTML page. -// Tags: upc-a, gs1-code128, coupon, barcode generation, image embedding, html, aspose.barcode, png +// Tags: upc-a, code128, gs1, coupon, barcode, image, html, aspose.barcode, generation, data-uri using System; using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.Drawing; -using Aspose.Drawing.Imaging; /// -/// Demonstrates generating a UPC‑A barcode with a GS1 Code128 coupon and embedding it into an HTML file. +/// Demonstrates generating a UPC‑A barcode with a GS1 Code128 coupon and embedding it in an HTML page. /// class Program { /// - /// Entry point. Generates the barcode, converts it to a Base64 PNG, and writes an HTML file containing the image. + /// Entry point of the example. Generates the barcode, saves it as PNG, creates a Base64 data URI, + /// and writes an HTML file that displays the barcode image. /// static void Main() { - // Initialize the barcode generator for UPC‑A with a GS1 Code128 coupon. - // Example codetext: "514141100906(8102)03" - using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, "514141100906(8102)03")) - { - // Generate the barcode image as a bitmap. - using (Bitmap bitmap = generator.GenerateBarCodeImage()) - { - // Save the bitmap to a memory stream in PNG format. - using (var memoryStream = new MemoryStream()) - { - bitmap.Save(memoryStream, ImageFormat.Png); - byte[] imageBytes = memoryStream.ToArray(); + // Define the barcode text that includes the UPC‑A data and the GS1 Code128 coupon segment. + const string codeText = "514141100906(8102)03"; - // Convert the PNG bytes to a Base64 string for embedding. - string base64Image = Convert.ToBase64String(imageBytes); + // File names for the generated PNG image and the resulting HTML page. + const string imageFile = "barcode.png"; + const string htmlFile = "barcode.html"; - // Build a simple HTML page that embeds the barcode image using a data URI. - string htmlContent = $"UPC‑A GS1‑Code128 Coupon" + - $"

UPC‑A with GS1‑Code128 Coupon

" + - $"\"Barcode\"/" + - $""; + // Variable to hold the Base64 representation of the PNG image for embedding. + string base64Image; + + // Create a BarcodeGenerator for the composite symbology (UPC‑A with GS1 Code128 coupon). + using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, codeText)) + { + // Use a memory stream to capture the generated PNG without writing to disk first. + using (var ms = new MemoryStream()) + { + // Render the barcode into the memory stream in PNG format. + generator.Save(ms, BarCodeImageFormat.Png); + ms.Position = 0; - // Write the HTML content to a file named 'barcode.html'. - File.WriteAllText("barcode.html", htmlContent); + // Persist the PNG image to a file for external use or inspection. + using (var fileStream = new FileStream(imageFile, FileMode.Create, FileAccess.Write)) + { + ms.CopyTo(fileStream); } + + // Convert the PNG bytes to a Base64 string for embedding in an HTML data URI. + base64Image = Convert.ToBase64String(ms.ToArray()); } } + + // Build a simple HTML document that displays the barcode using a data URI. + using (var writer = new StreamWriter(htmlFile, false)) + { + writer.WriteLine(""); + writer.WriteLine(""); + writer.WriteLine("Barcode Example"); + writer.WriteLine(""); + writer.WriteLine("

UPC‑A with GS1 Code128 Coupon

"); + writer.WriteLine($"\"Barcode\"/"); + writer.WriteLine(""); + writer.WriteLine(""); + } + + // Output the locations of the generated files for user reference. + Console.WriteLine($"Barcode image saved to: {Path.GetFullPath(imageFile)}"); + Console.WriteLine($"HTML page saved to: {Path.GetFullPath(htmlFile)}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/render-gs1-code-128-barcode-retrieve-image-bytes-and-store-them-in-database-column.cs b/gs1-barcode-types/render-gs1-code-128-barcode-retrieve-image-bytes-and-store-them-in-database-column.cs index 38a8743..483b5c8 100644 --- a/gs1-barcode-types/render-gs1-code-128-barcode-retrieve-image-bytes-and-store-them-in-database-column.cs +++ b/gs1-barcode-types/render-gs1-code-128-barcode-retrieve-image-bytes-and-store-them-in-database-column.cs @@ -1,64 +1,62 @@ -// Title: Render GS1 Code 128 barcode and store image bytes -// Description: Demonstrates generating a GS1 Code 128 barcode, extracting the PNG image bytes, and showing how to persist them to a database column. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and image handling classes such as Bitmap and ImageFormat. Typical scenarios include creating product barcodes, exporting them as image streams, and saving the binary data to a database for later retrieval. Developers often need to render barcodes, obtain raw bytes, and integrate them with data storage solutions. +// Title: Render GS1 Code 128 barcode and save image bytes +// Description: Demonstrates generating a GS1 Code 128 barcode, extracting the PNG image bytes, and persisting them (illustrated by writing to a file, with placeholder code for database storage). +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, showcasing the use of BarcodeGenerator with EncodeTypes.GS1Code128. It covers configuring barcode appearance, rendering to a memory stream, and handling raw image bytes—common tasks for developers integrating barcodes into databases, web services, or file systems. Typical use cases include inventory labeling, product tracking, and POS systems where GS1 standards are required. // Prompt: Render a GS1 Code 128 barcode, retrieve image bytes, and store them in a database column. -// Tags: gs1 code128, barcode generation, image output, png, database storage, aspose.barcode, aspose.drawing +// Tags: gs1, code128, barcode generation, image bytes, aspnet, aspose.barcode, png, database storage using System; using System.IO; -using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.Drawing; +using Aspose.BarCode; using Aspose.Drawing.Imaging; /// -/// Example program that generates a GS1 Code 128 barcode, -/// converts it to PNG bytes, and demonstrates how those bytes could be stored in a database. +/// Demonstrates generating a GS1 Code 128 barcode, obtaining its PNG bytes, +/// and persisting the image (example writes to file; database insertion code is provided as comment). /// class Program { /// - /// Entry point of the example. Generates the barcode, extracts image bytes, - /// and writes the PNG file to disk (simulating database storage). + /// Entry point. Generates the barcode, captures image bytes, and saves them. /// static void Main() { - // Sample GS1 Code 128 data (AI (01) with a 14‑digit GTIN) - const string gs1CodeText = "(01)12345678901231"; + // Define the GS1 Code 128 text. AI (01) requires exactly 14 digits. + string gs1Code128Text = "(01)00123456789012"; - // Initialize the barcode generator for GS1 Code 128 - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, gs1CodeText)) + // Generate the barcode and retrieve the image bytes. + byte[] barcodeBytes; + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, gs1Code128Text)) { - // Optional: always show checksum in the human‑readable text - generator.Parameters.Barcode.ChecksumAlwaysShow = true; + // Optional: customize barcode and background colors. + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Generate the barcode image as a Bitmap object - using (Bitmap bitmap = generator.GenerateBarCodeImage()) + // Render the barcode to a memory stream in PNG format. + using (var ms = new MemoryStream()) { - // Save the bitmap to a memory stream to obtain raw PNG bytes - using (var ms = new MemoryStream()) - { - bitmap.Save(ms, ImageFormat.Png); - byte[] imageBytes = ms.ToArray(); - - // ---- Substitute for database storage ---- - // In a real scenario you would store 'imageBytes' into a BLOB column, e.g.: - // using (var connection = new SqlConnection(connectionString)) - // { - // connection.Open(); - // using (var command = new SqlCommand("INSERT INTO Barcodes (Image) VALUES (@img)", connection)) - // { - // command.Parameters.Add("@img", SqlDbType.VarBinary, imageBytes.Length).Value = imageBytes; - // command.ExecuteNonQuery(); - // } - // } - // ----------------------------------------- - - // For the snippet runner, write the image to a local file instead - File.WriteAllBytes("gs1code128.png", imageBytes); - Console.WriteLine("Barcode image saved to 'gs1code128.png'."); - } + generator.Save(ms, BarCodeImageFormat.Png); + barcodeBytes = ms.ToArray(); // Extract the raw PNG bytes. } } + + // Placeholder for database storage: insert 'barcodeBytes' into a BLOB column. + // Example (commented out, requires a database library such as Microsoft.Data.Sqlite): + /* + using var connection = new SqliteConnection("Data Source=Barcodes.db"); + connection.Open(); + using var cmd = connection.CreateCommand(); + cmd.CommandText = "CREATE TABLE IF NOT EXISTS Barcodes(Id INTEGER PRIMARY KEY AUTOINCREMENT, Image BLOB)"; + cmd.ExecuteNonQuery(); + + cmd.CommandText = "INSERT INTO Barcodes(Image) VALUES (@img)"; + cmd.Parameters.Add("@img", SqliteType.Blob).Value = barcodeBytes; + cmd.ExecuteNonQuery(); + */ + + // For this runnable example, write the PNG file to disk. + string outputPath = "gs1_code128.png"; + File.WriteAllBytes(outputPath, barcodeBytes); + Console.WriteLine($"GS1 Code 128 barcode saved to '{Path.GetFullPath(outputPath)}'."); } } \ No newline at end of file diff --git a/gs1-barcode-types/set-barcode-size-to-200-100-pixels-for-gs1-code-128-barcode-and-export-as-jpeg.cs b/gs1-barcode-types/set-barcode-size-to-200-100-pixels-for-gs1-code-128-barcode-and-export-as-jpeg.cs index 390e7e9..0fbf6e4 100644 --- a/gs1-barcode-types/set-barcode-size-to-200-100-pixels-for-gs1-code-128-barcode-and-export-as-jpeg.cs +++ b/gs1-barcode-types/set-barcode-size-to-200-100-pixels-for-gs1-code-128-barcode-and-export-as-jpeg.cs @@ -1,37 +1,44 @@ -// Title: Set GS1 Code 128 barcode size and export as JPEG -// Description: Demonstrates how to configure a GS1 Code 128 barcode's dimensions to 200 × 100 pixels and save it as a JPEG image. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating image size manipulation using the BarcodeGenerator class. Developers often need to control barcode dimensions for UI layout, printing, or integration into documents; the API provides AutoSizeMode and image size properties to achieve precise pixel sizing. +// Title: Generate GS1 Code 128 barcode with custom size and save as JPEG +// Description: Demonstrates how to create a GS1 Code 128 barcode, set its image dimensions to 200 × 100 pixels, and export it as a JPEG file using Aspose.BarCode. +// Category-Description: This example belongs to the Aspose.BarCode image generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and AutoSizeMode to control barcode appearance. Typical scenarios include creating barcodes for product labeling, inventory systems, and e‑commerce platforms where specific image sizes and formats are required. Developers often need to adjust dimensions, scaling, and output formats to integrate barcodes into existing graphics pipelines. // Prompt: Set barcode size to 200 × 100 pixels for a GS1 Code 128 barcode and export as JPEG. -// Tags: gs1code128, barcode size, jpeg export, aspnet, aspose.barcode, generation +// Tags: gs1 code128, barcode size, jpeg export, aspose.barcode, image generation using System; -using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.BarCode; +using Aspose.Drawing.Imaging; /// -/// Demonstrates setting a GS1 Code 128 barcode's size to 200 × 100 pixels and saving it as a JPEG file. +/// Example program that generates a GS1 Code 128 barcode, +/// customizes its image size, and saves it as a JPEG file. /// class Program { /// - /// Entry point of the example. Generates the barcode, configures size, and saves the image. + /// Entry point of the application. + /// Creates a barcode, configures size, and writes the output image. /// static void Main() { - // Create a GS1 Code 128 barcode generator with sample GS1 data - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, "(01)12345678901231")) + // Initialize a barcode generator for the GS1 Code 128 symbology + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128)) { - // Enable automatic sizing mode that respects explicit image dimensions - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; + // Assign a valid GS1 Code 128 codetext (GTIN‑14 example) + generator.CodeText = "(01)12345678901231"; - // Set the desired image width to 200 pixels - generator.Parameters.ImageWidth.Point = 200f; + // Set the desired canvas dimensions: 200 × 100 pixels + generator.Parameters.ImageWidth.Pixels = 200f; + generator.Parameters.ImageHeight.Pixels = 100f; - // Set the desired image height to 100 pixels - generator.Parameters.ImageHeight.Point = 100f; + // Enable interpolation to scale the barcode to fit the specified canvas + generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; - // Save the generated barcode as a JPEG image file + // Save the generated barcode as a JPEG image generator.Save("gs1code128.jpg"); } + + // Inform the user that the barcode has been created + Console.WriteLine("Barcode generated and saved as gs1code128.jpg"); } } \ No newline at end of file diff --git a/gs1-barcode-types/set-foreground-color-to-blue-and-background-color-to-white-for-gs1-datamatrix-barcode.cs b/gs1-barcode-types/set-foreground-color-to-blue-and-background-color-to-white-for-gs1-datamatrix-barcode.cs index 2d51997..cd76ab5 100644 --- a/gs1-barcode-types/set-foreground-color-to-blue-and-background-color-to-white-for-gs1-datamatrix-barcode.cs +++ b/gs1-barcode-types/set-foreground-color-to-blue-and-background-color-to-white-for-gs1-datamatrix-barcode.cs @@ -1,11 +1,10 @@ -// Title: Set colors for GS1 DataMatrix barcode -// Description: Demonstrates how to set the foreground color to blue and background color to white when generating a GS1 DataMatrix barcode using Aspose.BarCode. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on visual customization of barcodes. It showcases the use of BarcodeGenerator, EncodeTypes, and color properties to control appearance, a common requirement for branding and readability in applications that generate DataMatrix symbols. +// Title: Set colors for a GS1 DataMatrix barcode +// Description: Demonstrates how to generate a GS1 DataMatrix barcode image with a blue foreground and white background. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and Parameters to customize barcode appearance. Developers often need to adjust colors for branding or readability when creating DataMatrix barcodes for product identification, packaging, or inventory systems. // Prompt: Set foreground color to blue and background color to white for a GS1 DataMatrix barcode. -// Tags: datamatrix, gs1, color, foreground, background, png, aspose.barcode, generation +// Tags: gs1 datamatrix, color, png, barcodegenerator, aspose.barcode using System; -using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.Drawing; @@ -15,30 +14,27 @@ class Program { /// - /// Entry point of the example. Creates a GS1 DataMatrix barcode, sets its colors, and saves it as a PNG file. + /// Entry point of the example. Creates and saves a colored GS1 DataMatrix barcode image. /// static void Main() { - // Define the GS1 DataMatrix code text (GTIN example) - string codeText = "(01)12345678901231"; + // Sample GS1 DataMatrix code text with AI (01) and a 14‑digit GTIN + string codeText = "(01)00123456789012"; - // Initialize the barcode generator for GS1 DataMatrix with the specified text + // Initialize the barcode generator for GS1 DataMatrix using the specified code text using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Set the foreground (bars) color to blue - generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Blue; + // Set the barcode's foreground (bars) color to blue + generator.Parameters.Barcode.BarColor = Color.Blue; - // Set the background color to white - generator.Parameters.BackColor = Aspose.Drawing.Color.White; + // Set the image background color to white + generator.Parameters.BackColor = Color.White; - // Define the output file path and format (PNG) - string outputPath = "gs1datamatrix.png"; - - // Save the generated barcode image to the file system - generator.Save(outputPath, BarCodeImageFormat.Png); - - // Inform the user where the barcode image was saved - Console.WriteLine($"Barcode saved to {outputPath}"); + // Save the generated barcode as a PNG image file + generator.Save("gs1datamatrix.png"); } + + // Inform the user that the barcode image has been created + Console.WriteLine("GS1 DataMatrix barcode generated: gs1datamatrix.png"); } } \ No newline at end of file