From 4335bed8fb9005191ab1aa1d201ed2d5f7fc697f Mon Sep 17 00:00:00 2001 From: agent-aspose-barcode-examples Date: Tue, 4 Aug 2026 14:10:35 +0500 Subject: [PATCH] =?UTF-8?q?feat(barcode-text-customization):=20Add=2029=20?= =?UTF-8?q?Aspose.BarCode=20.NET=20C#=20examples=20for=20Barcode=20Text=20?= =?UTF-8?q?Customization=20=E2=80=94=20Aspose.BarCode=20for=20.NET=2026.7.?= =?UTF-8?q?0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...t-to-4-points-for-high-density-qr-codes.cs | 35 ++-- ...c-barcodes-by-setting-textalignmentleft.cs | 79 ++++---- ...stopalignment-to-captionalignmentcenter.cs | 25 ++- ...nt-and-captionparametersfont-separately.cs | 44 ++--- ...lates-optimal-font-size-for-each-symbol.cs | 61 +++--- ...file-applying-unique-font-sizes-per-row.cs | 96 +++++----- ...ametersalignment-to-textalignmentcenter.cs | 66 +++---- ...ied-fonts-for-large-batches-of-qr-codes.cs | 96 +++++----- ...sible-each-aligned-left-for-consistency.cs | 38 ++-- ...-style-for-all-generated-code39-symbols.cs | 23 ++- ...erated-aztec-barcodes-to-match-branding.cs | 46 ++--- ...padded-10-pixels-and-centered-alignment.cs | 66 +++---- ...-to-prevent-line-breaks-in-long-strings.cs | 46 ++--- ...alignment-and-spacing-settings-in-image.cs | 126 +++++++++---- ...-based-alignment-for-scalable-rendering.cs | 66 ++++--- ...o-display-supplemental-information-only.cs | 52 ++--- ...tionparametersvisible-to-false-globally.cs | 58 +++--- ...ting-codetextparametersvisible-to-false.cs | 69 ++++--- ...sers-to-toggle-visibility-and-alignment.cs | 77 ++++---- ...extparameterslocation-textlocationabove.cs | 32 ++-- ...m-url-by-setting-codetextparameterstext.cs | 36 ++-- ...tparametersalignment-textalignmentright.cs | 35 ++-- ...-recreate-identical-barcode-appearances.cs | 177 ++++++++++-------- ...using-default-textlocationbelow-setting.cs | 35 ++-- ...f-aztec-barcodes-to-improve-readability.cs | 50 ++--- ...to-create-visual-separation-from-symbol.cs | 37 ++-- ...tting-codetextparametersvisible-to-true.cs | 55 ++++-- ...ing-captionparameterstopvisible-to-true.cs | 34 ++-- ...ectly-shows-and-hides-main-barcode-text.cs | 133 +++++++++---- 29 files changed, 1021 insertions(+), 772 deletions(-) diff --git a/barcode-text-customization/adjust-gap-between-barcode-and-its-text-to-4-points-for-high-density-qr-codes.cs b/barcode-text-customization/adjust-gap-between-barcode-and-its-text-to-4-points-for-high-density-qr-codes.cs index 1d6a8ae..f52c1b8 100644 --- a/barcode-text-customization/adjust-gap-between-barcode-and-its-text-to-4-points-for-high-density-qr-codes.cs +++ b/barcode-text-customization/adjust-gap-between-barcode-and-its-text-to-4-points-for-high-density-qr-codes.cs @@ -1,37 +1,44 @@ -// Title: Adjust QR Code Text Gap for High‑Density QR Barcodes -// Description: Demonstrates how to set a 4‑point gap between a high‑density QR code and its human‑readable text. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on QR code customization. It showcases the use of BarcodeGenerator, EncodeTypes, QRErrorLevel, and CodeTextParameters to control visual layout. Developers often need to fine‑tune text positioning for readability and aesthetic requirements in printed or digital media. +// Title: Adjust QR Code Text Gap for High‑Density QR Codes +// Description: Demonstrates how to set the spacing between a QR code and its human‑readable text to 4 points, using Aspose.BarCode for a high‑density QR with error correction level H. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to configure QR code parameters such as error correction level, text location, and text‑barcode gap. It showcases the use of BarcodeGenerator, EncodeTypes, and CodeTextParameters classes—common tasks for developers creating printable or screen‑displayed barcodes with customized appearance. // Prompt: Adjust the gap between barcode and its text to 4 points for high‑density QR codes. -// Tags: qr, gap adjustment, png, barcodegenerator, codetextparameters, qrcodes, aspnet +// Tags: qr, barcode, text-gap, high-density, aspose.barcode, generation, png using System; +using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Demonstrates adjusting the space between a QR code and its human‑readable text. +/// Generates a high‑density QR code and sets a 4‑point gap between the barcode and its human‑readable text. /// class Program { /// - /// Entry point. Generates a high‑density QR code with a 4‑point text gap and saves it as PNG. + /// Entry point of the example. Creates a QR code, configures its parameters, and saves it as a PNG file. /// static void Main() { - // Initialize a QR code generator with sample text - using (var generator = new BarcodeGenerator(EncodeTypes.QR, "High density QR example")) + // Define the output file path in the current working directory. + string outputPath = Path.Combine(Directory.GetCurrentDirectory(), "high_density_qr.png"); + + // Initialize the QR code generator with sample text. + using (var generator = new BarcodeGenerator(EncodeTypes.QR, "https://example.com")) { - // Set QR error correction level to high (Level H) for higher density + // Set a high error correction level (Level H) to increase data density. generator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelH; - // Adjust the gap between the barcode and its human‑readable text to 4 points + // Position the human‑readable text below the QR code. + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; + + // Adjust the gap (space) between the QR code and its text to 4 points. generator.Parameters.Barcode.CodeTextParameters.Space.Point = 4f; - // Save the generated barcode image as PNG - generator.Save("HighDensityQR.png"); + // Save the generated QR code image as a PNG file. + generator.Save(outputPath, BarCodeImageFormat.Png); } - // Inform the user that the QR code has been generated - Console.WriteLine("QR code generated and saved as HighDensityQR.png"); + // Inform the user where the QR code image was saved. + Console.WriteLine($"QR code saved to: {outputPath}"); } } \ No newline at end of file diff --git a/barcode-text-customization/align-barcode-text-left-for-series-of-upc-barcodes-by-setting-textalignmentleft.cs b/barcode-text-customization/align-barcode-text-left-for-series-of-upc-barcodes-by-setting-textalignmentleft.cs index a53ad7a..4a96903 100644 --- a/barcode-text-customization/align-barcode-text-left-for-series-of-upc-barcodes-by-setting-textalignmentleft.cs +++ b/barcode-text-customization/align-barcode-text-left-for-series-of-upc-barcodes-by-setting-textalignmentleft.cs @@ -1,53 +1,62 @@ -// Title: Align UPC‑A barcode text to the left -// Description: Demonstrates how to set the human‑readable text alignment to the left for a series of UPC‑A barcodes and save them as PNG images. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and TextAlignment to customize barcode appearance. Developers often need to adjust text positioning for branding or layout requirements when generating barcodes programmatically. +// Title: Left-align human‑readable text for UPC‑A barcodes +// Description: Demonstrates generating multiple UPC‑A barcodes with the human‑readable text aligned to the left using Aspose.BarCode. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to configure CodeTextParameters (Alignment, Location) for barcode images. It shows typical usage of BarcodeGenerator, EncodeTypes, and BarCodeImageFormat to produce PNG files, a common requirement for developers creating printable or displayable barcodes in .NET applications. // Prompt: Align barcode text left for a series of UPC‑A barcodes by setting TextAlignment.Left. -// Tags: upc-a, text alignment, left, png, barcode generation, aspose.barcode, c# +// Tags: upc-a, text-alignment, png, aspose.barcode, generation using System; +using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; -namespace BarcodeExample +/// +/// Generates a set of UPC‑A barcode images with left‑aligned human‑readable text. +/// +class Program { /// - /// Demonstrates aligning the human‑readable text of UPC‑A barcodes to the left and saving them as PNG files. + /// Entry point of the example. Creates an output folder, iterates over sample UPC‑A codes, + /// configures text alignment, and saves each barcode as a PNG file. /// - class Program + static void Main() { - /// - /// Entry point. Generates several UPC‑A barcodes with left‑aligned text and writes each to a PNG file. - /// - static void Main() + // Define the output directory for generated barcode images + string outputDir = "Barcodes"; + + // Create the directory if it does not already exist + if (!Directory.Exists(outputDir)) + Directory.CreateDirectory(outputDir); + + // Sample UPC‑A codes (each code must contain exactly 12 digits) + string[] upcCodes = new string[] { - // Define a collection of sample UPC‑A codes (each code must contain 12 digits) - string[] upcCodes = new string[] - { - "012345678905", - "123456789012", - "234567890123", - "345678901234", - "456789012345" - }; - - // Iterate over each code, generate a barcode, and save it as a PNG image - for (int i = 0; i < upcCodes.Length; i++) + "012345678905", + "123456789012", + "036000291452", + "070123456789", + "041000005264" + }; + + // Process each UPC‑A code + foreach (string code in upcCodes) + { + // Initialize a barcode generator for the UPC‑A symbology with the current code + using (var generator = new BarcodeGenerator(EncodeTypes.UPCA, code)) { - string code = upcCodes[i]; - string fileName = $"upc_a_{i + 1}.png"; + // Align the human‑readable text to the left side of the barcode + generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Left; + + // Ensure the text appears below the bars (explicitly set for clarity) + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; - // Create a BarcodeGenerator for the UPC‑A symbology with the current code - using (var generator = new BarcodeGenerator(EncodeTypes.UPCA, code)) - { - // Set the human‑readable text alignment to the left side of the barcode - generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Left; + // Build the full file path for the PNG image + string filePath = Path.Combine(outputDir, $"{code}.png"); - // Save the generated barcode image to a PNG file - generator.Save(fileName); - } + // Save the generated barcode image in PNG format + generator.Save(filePath, BarCodeImageFormat.Png); - // Output the name of the saved file to the console for verification - Console.WriteLine($"Saved {fileName}"); + // Output a confirmation message to the console + Console.WriteLine($"Saved barcode for {code} to {filePath}"); } } } diff --git a/barcode-text-customization/align-top-caption-to-center-for-qr-codes-by-setting-captionparameterstopalignment-to-captionalignmentcenter.cs b/barcode-text-customization/align-top-caption-to-center-for-qr-codes-by-setting-captionparameterstopalignment-to-captionalignmentcenter.cs index cc936cb..ccbd20a 100644 --- a/barcode-text-customization/align-top-caption-to-center-for-qr-codes-by-setting-captionparameterstopalignment-to-captionalignmentcenter.cs +++ b/barcode-text-customization/align-top-caption-to-center-for-qr-codes-by-setting-captionparameterstopalignment-to-captionalignmentcenter.cs @@ -1,25 +1,24 @@ -// Title: Align QR Code Top Caption to Center -// Description: Demonstrates how to center a top caption on a QR code using Aspose.BarCode. -// Category-Description: This example belongs to the Aspose.BarCode generation category, focusing on customizing barcode captions. It shows how to use the BarcodeGenerator class along with CaptionParameters to modify caption text and alignment. Developers often need to add descriptive text above or below barcodes and control its positioning for better visual integration in documents and UI. +// Title: Center Top Caption on QR Code using Aspose.BarCode +// Description: Demonstrates generating a QR code image with a top caption that is horizontally centered. Shows how to configure caption text, alignment, and font size using Aspose.BarCode API. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to work with BarcodeGenerator, EncodeTypes, and CaptionParameters to customize barcode appearance. Developers often need to add readable text above or below barcodes for branding, instructions, or product information; this snippet shows the typical steps for setting caption text, alignment, and styling before saving the image. // Prompt: Align top caption to center for QR codes by setting CaptionParameters.Top.Alignment to CaptionAlignment.Center. -// Tags: qr code, caption alignment, barcode generation, aspose.barcode, image output +// Tags: qr code, caption alignment, barcode generation, aspose.barcode, png output using System; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Example program that creates a QR code with a centered top caption. +/// Generates a QR code with a centered top caption and saves it as a PNG image. /// class Program { /// - /// Entry point of the application. Generates a QR code, adds a top caption, - /// centers the caption, and saves the image to a file. + /// Entry point of the example. Creates a QR code, configures a centered top caption, and writes the result to disk. /// static void Main() { - // Initialize a QR code generator with the desired text. + // Initialize a QR code generator with the desired data. using (var generator = new BarcodeGenerator(EncodeTypes.QR, "https://example.com")) { // Set the text for the caption that appears above the barcode. @@ -28,8 +27,14 @@ static void Main() // Center the top caption horizontally. generator.Parameters.CaptionAbove.Alignment = TextAlignment.Center; - // Save the generated barcode image with the centered caption to a PNG file. - generator.Save("qr_with_centered_top_caption.png"); + // Optionally increase the font size for better readability. + generator.Parameters.CaptionAbove.Font.Size.Point = 12f; + + // Save the generated barcode with the caption to a PNG file. + generator.Save("qr_with_caption.png"); } + + // Inform the user that the image has been created. + Console.WriteLine("QR code with centered top caption generated successfully."); } } \ No newline at end of file diff --git a/barcode-text-customization/apply-different-fonts-to-main-text-and-caption-by-setting-codetextparametersfont-and-captionparametersfont-separately.cs b/barcode-text-customization/apply-different-fonts-to-main-text-and-caption-by-setting-codetextparametersfont-and-captionparametersfont-separately.cs index bdad418..4f280ee 100644 --- a/barcode-text-customization/apply-different-fonts-to-main-text-and-caption-by-setting-codetextparametersfont-and-captionparametersfont-separately.cs +++ b/barcode-text-customization/apply-different-fonts-to-main-text-and-caption-by-setting-codetextparametersfont-and-captionparametersfont-separately.cs @@ -1,8 +1,8 @@ -// Title: Apply distinct fonts to barcode text and caption +// Title: Applying distinct fonts to barcode text and caption // Description: Demonstrates how to set separate fonts for the main barcode text and an above‑barcode caption using Aspose.BarCode. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, CodeTextParameters, and CaptionParameters to customize human‑readable text. Developers often need to style barcode text and captions differently for branding or readability, and this snippet shows the typical API calls for such customizations. -// Prompt: Apply different fonts to main text and caption by setting CodetextParameters.Font and CaptionParameters.Font separately. -// Tags: barcode, code128, font, caption, generation, aspose.barcode, codetextparameters, captionparameters, png +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, CodeTextParameters, and CaptionParameters to customize text appearance. Developers often need to adjust fonts for readability or branding when creating barcodes for labels, packaging, or documents. +/// Prompt: Apply different fonts to main text and caption by setting CodetextParameters.Font and CaptionParameters.Font separately. +/// Tags: code128, font, caption, png, barcodegenerator, aspose.barcode using System; using Aspose.BarCode; @@ -10,37 +10,37 @@ using Aspose.Drawing; /// -/// Demonstrates applying different fonts to the barcode's main text and its caption. +/// Demonstrates setting different fonts for barcode code text and caption. /// class Program { /// - /// Generates a Code128 barcode with custom fonts for the code text and caption, then saves it as PNG. + /// Entry point. Generates a Code128 barcode with custom fonts for the code text and caption, then saves it as PNG. /// static void Main() { - // Initialize a barcode generator for the Code128 symbology - using (var generator = new BarcodeGenerator(EncodeTypes.Code128)) + // Initialize a barcode generator for Code128 with the sample code text "12345" + using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "12345")) { - // Set the value to be encoded in the barcode - generator.CodeText = "123ABC"; - - // Configure the font for the main (human‑readable) barcode text - generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial"; + // Configure the font for the human‑readable code text (main text) + generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Helvetica"; generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f; - // Enable and configure a caption displayed above the barcode - generator.Parameters.CaptionAbove.Visible = true; + // Set up a caption above the barcode and assign a different font generator.Parameters.CaptionAbove.Text = "Sample Caption"; - generator.Parameters.CaptionAbove.Font.FamilyName = "Times New Roman"; + generator.Parameters.CaptionAbove.Font.FamilyName = "Courier"; generator.Parameters.CaptionAbove.Font.Size.Point = 10f; - generator.Parameters.CaptionAbove.Alignment = TextAlignment.Center; + generator.Parameters.CaptionAbove.Visible = true; - // Save the generated barcode image to a PNG file - generator.Save("barcode.png"); - } + // Ensure the main code text appears below the barcode bars + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; + + // Define the output file path and save the barcode as a PNG image + string outputPath = "barcode.png"; + generator.Save(outputPath, BarCodeImageFormat.Png); - // Inform the user that the barcode has been generated - Console.WriteLine("Barcode generated successfully."); + // Inform the user where the file was saved + Console.WriteLine($"Barcode saved to {outputPath}"); + } } } \ No newline at end of file diff --git a/barcode-text-customization/apply-fontmodeauto-to-barcode-text-so-library-automatically-calculates-optimal-font-size-for-each-symbol.cs b/barcode-text-customization/apply-fontmodeauto-to-barcode-text-so-library-automatically-calculates-optimal-font-size-for-each-symbol.cs index a904d7e..f9a8017 100644 --- a/barcode-text-customization/apply-fontmodeauto-to-barcode-text-so-library-automatically-calculates-optimal-font-size-for-each-symbol.cs +++ b/barcode-text-customization/apply-fontmodeauto-to-barcode-text-so-library-automatically-calculates-optimal-font-size-for-each-symbol.cs @@ -1,45 +1,50 @@ -// Title: Apply FontMode.Auto for Automatic Font Sizing in Barcode Generation -// Description: Demonstrates how to enable automatic font size calculation for barcode text using Aspose.BarCode, ensuring optimal readability across different symbols. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, showcasing the use of BarcodeGenerator, EncodeTypes, and CodeTextParameters to customize text rendering. Developers often need to adjust font sizing, image dimensions, and auto‑size modes when creating barcodes for labels, packaging, or inventory systems. The snippet illustrates typical API calls for setting FontMode, AutoSizeMode, and image size. +// Title: Automatic Font Size for Barcode Text using FontMode.Auto +// Description: Demonstrates how to enable FontMode.Auto so Aspose.BarCode automatically determines the optimal font size for each barcode symbol. +// Category-Description: This example belongs to the Aspose.BarCode generation category, showcasing the use of BarcodeGenerator, EncodeTypes, and FontMode to control text rendering. Developers often need to adjust barcode text appearance for readability and layout constraints; FontMode.Auto provides a convenient way to let the library calculate the best font size per symbol, useful in dynamic image generation and reporting scenarios. // Prompt: Apply FontMode.Auto to barcode text so the library automatically calculates optimal font size for each symbol. -// Tags: code128, fontmode, autosize, png, barcodelibrary, generation, aspnet, csharp +// Tags: barcode, fontmode, auto, code128, generation, image, aspose.barcode using System; +using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; -/// -/// Demonstrates applying FontMode.Auto to barcode text for automatic font sizing. -/// -class Program +namespace BarcodeFontModeExample { /// - /// Entry point of the example. Generates a Code128 barcode with automatic font size calculation and saves it as a PNG file. + /// Demonstrates applying FontMode.Auto to barcode text for automatic font sizing. /// - static void Main() + class Program { - // Output file path for the generated barcode image - string outputPath = "barcode.png"; - - // Initialize a BarcodeGenerator for Code128 symbology - using (var generator = new BarcodeGenerator(EncodeTypes.Code128)) + /// + /// Entry point that creates a Code128 barcode with automatic font size and saves it as PNG. + /// + static void Main() { - // Set the data to encode in the barcode - generator.CodeText = "1234567890"; + // Define the output file path for the generated barcode image. + string outputPath = "barcode.png"; - // Enable automatic font size calculation for the barcode text - generator.Parameters.Barcode.CodeTextParameters.FontMode = FontMode.Auto; + // Ensure a clean start by deleting any existing file with the same name. + if (File.Exists(outputPath)) + { + File.Delete(outputPath); + } - // Optional: configure auto‑size mode and define image dimensions - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; - generator.Parameters.ImageWidth.Point = 300f; - generator.Parameters.ImageHeight.Point = 150f; + // Initialize the barcode generator for the Code128 symbology. + using (var generator = new BarcodeGenerator(EncodeTypes.Code128)) + { + // Set the text that will be encoded into the barcode. + generator.CodeText = "123ABC"; - // Save the generated barcode image to the specified file - generator.Save(outputPath); - } + // Enable automatic font size calculation for the barcode text. + generator.Parameters.Barcode.CodeTextParameters.FontMode = FontMode.Auto; - // Inform the user where the barcode image was saved - Console.WriteLine($"Barcode image saved to: {outputPath}"); + // Save the generated barcode image to the specified path. + generator.Save(outputPath); + } + + // Inform the user where the barcode image has been saved. + Console.WriteLine($"Barcode image saved to: {Path.GetFullPath(outputPath)}"); + } } } \ No newline at end of file diff --git a/barcode-text-customization/batch-generate-qr-codes-with-custom-texts-from-csv-file-applying-unique-font-sizes-per-row.cs b/barcode-text-customization/batch-generate-qr-codes-with-custom-texts-from-csv-file-applying-unique-font-sizes-per-row.cs index 60e4ac6..5385048 100644 --- a/barcode-text-customization/batch-generate-qr-codes-with-custom-texts-from-csv-file-applying-unique-font-sizes-per-row.cs +++ b/barcode-text-customization/batch-generate-qr-codes-with-custom-texts-from-csv-file-applying-unique-font-sizes-per-row.cs @@ -1,92 +1,100 @@ // Title: Batch QR Code Generation from CSV with Custom Font Sizes -// Description: Demonstrates reading a CSV file and generating QR code images, each using a distinct text and font size. -// Category-Description: This example belongs to the Aspose.BarCode generation category, showcasing how to use BarcodeGenerator, EncodeTypes, and QRErrorLevel to create QR codes in bulk. Typical use cases include batch processing of product identifiers, marketing materials, or any scenario where each barcode requires custom human‑readable text styling. Developers often need to read data sources, apply per‑row formatting, and output images in common formats like PNG. +// Description: Demonstrates how to read text and font size values from a CSV file and generate QR code images, applying a unique font size for each barcode's human‑readable text. +// Category-Description: This example is part of the Aspose.BarCode barcode generation collection, showcasing the use of BarcodeGenerator, QR encoding, and CodeTextParameters to customize output. It illustrates typical batch processing scenarios where developers create multiple barcodes from external data sources (e.g., CSV files) and need per‑item visual customization such as font size. Ideal for automating label creation, inventory tagging, or marketing material generation. // Prompt: Batch generate QR codes with custom texts from a CSV file, applying unique font sizes per row. -// Tags: qr,barcode,generation,csv,fontsize,aspose.barcode,aspose.drawing +// Tags: qr, barcode, generation, csv, font size, aspose.barcode using System; using System.IO; using System.Globalization; -using System.Linq; using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.Drawing; /// -/// Demonstrates batch generation of QR codes from a CSV file, applying custom font sizes per row. +/// Generates QR codes in batch by reading text and font size values from a CSV file. +/// Each QR code is saved as a PNG image with the specified font size applied to the +/// human‑readable text displayed below the barcode. /// class Program { /// - /// Entry point. Reads the CSV, creates QR codes with specified text and font size, and saves them as PNG files. + /// Entry point of the application. Handles CSV processing, QR code creation, + /// and image output. No interactive console input is required. /// static void Main() { - // Path to the CSV file. Each line should contain: Text,FontSize + // Define input CSV path and output folder for generated images string csvPath = "input.csv"; + string outputFolder = "Output"; - // If the CSV does not exist, create a small sample file (5 rows) to keep the example runnable. + // Ensure the output directory exists + if (!Directory.Exists(outputFolder)) + { + Directory.CreateDirectory(outputFolder); + } + + // If the CSV file is missing, create a sample file with example rows if (!File.Exists(csvPath)) { - using (var writer = new StreamWriter(csvPath)) + string[] sampleLines = { - writer.WriteLine("Hello World,12"); - writer.WriteLine("Aspose.BarCode,14"); - writer.WriteLine("QR Code Sample,16"); - writer.WriteLine("Sample Text,10"); - writer.WriteLine("Final Row,18"); - } + "Hello World,12", + "Aspose.BarCode,14", + "QR Code Sample,10", + "Custom Text,16", + "Sample 5,11" + }; + File.WriteAllLines(csvPath, sampleLines); } - // Read all non‑empty lines from the CSV. + // Read all lines from the CSV file string[] lines = File.ReadAllLines(csvPath); - int rowIndex = 0; + int index = 1; - foreach (string rawLine in lines) + // Process each non‑empty line + foreach (string line in lines) { - // Skip blank lines. - if (string.IsNullOrWhiteSpace(rawLine)) + if (string.IsNullOrWhiteSpace(line)) continue; - rowIndex++; - - // Split by comma – expected format: Text,FontSize - string[] parts = rawLine.Split(new[] { ',' }, 2); + // Split the line by comma: first part = text, second part = font size + string[] parts = line.Split(','); if (parts.Length < 2) { - Console.WriteLine($"Skipping line {rowIndex}: insufficient columns."); + Console.WriteLine($"Skipping invalid line {index}: '{line}'"); continue; } - string text = parts[0].Trim(); - string fontSizeStr = parts[1].Trim(); + string codeText = parts[0].Trim(); - // Parse font size; fallback to a default size if parsing fails. - if (!float.TryParse(fontSizeStr, NumberStyles.Float, CultureInfo.InvariantCulture, out float fontSize)) + // Parse the font size; fall back to 12 if parsing fails + if (!float.TryParse(parts[1].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out float fontSize)) { - Console.WriteLine($"Invalid font size on line {rowIndex}, using default 12pt."); + Console.WriteLine($"Invalid font size on line {index}, using default 12."); fontSize = 12f; } - // Prepare output file name – ensure a valid file name per row. - string safeText = string.Concat(Array.FindAll(text.ToCharArray(), c => !Path.GetInvalidFileNameChars().Contains(c))); - string outputFile = $"qr_{rowIndex}_{safeText}.png"; - - // Generate QR code with the specified text and font size. - using (var generator = new BarcodeGenerator(EncodeTypes.QR, text)) + // Create a QR code generator with the specified text + using (var generator = new BarcodeGenerator(EncodeTypes.QR, codeText)) { - // Set human‑readable text font family and size. - generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial"; + // Display the human‑readable text below the QR code + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; + + // Apply the custom font size to the code text generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = fontSize; - // Optional: set QR error correction level (default is LevelL). - generator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelM; + // Optional: set a high error correction level for better resilience + generator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelH; + + // Build the output file name (e.g., qr_1.png) + string outputPath = Path.Combine(outputFolder, $"qr_{index}.png"); - // Save the barcode image. - generator.Save(outputFile); + // Save the generated QR code image + generator.Save(outputPath); + Console.WriteLine($"Generated QR code {index}: '{codeText}' with font size {fontSize} -> {outputPath}"); } - Console.WriteLine($"Generated QR code for row {rowIndex}: \"{text}\" with font size {fontSize}pt -> {outputFile}"); + index++; } Console.WriteLine("Batch QR code generation completed."); diff --git a/barcode-text-customization/centeralign-barcode-text-for-collection-of-ean-13-barcodes-by-setting-codetextparametersalignment-to-textalignmentcenter.cs b/barcode-text-customization/centeralign-barcode-text-for-collection-of-ean-13-barcodes-by-setting-codetextparametersalignment-to-textalignmentcenter.cs index 4601f9a..37600b4 100644 --- a/barcode-text-customization/centeralign-barcode-text-for-collection-of-ean-13-barcodes-by-setting-codetextparametersalignment-to-textalignmentcenter.cs +++ b/barcode-text-customization/centeralign-barcode-text-for-collection-of-ean-13-barcodes-by-setting-codetextparametersalignment-to-textalignmentcenter.cs @@ -1,8 +1,8 @@ -// Title: Center-align EAN‑13 barcode text -// Description: Demonstrates generating EAN‑13 barcodes with the human‑readable text centered beneath the bars. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use BarcodeGenerator, CodetextParameters, and TextAlignment to control the appearance of human‑readable text. Typical use cases include creating printable product labels where the text must be centered for aesthetic or regulatory reasons. Developers often need to adjust text alignment, font, and positioning when producing barcodes for packaging, inventory, or point‑of‑sale systems. +// Title: Center-align text for EAN‑13 barcodes using Aspose.BarCode +// Description: Demonstrates how to generate a set of EAN‑13 barcodes with the human‑readable text centered beneath each barcode. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to customize barcode appearance using the BarcodeGenerator and its Parameters properties. It shows typical usage of EncodeTypes, CodeTextParameters, and image export for common scenarios such as product labeling and inventory systems. Developers often need to adjust text alignment, font, and output format when creating barcodes programmatically. // Prompt: Center-align barcode text for a collection of EAN‑13 barcodes by setting CodetextParameters.Alignment to TextAlignment.Center. -// Tags: ean13, barcode, text alignment, center, aspose.barcode, png, generation +// Tags: ean-13, barcode, text-alignment, png, aspose.barcode, generation using System; using System.IO; @@ -10,58 +10,52 @@ using Aspose.BarCode.Generation; /// -/// Generates a set of EAN‑13 barcodes and saves them as PNG images with centered human‑readable text. +/// Generates multiple EAN‑13 barcodes with centered human‑readable text and saves them as PNG files. /// class Program { /// - /// Entry point of the example. Iterates over a list of sample codes, creates a barcode for each, - /// centers the text, and writes the image to the output folder. + /// Entry point of the example. Creates an output folder, iterates over sample codes, + /// configures text alignment, and saves each barcode image. /// static void Main() { + // Define the output folder for generated barcode images + string outputFolder = Path.Combine(Directory.GetCurrentDirectory(), "Barcodes"); + if (!Directory.Exists(outputFolder)) + { + // Create the folder if it does not exist + Directory.CreateDirectory(outputFolder); + } + // Sample EAN‑13 codes (12 digits; checksum will be calculated automatically) - string[] ean13Codes = new string[] + string[] ean13Codes = new[] { "123456789012", "987654321098", - "400638133393", - "590123412345", - "735135371234" + "555555555555", + "111111111111", + "222222222222" }; - // Ensure the output directory exists - string outputDir = "Barcodes"; - if (!Directory.Exists(outputDir)) - { - Directory.CreateDirectory(outputDir); - } - - int index = 1; - foreach (var code in ean13Codes) + // Generate a barcode for each sample code + for (int i = 0; i < ean13Codes.Length; i++) { - // Validate that the code length is either 12 or 13 digits - if (code.Length < 12 || code.Length > 13) - { - Console.WriteLine($"Skipping invalid code '{code}'. Must be 12 or 13 digits."); - continue; - } - - // Create a barcode generator for the current EAN‑13 code - using (var generator = new BarcodeGenerator(EncodeTypes.EAN13, code)) + // Initialize the barcode generator with EAN‑13 symbology and the current code text + using (var generator = new BarcodeGenerator(EncodeTypes.EAN13, ean13Codes[i])) { // Center‑align the human‑readable text beneath the barcode generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center; - // Build the full file path for the PNG image - string filePath = Path.Combine(outputDir, $"ean13_{index}.png"); + // Build the file path for the PNG image + string filePath = Path.Combine(outputFolder, $"EAN13_{i + 1}.png"); - // Save the barcode image in PNG format - generator.Save(filePath, BarCodeImageFormat.Png); - Console.WriteLine($"Saved barcode to {filePath}"); - } + // Save the barcode image to disk + generator.Save(filePath); - index++; + // Inform the user about the saved file + Console.WriteLine($"Saved barcode to: {filePath}"); + } } } } \ No newline at end of file diff --git a/barcode-text-customization/compare-rendering-performance-between-fontmodeauto-and-manually-specified-fonts-for-large-batches-of-qr-codes.cs b/barcode-text-customization/compare-rendering-performance-between-fontmodeauto-and-manually-specified-fonts-for-large-batches-of-qr-codes.cs index d04e81c..9eb5bbd 100644 --- a/barcode-text-customization/compare-rendering-performance-between-fontmodeauto-and-manually-specified-fonts-for-large-batches-of-qr-codes.cs +++ b/barcode-text-customization/compare-rendering-performance-between-fontmodeauto-and-manually-specified-fonts-for-large-batches-of-qr-codes.cs @@ -1,88 +1,92 @@ -// Title: QR Code Rendering Performance Comparison between FontMode.Auto and Manual Fonts -// Description: Demonstrates how to measure the generation time of QR codes using Aspose.BarCode with automatic font selection versus manually specified fonts. -// Category-Description: This example belongs to the Aspose.BarCode rendering performance category, showcasing the use of BarcodeGenerator, EncodeTypes, and CodeTextParameters.FontMode. Developers often need to benchmark barcode generation for large batches to choose optimal settings for speed and quality. The snippet illustrates typical use cases such as bulk QR code creation for marketing or inventory systems. +// Title: Benchmark FontMode.Auto vs Manual Font Settings for QR Code Generation +// Description: Demonstrates how to measure rendering performance when using FontMode.Auto compared with manually specified fonts while generating a batch of QR codes. +// Category-Description: This example belongs to the Aspose.BarCode performance benchmarking category. It shows how to use BarcodeGenerator, EncodeTypes, and CodeTextParameters to render QR codes, adjust FontMode, and evaluate rendering speed. Developers often need to compare automatic font sizing with explicit font settings to optimize batch barcode generation. // Prompt: Compare rendering performance between FontMode.Auto and manually specified fonts for large batches of QR codes. -// Tags: qr code, performance, fontmode, automatic, manual, aspnet, aspose.barcode, generation, benchmarking +// Tags: qr code, performance, fontmode, automatic font, manual font, aspose.barcode, barcode generation, png output using System; -using System.Diagnostics; using System.IO; +using System.Diagnostics; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing; /// -/// Demonstrates performance comparison of QR code generation using FontMode.Auto versus manual font settings. +/// Provides a simple benchmark that compares the rendering time of QR codes +/// when using FontMode.Auto versus manually specified font settings. /// class Program { /// - /// Entry point. Generates a set of QR codes with automatic and manual font modes, measures elapsed time, and outputs results. + /// Entry point of the application. Generates a batch of QR codes with two different + /// font configurations and measures the elapsed time for each approach. /// static void Main() { - // Number of QR codes to generate for each test case (kept small for safe execution) - const int sampleCount = 5; - // Sample text to encode (same for all barcodes) - const string sampleText = "https://www.example.com/performance-test"; + const int batchSize = 5; - // Prepare timers for each font mode - var autoTimer = new Stopwatch(); - var manualTimer = new Stopwatch(); + // Determine output folder and ensure it exists + string outputFolder = Path.Combine(Directory.GetCurrentDirectory(), "output"); + if (!Directory.Exists(outputFolder)) + { + Directory.CreateDirectory(outputFolder); + } - // Directory to store generated images - string outputDir = Path.Combine(Directory.GetCurrentDirectory(), "QrPerformance"); - if (!Directory.Exists(outputDir)) + // Prepare sample data for the QR codes + string[] sampleTexts = new string[batchSize]; + for (int i = 0; i < batchSize; i++) { - // Create the output folder if it does not exist - Directory.CreateDirectory(outputDir); + sampleTexts[i] = $"Sample QR {i + 1}"; } - // ---------- Test FontMode.Auto ---------- - for (int i = 0; i < sampleCount; i++) + // -------------------- Benchmark FontMode.Auto -------------------- + Stopwatch swAuto = new Stopwatch(); + swAuto.Start(); + + for (int i = 0; i < batchSize; i++) { - // Build file path for the current QR code image - string filePath = Path.Combine(outputDir, $"qr_auto_{i}.png"); - using (var generator = new BarcodeGenerator(EncodeTypes.QR, sampleText)) + using (var generator = new BarcodeGenerator(EncodeTypes.QR, sampleTexts[i])) { - // Ensure FontMode is Auto (default, but set explicitly for clarity) + // Enable automatic font sizing generator.Parameters.Barcode.CodeTextParameters.FontMode = FontMode.Auto; // Optional: set QR error correction level generator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelM; - // Start timing, generate the barcode, then stop timing - autoTimer.Start(); - generator.Save(filePath); - autoTimer.Stop(); + // Save the generated QR code image + string filePath = Path.Combine(outputFolder, $"auto_{i + 1}.png"); + generator.Save(filePath, BarCodeImageFormat.Png); } } - // ---------- Test FontMode.Manual ---------- - for (int i = 0; i < sampleCount; i++) + swAuto.Stop(); + + // -------------------- Benchmark Manual Font Specification -------------------- + Stopwatch swManual = new Stopwatch(); + swManual.Start(); + + for (int i = 0; i < batchSize; i++) { - // Build file path for the current QR code image - string filePath = Path.Combine(outputDir, $"qr_manual_{i}.png"); - using (var generator = new BarcodeGenerator(EncodeTypes.QR, sampleText)) + using (var generator = new BarcodeGenerator(EncodeTypes.QR, sampleTexts[i])) { - // Switch to manual font mode and specify font details + // Switch to manual font settings generator.Parameters.Barcode.CodeTextParameters.FontMode = FontMode.Manual; - generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial"; - generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f; // 12pt font + generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Helvetica"; + generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f; // Optional: set QR error correction level generator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelM; - // Start timing, generate the barcode, then stop timing - manualTimer.Start(); - generator.Save(filePath); - manualTimer.Stop(); + // Save the generated QR code image + string filePath = Path.Combine(outputFolder, $"manual_{i + 1}.png"); + generator.Save(filePath, BarCodeImageFormat.Png); } } - // Output aggregated timing results to the console - Console.WriteLine($"FontMode.Auto: Total time = {autoTimer.ElapsedMilliseconds} ms for {sampleCount} QR codes."); - Console.WriteLine($"FontMode.Manual: Total time = {manualTimer.ElapsedMilliseconds} ms for {sampleCount} QR codes."); - Console.WriteLine($"Average per QR (Auto): {(double)autoTimer.ElapsedMilliseconds / sampleCount:F2} ms"); - Console.WriteLine($"Average per QR (Manual): {(double)manualTimer.ElapsedMilliseconds / sampleCount:F2} ms"); + swManual.Stop(); + + // Output benchmark results + Console.WriteLine($"FontMode.Auto rendering time for {batchSize} QR codes: {swAuto.ElapsedMilliseconds} ms"); + Console.WriteLine($"Manual font rendering time for {batchSize} QR codes: {swManual.ElapsedMilliseconds} ms"); } } \ No newline at end of file diff --git a/barcode-text-customization/create-barcodes-where-both-main-text-and-bottom-caption-are-visible-each-aligned-left-for-consistency.cs b/barcode-text-customization/create-barcodes-where-both-main-text-and-bottom-caption-are-visible-each-aligned-left-for-consistency.cs index 6edd032..18f41ee 100644 --- a/barcode-text-customization/create-barcodes-where-both-main-text-and-bottom-caption-are-visible-each-aligned-left-for-consistency.cs +++ b/barcode-text-customization/create-barcodes-where-both-main-text-and-bottom-caption-are-visible-each-aligned-left-for-consistency.cs @@ -1,38 +1,46 @@ -// Title: Left-aligned main text and bottom caption in Code128 barcode -// Description: Demonstrates how to generate a Code128 barcode with visible main text and a bottom caption, both left‑aligned. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to customize human‑readable text and captions using the BarcodeGenerator and its Parameters properties. Developers often need to control text alignment, visibility, and positioning when creating barcodes for labels, packaging, or documentation. The snippet shows typical usage of EncodeTypes, TextAlignment, and Caption settings. -/// Prompt: Create barcodes where both main text and bottom caption are visible, each aligned left for consistency. -/// Tags: code128, barcode, text-alignment, caption, png, aspose.barcode, generation +// Title: Generate Code128 barcode with left-aligned main text and caption +// Description: Demonstrates how to create a Code128 barcode where both the primary code text and a custom bottom caption are displayed, each aligned to the left. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, CodeTextParameters, and CaptionBelow settings to control human‑readable text placement and alignment. Typical use cases include creating product labels, shipping tags, or inventory markers where consistent left alignment of text improves readability. Developers often need to customize text location, alignment, visibility, and colors when generating barcodes programmatically. +// Prompt: Create barcodes where both main text and bottom caption are visible, each aligned left for consistency. +// Tags: code128, barcode generation, text alignment, caption, aspose.barcode, image output using System; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing; /// -/// Generates a Code128 barcode with left‑aligned main text and a visible bottom caption. +/// Demonstrates generating a Code128 barcode with left‑aligned code text and a visible caption below. /// class Program { /// - /// Entry point. Creates the barcode, configures text alignment, and saves the image. + /// Entry point that creates the barcode, configures text and caption alignment, and saves the image. /// static void Main() { - // Initialize a BarcodeGenerator for Code128 with the main text "123ABC" - using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "123ABC")) + // Initialize a BarcodeGenerator for Code128 with the desired code text. + using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "12345")) { - // Align the human‑readable main text to the left + // Show the human‑readable code text below the barcode bars. + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; + // Align the code text to the left for consistent appearance. generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Left; - // Make the bottom caption visible and set its text - generator.Parameters.CaptionBelow.Visible = true; + // Configure a custom caption that appears below the barcode. generator.Parameters.CaptionBelow.Text = "Sample Caption"; - - // Align the bottom caption text to the left generator.Parameters.CaptionBelow.Alignment = TextAlignment.Left; + generator.Parameters.CaptionBelow.Visible = true; - // Save the generated barcode as a PNG image + // Optional visual styling: set barcode and background colors. + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; + + // Save the generated barcode image to a PNG file. generator.Save("barcode.png"); } + + // Inform the user that the barcode has been generated. + Console.WriteLine("Barcode generated: barcode.png"); } } \ No newline at end of file diff --git a/barcode-text-customization/define-barcode-text-font-as-arial-size-6-regular-style-for-all-generated-code39-symbols.cs b/barcode-text-customization/define-barcode-text-font-as-arial-size-6-regular-style-for-all-generated-code39-symbols.cs index 47a5604..b95b9c1 100644 --- a/barcode-text-customization/define-barcode-text-font-as-arial-size-6-regular-style-for-all-generated-code39-symbols.cs +++ b/barcode-text-customization/define-barcode-text-font-as-arial-size-6-regular-style-for-all-generated-code39-symbols.cs @@ -1,31 +1,38 @@ -// Title: Generate Code39 barcode with custom Arial 6pt font -// Description: Demonstrates how to set the human‑readable text font to Arial, size 6, regular style for a Code39 barcode using Aspose.BarCode. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating font customization for barcode text. It uses BarcodeGenerator, EncodeTypes, and CodeTextParameters classes to modify text appearance, a common requirement when integrating barcodes into printed materials or UI displays. Developers often need to adjust font family, size, and style to match branding or layout specifications. +// Title: Set custom font for Code39 barcode text +// Description: Demonstrates how to define the human‑readable text font (Arial, 6 pt, regular) for a Code39 barcode using Aspose.BarCode. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to customize barcode appearance with the BarcodeGenerator class. Typical use cases include setting font properties, text location, and saving the barcode as an image. Developers often need to adjust font settings to match branding or printing requirements. // Prompt: Define barcode text font as Arial, size 6, regular style for all generated Code39 symbols. -// Tags: code39, font, arial, size6, regular, barcode, generation, aspose.barcode +// Tags: code39, font, barcode generation, png, aspose.barcode, barcode text using System; +using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Example program that creates a Code39 barcode and sets the text font to Arial, 6pt, regular style. +/// Generates a Code39 barcode with custom font settings for the human‑readable text. /// class Program { /// - /// Main entry point. Generates the barcode, applies font settings, and saves the image. + /// Entry point of the example. Creates a barcode, configures font properties, and saves the image. /// static void Main() { - // Initialize the barcode generator for Code39 with the desired value. + // Initialize a Code39 barcode generator with the sample value "CODE39". using (var generator = new BarcodeGenerator(EncodeTypes.Code39, "CODE39")) { - // Configure the human‑readable text font: Arial family, 6 point size, regular style. + // Configure the font for the human‑readable text: Arial, 6 points, regular style. generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial"; generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 6f; + // Position the human‑readable text below the barcode graphic. + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; + // Save the generated barcode as a PNG image file. generator.Save("code39.png"); } + + // Inform the user that the barcode image has been saved. + Console.WriteLine("Barcode image saved as code39.png"); } } \ No newline at end of file diff --git a/barcode-text-customization/define-caption-font-as-times-new-roman-size-9-for-all-generated-aztec-barcodes-to-match-branding.cs b/barcode-text-customization/define-caption-font-as-times-new-roman-size-9-for-all-generated-aztec-barcodes-to-match-branding.cs index bc67c46..5979eb3 100644 --- a/barcode-text-customization/define-caption-font-as-times-new-roman-size-9-for-all-generated-aztec-barcodes-to-match-branding.cs +++ b/barcode-text-customization/define-caption-font-as-times-new-roman-size-9-for-all-generated-aztec-barcodes-to-match-branding.cs @@ -1,47 +1,47 @@ -// Title: Set caption font for Aztec barcode using Aspose.BarCode -// Description: Demonstrates how to define a Times New Roman, size 9 caption font for an Aztec barcode and save it as PNG. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to customize barcode captions using the BarcodeGenerator class. It shows setting caption text, font properties, and alignment—common tasks when branding barcodes for print or digital media. Developers often need to adjust caption appearance to match corporate style guidelines. +// Title: Generate Aztec Barcode with Times New Roman Caption Font +// Description: Creates an Aztec barcode image and sets the caption font to Times New Roman, size 9, demonstrating how to customize barcode captions using Aspose.BarCode. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and the Parameters.Caption* properties to customize barcode appearance. Typical scenarios include branding, adding descriptive text above or below barcodes, and exporting to common image formats. Developers often need to adjust fonts, sizes, and caption content to meet visual guidelines. // Prompt: Define caption font as Times New Roman, size 9, for all generated Aztec barcodes to match branding. -// Tags: aztec, barcode, caption, font, png, aspose.barcode, generation +// Tags: aztec, barcode, caption, font, times new roman, size9, generation, png, aspose.barcode, csharp using System; +using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.Drawing; /// -/// Generates an Aztec barcode with a caption styled in Times New Roman, size 9, -/// and saves the result as a PNG image. +/// Demonstrates how to generate an Aztec barcode and apply a custom caption font using Aspose.BarCode. /// class Program { /// - /// Entry point of the example. Creates the barcode, configures the caption, - /// and writes the image to disk. + /// Entry point of the example. Generates an Aztec barcode, sets caption fonts, and saves the image. /// static void Main() { - // Define the output file path for the generated barcode image. - string outputPath = "aztec_caption.png"; + // Define the output file name for the generated barcode image. + string outputFile = "aztec.png"; - // Initialize the barcode generator for Aztec symbology with sample data. - using (var generator = new BarcodeGenerator(EncodeTypes.Aztec, "Sample123")) + // Initialize the barcode generator for the Aztec symbology with sample text. + using (var generator = new BarcodeGenerator(EncodeTypes.Aztec, "Sample")) { - // Set optional caption text that will appear above the barcode. - generator.Parameters.CaptionAbove.Text = "Aztec Barcode"; - - // Apply the required font settings: Times New Roman, 9‑point size. + // Configure the caption font for the text displayed above the barcode. generator.Parameters.CaptionAbove.Font.FamilyName = "Times New Roman"; generator.Parameters.CaptionAbove.Font.Size.Point = 9f; - // Align the caption to the center of the barcode area. - generator.Parameters.CaptionAbove.Alignment = TextAlignment.Center; + // Configure the caption font for the text displayed below the barcode. + generator.Parameters.CaptionBelow.Font.FamilyName = "Times New Roman"; + generator.Parameters.CaptionBelow.Font.Size.Point = 9f; + + // Optional: set custom caption texts. + generator.Parameters.CaptionAbove.Text = "Aztec Barcode"; + generator.Parameters.CaptionBelow.Text = "Sample"; - // Render and save the barcode image in PNG format. - generator.Save(outputPath, BarCodeImageFormat.Png); + // Save the generated barcode image to the specified file. + generator.Save(outputFile); } - // Inform the user that the barcode has been saved successfully. - Console.WriteLine($"Aztec barcode saved to {outputPath}"); + // Output the full path of the saved barcode image for user reference. + Console.WriteLine($"Aztec barcode saved to: {Path.GetFullPath(outputFile)}"); } } \ No newline at end of file diff --git a/barcode-text-customization/develop-script-that-generates-datamatrix-barcodes-with-top-caption-padded-10-pixels-and-centered-alignment.cs b/barcode-text-customization/develop-script-that-generates-datamatrix-barcodes-with-top-caption-padded-10-pixels-and-centered-alignment.cs index 143ef34..150a737 100644 --- a/barcode-text-customization/develop-script-that-generates-datamatrix-barcodes-with-top-caption-padded-10-pixels-and-centered-alignment.cs +++ b/barcode-text-customization/develop-script-that-generates-datamatrix-barcodes-with-top-caption-padded-10-pixels-and-centered-alignment.cs @@ -1,6 +1,6 @@ -// Title: Generate DataMatrix barcode with top caption, padding and centered alignment -// Description: Creates a DataMatrix barcode image, adds a caption above it, pads the top by 10 pixels, and centers the caption. -// Category-Description: This example belongs to the Aspose.BarCode generation category, demonstrating how to customize barcode appearance using the BarcodeGenerator class. It covers setting caption text, alignment, and image padding—common tasks when integrating barcodes into reports, labels, or UI elements. Developers often need to adjust visual layout without altering the encoded data, and this snippet shows the essential API calls for such scenarios. +// Title: Generate DataMatrix barcode with top caption, padding, and centered alignment +// Description: Demonstrates creating a DataMatrix barcode, adding a top caption with 10‑pixel padding, and centering the text. The barcode is saved as a PNG image. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use BarcodeGenerator, EncodeTypes, and caption parameters to customize barcode appearance. Typical use cases include adding descriptive text above barcodes for labeling, packaging, or inventory systems. Developers often need to adjust caption styling, padding, and alignment to meet design requirements. // Prompt: Develop a script that generates DataMatrix barcodes with top caption padded 10 pixels and centered alignment. // Tags: datamatrix, caption, padding, alignment, png, aspose.barcode, generation @@ -9,44 +9,38 @@ using Aspose.BarCode.Generation; using Aspose.Drawing; -namespace DataMatrixCaptionExample +/// +/// Example program that creates a DataMatrix barcode with a top caption, +/// applies 10‑pixel top padding, centers the caption, and saves the result as a PNG file. +/// +class Program { /// - /// Demonstrates generating a DataMatrix barcode with a top caption, - /// applying 10‑pixel top padding and centering the caption text. + /// Entry point of the application. /// - class Program + static void Main() { - /// - /// Entry point of the example. Generates the barcode and saves it as a PNG file. - /// - static void Main() - { - // Define the output file path for the generated barcode image. - string outputPath = "datamatrix_caption.png"; - - // Initialize a BarcodeGenerator for DataMatrix with sample codetext. - using (var generator = new BarcodeGenerator(EncodeTypes.DataMatrix, "Sample123")) - { - // Set the caption text that will appear above the barcode. - generator.Parameters.CaptionAbove.Text = "Top Caption"; - - // Align the caption horizontally to the center. - generator.Parameters.CaptionAbove.Alignment = TextAlignment.Center; - - // Apply a 10‑pixel padding to the top side of the barcode image. - generator.Parameters.Barcode.Padding.Top.Pixels = 10f; + // Define the output file path for the generated barcode image. + const string outputPath = "datamatrix.png"; - // Optional visual settings: white background and black bars. - generator.Parameters.BackColor = Color.White; - generator.Parameters.Barcode.BarColor = Color.Black; - - // Save the configured barcode image to the specified path. - generator.Save(outputPath); - } - - // Inform the user that the barcode has been saved. - Console.WriteLine($"Barcode saved to {outputPath}"); + // Initialize a BarcodeGenerator for the DataMatrix symbology with sample text. + using (var generator = new BarcodeGenerator(EncodeTypes.DataMatrix, "Sample DataMatrix")) + { + // ----- Configure the top caption (CaptionAbove) ----- + generator.Parameters.CaptionAbove.Text = "Top Caption"; // Caption text + generator.Parameters.CaptionAbove.Font.FamilyName = "Helvetica"; // Font family + generator.Parameters.CaptionAbove.Font.Size.Point = 12f; // Font size in points + generator.Parameters.CaptionAbove.TextColor = Aspose.Drawing.Color.Black; // Text color + generator.Parameters.CaptionAbove.Alignment = TextAlignment.Center; // Center alignment + + // Apply a 10‑pixel top padding to the caption to create visual separation. + generator.Parameters.CaptionAbove.Padding.Top.Pixels = 10f; + + // Save the configured barcode as a PNG image to the specified path. + generator.Save(outputPath); } + + // Inform the user where the barcode image has been saved. + Console.WriteLine($"DataMatrix barcode saved to {outputPath}"); } } \ No newline at end of file diff --git a/barcode-text-customization/enable-nowrap-mode-for-barcode-text-on-datamatrix-barcodes-to-prevent-line-breaks-in-long-strings.cs b/barcode-text-customization/enable-nowrap-mode-for-barcode-text-on-datamatrix-barcodes-to-prevent-line-breaks-in-long-strings.cs index 4262984..ee4ed47 100644 --- a/barcode-text-customization/enable-nowrap-mode-for-barcode-text-on-datamatrix-barcodes-to-prevent-line-breaks-in-long-strings.cs +++ b/barcode-text-customization/enable-nowrap-mode-for-barcode-text-on-datamatrix-barcodes-to-prevent-line-breaks-in-long-strings.cs @@ -1,43 +1,47 @@ -// Title: Enable NoWrap mode for DataMatrix barcode text -// Description: Demonstrates how to prevent line breaks in the human‑readable text of a DataMatrix barcode by enabling NoWrap mode. -// Category-Description: This example belongs to the Aspose.BarCode generation category, focusing on barcode text formatting. It showcases the use of BarcodeGenerator, EncodeTypes, and CodeTextParameters to control text wrapping. Developers often need to adjust human‑readable text appearance for long strings in various symbologies, especially DataMatrix, to ensure readability in printed or displayed barcodes. -// Prompt: Enable NoWrap mode for barcode text on DataMatrix barcodes to prevent line breaks in long strings. -// Tags: datamatrix, nowrap, barcode, text-formatting, generation, csharp, aspnet, aspnetcore +// Title: Enable NoWrap Mode for DataMatrix Barcode Text +// Description: Demonstrates how to generate a DataMatrix barcode with long code text and prevent line‑breaks by enabling the NoWrap option. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating how to control human‑readable text rendering for 2‑D symbologies. It uses the BarcodeGenerator class and CodeTextParameters to adjust text location, wrapping, and font. Developers often need to customize barcode captions for readability and layout, especially when dealing with long strings in DataMatrix or QR codes. +/// Prompt: Enable NoWrap mode for barcode text on DataMatrix barcodes to prevent line breaks in long strings. +// Tags: datamatrix, no-wrap, text, png, barcodegenerator, codetextparameters using System; +using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Generates a DataMatrix barcode with NoWrap enabled to keep the human‑readable text on a single line. +/// Demonstrates enabling NoWrap mode for DataMatrix barcode text to keep long strings on a single line. /// class Program { /// - /// Entry point of the example. Creates a DataMatrix barcode from a long string and saves it as an image. + /// Generates a DataMatrix barcode with a long code text, disables text wrapping, and saves it as a PNG file. /// static void Main() { - // Define a long codetext that would wrap without NoWrap enabled. - string longText = "ThisIsAVeryLongStringThatMightWrapInTheHumanReadableTextIfNoWrapIsNotEnabled1234567890"; + // Define the output file path for the generated barcode image. + string outputPath = "datamatrix.png"; - // Initialize a DataMatrix barcode generator with the long text. - using (var generator = new BarcodeGenerator(EncodeTypes.DataMatrix, longText)) + // Create a long string (200 characters) that would normally cause text wrapping. + string codeText = new string('A', 200); + + // Initialize a DataMatrix barcode generator with the long code text. + using (var generator = new BarcodeGenerator(EncodeTypes.DataMatrix, codeText)) { - // Enable NoWrap mode to prevent line breaks in the displayed human‑readable text. - generator.Parameters.Barcode.CodeTextParameters.NoWrap = true; + // Position the human‑readable text below the barcode symbol. + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; - // Set auto‑size mode to Interpolation (optional) to ensure proper image scaling. - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; + // Disable automatic line wrapping so the text stays on a single line. + generator.Parameters.Barcode.CodeTextParameters.NoWrap = true; - // Define the output file path. - string outputPath = "datamatrix_nowrap.png"; + // Set a readable font size for the caption. + generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 8f; - // Save the generated barcode image to the specified path. - generator.Save(outputPath); + // Save the generated barcode as a PNG image. + generator.Save(outputPath, BarCodeImageFormat.Png); } - // Inform the user that the barcode has been generated. - Console.WriteLine("DataMatrix barcode generated with NoWrap enabled."); + // Output the full path of the saved barcode image. + Console.WriteLine($"DataMatrix barcode saved to {Path.GetFullPath(outputPath)}"); } } \ No newline at end of file diff --git a/barcode-text-customization/export-barcodes-with-customized-text-to-png-format-preserving-alignment-and-spacing-settings-in-image.cs b/barcode-text-customization/export-barcodes-with-customized-text-to-png-format-preserving-alignment-and-spacing-settings-in-image.cs index 5c6c91c..1112fcf 100644 --- a/barcode-text-customization/export-barcodes-with-customized-text-to-png-format-preserving-alignment-and-spacing-settings-in-image.cs +++ b/barcode-text-customization/export-barcodes-with-customized-text-to-png-format-preserving-alignment-and-spacing-settings-in-image.cs @@ -1,66 +1,122 @@ -// Title: Export Barcode with Custom Text to PNG -// Description: Demonstrates how to generate a Code128 barcode with customized human‑readable text, alignment, spacing, and colors, then save it as a PNG image. -// Category-Description: This example belongs to the Aspose.BarCode generation category, showcasing the use of BarcodeGenerator, EncodeTypes, and related parameter classes to control barcode appearance. Typical use cases include creating branded labels, receipts, or product tags where precise text placement and visual styling are required. Developers often need to adjust font, alignment, padding, and colors before exporting the barcode to common image formats. +// Title: Export barcodes with custom text alignment and spacing to PNG +// Description: Demonstrates how to generate Code128, QR, and DataMatrix barcodes with customized human‑readable text positioning, alignment, and spacing, then save them as PNG images. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and related parameter classes (Barcode, CodeTextParameters, Padding) to control visual appearance of barcodes. Typical use cases include creating printable barcode assets with precise layout requirements, such as aligning text above or below the symbol and adjusting margins. Developers often need to fine‑tune colors, module size, and padding to match branding or packaging specifications. // Prompt: Export barcodes with customized text to PNG format, preserving alignment and spacing settings in the image. -// Tags: code128, barcode, export, png, custom-text, alignment, spacing, aspose.barcode, generation +// Tags: barcode, code128, qr, datamatrix, text alignment, spacing, png, aspose.barcode, generation using System; +using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.Drawing; +using Aspose.Drawing.Imaging; /// -/// Generates a Code128 barcode with customized human‑readable text and saves it as a PNG image. +/// Demonstrates exporting barcodes with customized text alignment and spacing to PNG files. /// class Program { /// - /// Entry point of the example. Configures barcode parameters, applies custom text styling, - /// and writes the resulting image to disk. + /// Entry point that generates sample barcodes and saves them as PNG images. /// static void Main() { - // Output file path for the generated PNG image - string outputPath = "custom_text_barcode.png"; - - // Initialize a barcode generator for Code128 with the desired code text - using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890")) + // Determine output folder for generated barcode images + string outputFolder = Path.Combine(Directory.GetCurrentDirectory(), "Barcodes"); + if (!Directory.Exists(outputFolder)) { - // Disable automatic sizing to allow manual dimension control - generator.Parameters.AutoSizeMode = AutoSizeMode.None; + // Create the folder if it does not exist + Directory.CreateDirectory(outputFolder); + } - // Set explicit barcode dimensions - generator.Parameters.Barcode.BarHeight.Point = 50f; // Height of the bars - generator.Parameters.Barcode.XDimension.Point = 2f; // Width of a single module + // ------------------------------------------------------------ + // Example 1: Code128 barcode with custom text alignment and spacing + // ------------------------------------------------------------ + using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "ABC-1234")) + { + // Set barcode and background colors + generator.Parameters.Barcode.BarColor = Color.Black; + generator.Parameters.BackColor = Color.White; - // Configure human‑readable text appearance - generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial"; - generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f; + // Define module size (XDimension) and bar height + generator.Parameters.Barcode.XDimension.Point = 2f; + generator.Parameters.Barcode.BarHeight.Point = 50f; - // Center the text horizontally relative to the barcode + // Configure human‑readable text: location below the barcode, centered, with spacing + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center; + generator.Parameters.Barcode.CodeTextParameters.Space.Point = 5f; // space between barcode and text - // Position the text above the barcode bars + // Set individual paddings (left, top, right, bottom) around the barcode image + generator.Parameters.Barcode.Padding.Left.Point = 10f; + generator.Parameters.Barcode.Padding.Top.Point = 5f; + generator.Parameters.Barcode.Padding.Right.Point = 10f; + generator.Parameters.Barcode.Padding.Bottom.Point = 5f; + + // Save the barcode as a PNG file + string filePath = Path.Combine(outputFolder, "code128.png"); + generator.Save(filePath, BarCodeImageFormat.Png); + Console.WriteLine($"Generated: {filePath}"); + } + + // ------------------------------------------------------------ + // Example 2: QR code with custom text alignment and spacing + // ------------------------------------------------------------ + using (var generator = new BarcodeGenerator(EncodeTypes.QR, "https://example.com")) + { + // Set barcode and background colors + generator.Parameters.Barcode.BarColor = Color.DarkBlue; + generator.Parameters.BackColor = Color.LightYellow; + + // Define module size; QR codes ignore BarHeight + generator.Parameters.Barcode.XDimension.Point = 3f; + + // Configure human‑readable text: location above the QR code, right‑aligned, with spacing generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Above; + generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Right; + generator.Parameters.Barcode.CodeTextParameters.Space.Point = 8f; - // Define spacing between the text and the barcode (10 points) - generator.Parameters.Barcode.CodeTextParameters.Space.Point = 10f; + // Set uniform padding around the QR code image + generator.Parameters.Barcode.Padding.Left.Point = 12f; + generator.Parameters.Barcode.Padding.Top.Point = 12f; + generator.Parameters.Barcode.Padding.Right.Point = 12f; + generator.Parameters.Barcode.Padding.Bottom.Point = 12f; - // Apply uniform padding around the entire barcode image (5 points on each side) - generator.Parameters.Barcode.Padding.Left.Point = 5f; - generator.Parameters.Barcode.Padding.Top.Point = 5f; - generator.Parameters.Barcode.Padding.Right.Point = 5f; - generator.Parameters.Barcode.Padding.Bottom.Point = 5f; + // Save the QR code as a PNG file + string filePath = Path.Combine(outputFolder, "qr.png"); + generator.Save(filePath, BarCodeImageFormat.Png); + Console.WriteLine($"Generated: {filePath}"); + } - // Optional: set foreground (bars) and background colors - generator.Parameters.Barcode.BarColor = Color.Blue; + // ------------------------------------------------------------ + // Example 3: DataMatrix with custom text alignment and spacing + // ------------------------------------------------------------ + using (var generator = new BarcodeGenerator(EncodeTypes.DataMatrix, "DataMatrix123")) + { + // Set barcode and background colors + generator.Parameters.Barcode.BarColor = Color.Green; generator.Parameters.BackColor = Color.White; - // Save the configured barcode as a PNG file - generator.Save(outputPath); + // Define module size for DataMatrix + generator.Parameters.Barcode.XDimension.Point = 1.5f; + + // Configure human‑readable text: location below the symbol, left‑aligned, with spacing + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; + generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Left; + generator.Parameters.Barcode.CodeTextParameters.Space.Point = 4f; + + // Set uniform padding around the DataMatrix image + generator.Parameters.Barcode.Padding.Left.Point = 8f; + generator.Parameters.Barcode.Padding.Top.Point = 8f; + generator.Parameters.Barcode.Padding.Right.Point = 8f; + generator.Parameters.Barcode.Padding.Bottom.Point = 8f; + + // Save the DataMatrix as a PNG file + string filePath = Path.Combine(outputFolder, "datamatrix.png"); + generator.Save(filePath, BarCodeImageFormat.Png); + Console.WriteLine($"Generated: {filePath}"); } - // Inform the user that the image has been created - Console.WriteLine($"Barcode saved to {outputPath}"); + Console.WriteLine("Barcode generation completed."); } } \ No newline at end of file diff --git a/barcode-text-customization/export-barcodes-with-customized-text-to-svg-format-to-retain-vector-based-alignment-for-scalable-rendering.cs b/barcode-text-customization/export-barcodes-with-customized-text-to-svg-format-to-retain-vector-based-alignment-for-scalable-rendering.cs index 736e59d..4ae39f6 100644 --- a/barcode-text-customization/export-barcodes-with-customized-text-to-svg-format-to-retain-vector-based-alignment-for-scalable-rendering.cs +++ b/barcode-text-customization/export-barcodes-with-customized-text-to-svg-format-to-retain-vector-based-alignment-for-scalable-rendering.cs @@ -1,50 +1,62 @@ // Title: Export Code39 Barcode with Custom Text to SVG -// Description: Demonstrates generating a Code39 barcode, customizing its human‑readable text, and exporting it as an SVG file for scalable vector rendering. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use BarcodeGenerator, EncodeTypes, and rendering parameters to create barcodes. Typical use cases include producing printable or web‑ready barcodes with vector output, customizing appearance, and ensuring high‑quality scaling. Developers often need to adjust colors, fonts, and layout before saving to formats like SVG, PNG, or PDF. +// Description: Demonstrates generating a Code39 barcode with customized human‑readable text and saving it as an SVG file for scalable vector rendering. +// Category-Description: This example belongs to the Aspose.BarCode generation and export category. It showcases how to use the BarcodeGenerator class together with EncodeTypes, BarCodeImageFormat, and related parameter objects to customize barcode appearance (text location, alignment, font, colors) and export to a vector format. Developers often need such patterns when creating printable or web‑ready barcodes that must retain crisp quality at any size. // Prompt: Export barcodes with customized text to SVG format to retain vector‑based alignment for scalable rendering. -// Tags: code39, barcode generation, svg, aspose.barcode, barcodgenerator, custom text, vector rendering +// Tags: barcode, code39, generation, svg, custom-text, aspose.barcode using System; +using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.Drawing; /// -/// Example program that creates a Code39 barcode with customized human‑readable text -/// and saves it as an SVG file using Aspose.BarCode. +/// Example program that creates a Code39 barcode with customized text and exports it to SVG. /// class Program { /// - /// Entry point of the application. - /// Generates the barcode, applies visual customizations, and writes the SVG output. + /// Entry point of the example. Generates the barcode and saves it as an SVG file. /// static void Main() { - // Initialize a BarcodeGenerator for Code39 (evaluation version limitation) - using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code39, "1234567890")) + // Prepare output folder + string outputFolder = "Output"; + if (!Directory.Exists(outputFolder)) { - // Set foreground (barcode) and background colors - generator.Parameters.Barcode.BarColor = Color.Black; - generator.Parameters.BackColor = Color.White; + Directory.CreateDirectory(outputFolder); + } + + // Path for the SVG file + string svgPath = Path.Combine(outputFolder, "custom_code39.svg"); - // Configure vector‑based rendering (SVG) with interpolation sizing - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; - generator.Parameters.ImageWidth.Point = 300; // Width in points - generator.Parameters.ImageHeight.Point = 100; // Height in points + try + { + // Create a Code39 barcode generator with sample code text + using (var generator = new BarcodeGenerator(EncodeTypes.Code39, "123ABC")) + { + // Customize human‑readable text (code text) appearance + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; + generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center; + generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Helvetica"; + generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f; - // Customize the human‑readable text appearance - generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial"; - generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12; - generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Above; - generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center; - generator.Parameters.Barcode.CodeTextParameters.Color = Color.DarkBlue; + // Set barcode colors + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.DarkBlue; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Save the generated barcode as an SVG file (vector format) - generator.Save("custom_barcode.svg"); - } + // Define module size for vector scalability + generator.Parameters.Barcode.XDimension.Point = 2f; - // Inform the user that the file has been created - Console.WriteLine("Barcode saved as custom_barcode.svg"); + // Save the barcode as SVG (vector format) + generator.Save(svgPath, BarCodeImageFormat.Svg); + Console.WriteLine($"Barcode saved to: {svgPath}"); + } + } + catch (Exception ex) + { + // Handle errors such as evaluation license restrictions + Console.WriteLine($"Error generating barcode: {ex.Message}"); + } } } \ No newline at end of file diff --git a/barcode-text-customization/generate-barcodes-with-hidden-main-text-and-visible-top-caption-to-display-supplemental-information-only.cs b/barcode-text-customization/generate-barcodes-with-hidden-main-text-and-visible-top-caption-to-display-supplemental-information-only.cs index 7679f35..4e02b5a 100644 --- a/barcode-text-customization/generate-barcodes-with-hidden-main-text-and-visible-top-caption-to-display-supplemental-information-only.cs +++ b/barcode-text-customization/generate-barcodes-with-hidden-main-text-and-visible-top-caption-to-display-supplemental-information-only.cs @@ -1,50 +1,58 @@ // Title: Generate barcode with hidden main text and visible top caption -// Description: This example creates a Code128 barcode where the main human‑readable text is hidden and a caption is displayed above the barcode to convey supplemental information. -// Category-Description: Demonstrates Aspose.BarCode generation features for customizing human‑readable text and adding captions. It uses BarcodeGenerator, EncodeTypes, and the Parameters hierarchy (CodeTextParameters, CaptionAbove) to control visibility, positioning, and styling of text elements. Ideal for developers needing to embed supplemental data without cluttering the barcode itself, such as product codes with additional notes. +// Description: Demonstrates how to create a Code128 barcode where the primary human‑readable text is hidden and a supplemental caption is shown above the barcode. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, CodeTextParameters, and CaptionAbove settings. Developers often need to hide the default barcode text while adding custom labels such as order numbers, dates, or other metadata above the barcode. The snippet shows typical configuration steps for text location, caption visibility, alignment, font, and colors, useful for creating clean, information‑rich barcode images. // Prompt: Generate barcodes with hidden main text and visible top caption to display supplemental information only. -// Tags: code128, barcode, caption, hiddentext, png, aspose.barcode, generation +// Tags: code128, barcode generation, hidden text, top caption, aspnet, aspose.barcode, image output using System; +using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.Drawing; /// -/// Example program that generates a barcode with the main text hidden and a visible caption above it. +/// Demonstrates generating a Code128 barcode with hidden main text and a visible top caption. /// class Program { /// - /// Entry point of the application. Creates and saves a barcode image with customized text settings. + /// Entry point that creates the barcode image and saves it to disk. /// static void Main() { - // Define the output file path for the generated barcode image. - string outputPath = "barcode_with_caption.png"; + // Define the output file path for the generated barcode image + string outputPath = "barcode.png"; - // Initialize a BarcodeGenerator for Code128 symbology with sample data. + // Ensure the target directory exists; create it if necessary + string outputDir = Path.GetDirectoryName(Path.GetFullPath(outputPath)); + if (!Directory.Exists(outputDir)) + { + Directory.CreateDirectory(outputDir); + } + + // Initialize a BarcodeGenerator for Code128 with the desired code text using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890")) { - // Hide the default human‑readable text that would appear below the barcode. + // Hide the default human‑readable barcode text generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None; - // Configure the caption that appears above the barcode. - generator.Parameters.CaptionAbove.Text = "Supplemental Information"; - generator.Parameters.CaptionAbove.Visible = true; // Ensure the caption is displayed. - generator.Parameters.CaptionAbove.Font.FamilyName = "Arial"; - generator.Parameters.CaptionAbove.Font.Size.Point = 12f; + // Configure the caption that appears above the barcode + generator.Parameters.CaptionAbove.Visible = true; + generator.Parameters.CaptionAbove.Text = "Order ID: 98765"; generator.Parameters.CaptionAbove.Alignment = TextAlignment.Center; - generator.Parameters.CaptionAbove.TextColor = Color.Black; + generator.Parameters.CaptionAbove.Font.FamilyName = "Helvetica"; + generator.Parameters.CaptionAbove.Font.Size.Point = 12f; + generator.Parameters.CaptionAbove.TextColor = Aspose.Drawing.Color.Black; - // Optional: set the barcode's foreground and background colors. - generator.Parameters.Barcode.BarColor = Color.Black; - generator.Parameters.BackColor = Color.White; + // Optional: set barcode and background colors + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Save the generated barcode as a PNG image to the specified path. - generator.Save(outputPath, BarCodeImageFormat.Png); + // Save the generated barcode image to the specified file + generator.Save(outputPath); } - // Inform the user that the image has been saved. - Console.WriteLine($"Barcode image saved to {outputPath}"); + // Inform the user where the barcode image was saved + Console.WriteLine($"Barcode image saved to: {Path.GetFullPath(outputPath)}"); } } \ No newline at end of file diff --git a/barcode-text-customization/hide-all-captions-for-batch-of-code128-barcodes-by-setting-captionparametersvisible-to-false-globally.cs b/barcode-text-customization/hide-all-captions-for-batch-of-code128-barcodes-by-setting-captionparametersvisible-to-false-globally.cs index b183602..b9d4936 100644 --- a/barcode-text-customization/hide-all-captions-for-batch-of-code128-barcodes-by-setting-captionparametersvisible-to-false-globally.cs +++ b/barcode-text-customization/hide-all-captions-for-batch-of-code128-barcodes-by-setting-captionparametersvisible-to-false-globally.cs @@ -1,8 +1,8 @@ -// Title: Hide Captions for Batch of Code128 Barcodes -// Description: Demonstrates how to generate multiple Code128 barcodes while globally disabling their captions. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator and its Parameters.Caption* properties to control caption visibility. Developers often need to produce clean barcode images without human‑readable text for scanning applications, packaging, or UI display. The snippet shows typical batch processing, directory handling, and saving PNG files, useful for quick integration in .NET projects. +// Title: Hide Captions for Multiple Code128 Barcodes +// Description: Demonstrates generating a batch of Code128 barcodes and disabling both above and below captions. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to configure global caption visibility using the BarcodeGenerator.Parameters.CaptionAbove and CaptionBelow properties. Typical use cases include creating clean barcode images for packaging, inventory, or point‑of‑sale systems where textual captions are not required. Developers often need to adjust these settings across many barcodes in a single run. // Prompt: Hide all captions for a batch of Code128 barcodes by setting CaptionParameters.Visible to false globally. -// Tags: code128, barcode generation, hide captions, batch processing, aspnet, aspose.barcode, png +// Tags: code128, barcode, hide-caption, png, aspose.barcode, generation using System; using System.IO; @@ -10,55 +10,51 @@ using Aspose.BarCode.Generation; /// -/// Demonstrates batch generation of Code128 barcodes with captions hidden. +/// Generates a series of Code128 barcodes with captions hidden and saves them as PNG files. /// class Program { /// - /// Entry point. Generates a set of Code128 barcodes, disables both above and below captions, and saves them as PNG files. + /// Entry point of the application. Creates an output folder, generates barcodes, and writes a completion message. /// static void Main() { - // Define the output directory for generated barcode images - string outputDir = Path.Combine(Directory.GetCurrentDirectory(), "Barcodes"); - if (!Directory.Exists(outputDir)) + // Determine and ensure the output directory exists + string outputFolder = Path.Combine(Directory.GetCurrentDirectory(), "Barcodes"); + if (!Directory.Exists(outputFolder)) { - // Create the directory if it does not already exist - Directory.CreateDirectory(outputDir); + Directory.CreateDirectory(outputFolder); } - // Sample data for a batch of Code128 barcodes - string[] codes = new string[] + // Define the set of texts to encode as Code128 barcodes + string[] codeTexts = new string[] { "ABC123", - "DEF456", - "GHI789", - "JKL012", - "MNO345" + "9876543210", + "CODE128TEST", + "1234567890", + "HELLOWORLD" }; - // Iterate over each code, generate a barcode, hide captions, and save the image - for (int i = 0; i < codes.Length; i++) + // Iterate over each text, generate a barcode, hide its captions, and save the image + for (int i = 0; i < codeTexts.Length; i++) { - string codeText = codes[i]; - string filePath = Path.Combine(outputDir, $"Code128_{i + 1}.png"); + string text = codeTexts[i]; + string filePath = Path.Combine(outputFolder, $"barcode_{i + 1}.png"); - // Use a using block to ensure proper disposal of the generator - using (var generator = new BarcodeGenerator(EncodeTypes.Code128, codeText)) + // Create a barcode generator for Code128 with the current text + using (var generator = new BarcodeGenerator(EncodeTypes.Code128, text)) { - // Hide both above and below captions globally for this generator + // Hide both above and below captions globally generator.Parameters.CaptionAbove.Visible = false; generator.Parameters.CaptionBelow.Visible = false; - // Save the barcode image to the specified file path - generator.Save(filePath); + // Save the generated barcode as a PNG file + generator.Save(filePath, BarCodeImageFormat.Png); } - - // Inform the user that the barcode has been saved - Console.WriteLine($"Saved barcode {i + 1} to: {filePath}"); } - // Final status message - Console.WriteLine("All barcodes generated successfully."); + // Inform the user about the number of barcodes generated and their location + Console.WriteLine($"Generated {codeTexts.Length} Code128 barcodes in '{outputFolder}'."); } } \ No newline at end of file diff --git a/barcode-text-customization/hide-main-barcode-text-for-batch-of-qr-code-images-by-setting-codetextparametersvisible-to-false.cs b/barcode-text-customization/hide-main-barcode-text-for-batch-of-qr-code-images-by-setting-codetextparametersvisible-to-false.cs index 4ec1d73..de36879 100644 --- a/barcode-text-customization/hide-main-barcode-text-for-batch-of-qr-code-images-by-setting-codetextparametersvisible-to-false.cs +++ b/barcode-text-customization/hide-main-barcode-text-for-batch-of-qr-code-images-by-setting-codetextparametersvisible-to-false.cs @@ -1,57 +1,68 @@ -// Title: Hide barcode text for batch QR code generation -// Description: Demonstrates generating multiple QR code images while suppressing the human‑readable text. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to configure barcode appearance using the BarcodeGenerator class. It shows typical use cases such as batch processing of QR codes where the visual text is not required, covering parameters like CodeTextParameters and AutoSizeMode. Developers often need to hide or customize barcode text for cleaner graphics or UI integration. +// Title: Hide QR Code Text for Batch Generation +// Description: Demonstrates how to generate multiple QR code images while suppressing the human‑readable text using Aspose.BarCode. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and CodeTextParameters to customize barcode appearance. Typical scenarios include creating batches of barcodes for marketing or inventory where the textual representation is not required. Developers often need to control visibility, location, and styling of barcode text for various output formats. // Prompt: Hide main barcode text for a batch of QR code images by setting CodetextParameters.Visible to false. -// Tags: qr code, hide text, batch generation, aspnet, aspose.barcode, codetextparameters, autosizemode, png +// Tags: qr code, hide text, batch, png, aspose.barcode, generation using System; using System.IO; +using System.Collections.Generic; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Generates a series of QR code images and hides the human‑readable text for each barcode. +/// Generates a batch of QR code images with the human‑readable text hidden. /// class Program { /// - /// Entry point of the application. Creates QR codes from a predefined list of strings, - /// disables the visible code text, and saves each image to the Output folder. + /// Entry point of the application. Creates QR codes from a list of URLs and saves them as PNG files without displaying the code text. /// static void Main() { - // Define sample texts to encode into QR codes. - string[] texts = { "Hello", "World", "Aspose", "Barcode", "QR Code" }; + // Define the output directory for the generated QR code images. + string outputFolder = Path.Combine(Directory.GetCurrentDirectory(), "QrCodes"); - // Ensure the output directory exists; create it if necessary. - string outputDir = "Output"; - if (!Directory.Exists(outputDir)) + // Ensure the output directory exists. + if (!Directory.Exists(outputFolder)) { - Directory.CreateDirectory(outputDir); + Directory.CreateDirectory(outputFolder); } - // Iterate over each text value and generate a QR code without visible text. - for (int i = 0; i < texts.Length; i++) + // List of sample QR code texts (e.g., URLs) to encode. + List qrTexts = new List { - // Initialize the barcode generator for QR encoding with the current text. - using (var generator = new BarcodeGenerator(EncodeTypes.QR, texts[i])) - { - // Hide the main barcode text by setting its location to None. - // (Equivalent to setting CodeTextParameters.Visible = false.) - generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None; + "https://example.com/1", + "https://example.com/2", + "https://example.com/3", + "https://example.com/4", + "https://example.com/5" + }; - // Use interpolation auto‑size mode to keep image dimensions consistent. - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; + int index = 1; // Counter for naming output files. - // Build the full file path for the output PNG image. - string filePath = Path.Combine(outputDir, $"qr_{i + 1}.png"); + // Iterate over each text value and generate a corresponding QR code. + foreach (string text in qrTexts) + { + // Build the full file path for the current QR code image. + string filePath = Path.Combine(outputFolder, $"qr_{index}.png"); - // Save the generated QR code image to disk. - generator.Save(filePath); + // Initialize the barcode generator with QR encoding and the current text. + using (var generator = new BarcodeGenerator(EncodeTypes.QR, text)) + { + // Hide the human‑readable text by setting its location to None. + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None; - // Inform the user that the image has been saved. - Console.WriteLine($"Saved QR code without text: {filePath}"); + // Save the generated QR code image as a PNG file. + generator.Save(filePath); } + + // Output a confirmation message to the console. + Console.WriteLine($"Generated QR code without text: {filePath}"); + index++; } + + // Indicate that all QR codes have been processed. + Console.WriteLine("All QR codes have been generated."); } } \ No newline at end of file diff --git a/barcode-text-customization/integrate-barcode-text-customization-into-aspnet-mvc-view-allowing-end-users-to-toggle-visibility-and-alignment.cs b/barcode-text-customization/integrate-barcode-text-customization-into-aspnet-mvc-view-allowing-end-users-to-toggle-visibility-and-alignment.cs index 259f659..eb0575b 100644 --- a/barcode-text-customization/integrate-barcode-text-customization-into-aspnet-mvc-view-allowing-end-users-to-toggle-visibility-and-alignment.cs +++ b/barcode-text-customization/integrate-barcode-text-customization-into-aspnet-mvc-view-allowing-end-users-to-toggle-visibility-and-alignment.cs @@ -1,8 +1,8 @@ -// Title: Barcode Text Visibility and Alignment Demo -// Description: Demonstrates how to generate barcodes with customizable human‑readable text visibility and alignment, suitable for integration into an ASP.NET MVC view. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and CodeTextParameters to control text display. Developers often need to show or hide barcode text and align it for UI consistency; this snippet shows typical settings for such scenarios. +// Title: Barcode Text Customization in ASP.NET MVC View +// Description: Demonstrates how to generate a barcode with customizable human‑readable text visibility and alignment, simulating user input from an MVC view. +// Category-Description: This example belongs to the Aspose.BarCode generation category, showing how to use BarcodeGenerator, EncodeTypes, and CodeTextParameters to control text display. Typical use cases include dynamic barcode creation in web applications where end users can choose whether to show the text and its alignment. Developers often need to adjust text location, color, and font for branding or readability, and this snippet illustrates those common tasks. // Prompt: Integrate barcode text customization into an ASP.NET MVC view, allowing end users to toggle visibility and alignment. -// Tags: barcode, text visibility, alignment, aspnet mvc, code128, png, aspose.barcode, generation +// Tags: barcode, text customization, visibility, alignment, aspnet mvc, code128, aspose.barcode, generation, image output using System; using System.IO; @@ -11,65 +11,52 @@ using Aspose.Drawing; /// -/// Program demonstrating barcode text visibility and alignment customization. +/// Demonstrates barcode generation with customizable human‑readable text settings. /// class Program { /// - /// Entry point. Generates two barcode images: one with visible centered text and one with hidden text. + /// Entry point that simulates MVC view inputs and creates a barcode image with the chosen text options. /// static void Main() { - // NOTE: The original request was for an ASP.NET MVC view. - // The snippet runner only supports a console application, so we demonstrate the core barcode logic here. - // The generated images can be used in an MVC view to allow users to toggle text visibility and alignment. + // Simulated user choices that would normally come from an MVC view (e.g., form fields). + bool showHumanReadableText = true; // Toggle visibility of the text + TextAlignment textAlignment = TextAlignment.Center; // Choose alignment for the text - // Sample data - string codeText = "1234567890"; - string outputDir = Directory.GetCurrentDirectory(); + // Barcode data to encode. + string codeText = "Sample123"; - // ------------------------------------------------------------ - // 1. Barcode with human‑readable text visible and centered - // ------------------------------------------------------------ - string visiblePath = Path.Combine(outputDir, "barcode_visible.png"); - using (var generator = new BarcodeGenerator(EncodeTypes.Code128, codeText)) + // Determine output folder and ensure it exists. + string outputFolder = Path.Combine(Directory.GetCurrentDirectory(), "Output"); + if (!Directory.Exists(outputFolder)) { - // Enable auto‑size mode so we don't need to set BarHeight manually - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; - - // Set text location to appear below the barcode and align it to the center - generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; - generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center; - - // Optional: customize the font of the human‑readable text - generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial"; - generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f; - - // Save the barcode image to disk - generator.Save(visiblePath); + Directory.CreateDirectory(outputFolder); } + string outputPath = Path.Combine(outputFolder, "barcode.png"); - Console.WriteLine($"Visible barcode saved to: {visiblePath}"); - - // ------------------------------------------------------------ - // 2. Barcode with human‑readable text hidden - // ------------------------------------------------------------ - string hiddenPath = Path.Combine(outputDir, "barcode_hidden.png"); + // Generate the barcode using the specified settings. using (var generator = new BarcodeGenerator(EncodeTypes.Code128, codeText)) { - // Keep auto‑size mode consistent with the first example - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; + // Set human‑readable text visibility based on user choice. + generator.Parameters.Barcode.CodeTextParameters.Location = showHumanReadableText + ? CodeLocation.Below + : CodeLocation.None; - // Hide the text by setting its location to None - generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None; + // Apply the selected text alignment. + generator.Parameters.Barcode.CodeTextParameters.Alignment = textAlignment; - // Alignment is irrelevant when text is hidden, but set it to Right for demonstration purposes - generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Right; + // Optional styling: set text color and font size for demonstration purposes. + generator.Parameters.Barcode.CodeTextParameters.Color = Aspose.Drawing.Color.DarkBlue; + generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f; - // Save the barcode image without human‑readable text - generator.Save(hiddenPath); + // Save the generated barcode image to the output path. + generator.Save(outputPath); } - Console.WriteLine($"Hidden barcode saved to: {hiddenPath}"); + // Output information to the console for verification. + Console.WriteLine($"Barcode image saved to: {outputPath}"); + Console.WriteLine($"Human‑readable text visible: {showHumanReadableText}"); + Console.WriteLine($"Text alignment: {textAlignment}"); } } \ No newline at end of file diff --git a/barcode-text-customization/place-barcode-text-above-datamatrix-symbols-by-assigning-codetextparameterslocation-textlocationabove.cs b/barcode-text-customization/place-barcode-text-above-datamatrix-symbols-by-assigning-codetextparameterslocation-textlocationabove.cs index 055cac2..9cf5370 100644 --- a/barcode-text-customization/place-barcode-text-above-datamatrix-symbols-by-assigning-codetextparameterslocation-textlocationabove.cs +++ b/barcode-text-customization/place-barcode-text-above-datamatrix-symbols-by-assigning-codetextparameterslocation-textlocationabove.cs @@ -1,40 +1,38 @@ // Title: Place Text Above DataMatrix Barcode // Description: Demonstrates how to position human‑readable text above a DataMatrix symbol using Aspose.BarCode. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on customizing CodeTextParameters for various symbologies. It shows how to use the BarcodeGenerator class with EncodeTypes.DataMatrix, adjust text location, and apply auto‑size modes. Developers often need to control human‑readable text placement for better visual integration in reports, labels, and packaging. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on text placement options. It showcases the use of BarcodeGenerator, EncodeTypes, and CodeTextParameters to control the location of the codetext. Developers often need to adjust text positioning for readability or branding when generating 2‑D barcodes for packaging, labeling, or documentation. // Prompt: Place barcode text above DataMatrix symbols by assigning CodetextParameters.Location = TextLocation.Above. -// Tags: datamatrix, text location, above, barcode generation, aspose.barcode, png, codetextparameters, autosizemode +// Tags: datamatrix, textlocation, above, barcode generation, aspose.barcodes, csharp using System; -using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.BarCode; /// -/// Example program that creates a DataMatrix barcode with the human‑readable text positioned above the symbol. +/// Demonstrates placing human‑readable text above a DataMatrix barcode using Aspose.BarCode. /// class Program { /// - /// Generates a DataMatrix barcode, sets the text location to above the symbol, and saves it as a PNG file. + /// Entry point of the example. Generates a DataMatrix barcode with the codetext positioned above the symbol and saves it as a PNG file. /// static void Main() { - // Output file name for the generated barcode image - const string outputFile = "datamatrix_above.png"; - - // Initialize a DataMatrix barcode generator with sample text - using (var generator = new BarcodeGenerator(EncodeTypes.DataMatrix, "Sample123")) + // Initialize a DataMatrix barcode generator with the desired codetext. + using (var generator = new BarcodeGenerator(EncodeTypes.DataMatrix, "Hello World")) { - // Set the human‑readable text to appear above the DataMatrix symbol + // Set the codetext location to appear above the barcode symbol. generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Above; - // Enable interpolation auto‑size so the image dimensions adapt to the content - generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; + // Optional: adjust image dimensions if required. + // generator.Parameters.ImageWidth.Point = 200f; + // generator.Parameters.ImageHeight.Point = 200f; - // Save the generated barcode image to the specified file - generator.Save(outputFile); + // Save the generated barcode image to a PNG file. + generator.Save("datamatrix.png"); } - // Inform the user that the barcode image has been saved - Console.WriteLine($"Barcode image saved to {outputFile}"); + // Inform the user that the barcode has been generated. + Console.WriteLine("DataMatrix barcode generated with text above the symbol."); } } \ No newline at end of file diff --git a/barcode-text-customization/replace-displayed-text-of-qr-code-with-custom-url-by-setting-codetextparameterstext.cs b/barcode-text-customization/replace-displayed-text-of-qr-code-with-custom-url-by-setting-codetextparameterstext.cs index 1a849e8..b014968 100644 --- a/barcode-text-customization/replace-displayed-text-of-qr-code-with-custom-url-by-setting-codetextparameterstext.cs +++ b/barcode-text-customization/replace-displayed-text-of-qr-code-with-custom-url-by-setting-codetextparameterstext.cs @@ -1,34 +1,40 @@ -// Title: Replace QR code displayed text with a custom URL -// Description: Demonstrates how to change the text shown beneath a QR code by using CodetextParameters.Text. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to customize QR code appearance using the BarcodeGenerator class and its Parameters.Barcode.CodeTextParameters. Developers often need to modify the human‑readable text under 2‑D barcodes for branding or linking purposes. The snippet shows setting TwoDDisplayText and saving the image, a common task when integrating QR codes into applications. +// Title: Replace QR Code Display Text with Custom URL using Aspose.BarCode +// Description: Demonstrates how to generate a QR code and override the human‑readable text displayed beneath the symbol with a custom URL. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to customize QR code appearance using the BarcodeGenerator class and its CodeTextParameters. Typical use cases include branding QR codes where the encoded data differs from the displayed text, such as showing a marketing URL while encoding other information. Developers often need to adjust TwoDDisplayText to control what end users see without altering the underlying payload. // Prompt: Replace displayed text of a QR code with a custom URL by setting CodetextParameters.Text. -// Tags: qr code, barcode generation, codetextparameters, display text, aspose.barcode, image output +// Tags: qr code,display text,custom url,aspose.barcode,generation,code text parameters using System; -using Aspose.BarCode.Generation; using Aspose.BarCode; +using Aspose.BarCode.Generation; /// -/// Demonstrates replacing the displayed text of a QR code with a custom URL using Aspose.BarCode. +/// Generates a QR code, sets a custom display text (URL), and saves the image to disk. /// class Program { /// - /// Entry point. Generates a QR code, sets custom display text, and saves the image. + /// Entry point of the example. Creates a QR code, customizes its displayed text, and writes the result to a PNG file. /// static void Main() { - // Create a QR code generator with sample data. - using (var generator = new BarcodeGenerator(EncodeTypes.QR, "SampleData")) + // Define the output file path for the generated QR code image. + string outputPath = "qr.png"; + + // Initialize a QR code generator with the QR symbology. + using (var generator = new BarcodeGenerator(EncodeTypes.QR)) { - // Set the human‑readable text displayed under the QR code. - generator.Parameters.Barcode.CodeTextParameters.TwoDDisplayText = "https://customurl.com"; + // Set the actual data to be encoded in the QR code. + generator.CodeText = "Data to encode"; + + // Override the human‑readable text shown below the QR code with a custom URL. + generator.Parameters.Barcode.CodeTextParameters.TwoDDisplayText = "https://example.com"; - // Save the generated QR code as a PNG image. - generator.Save("qr.png"); + // Save the generated QR code image to the specified file. + generator.Save(outputPath); } - // Inform the user that the QR code has been generated. - Console.WriteLine("QR code generated and saved as qr.png"); + // Inform the user where the QR code image has been saved. + Console.WriteLine($"QR code saved to {outputPath}"); } } \ No newline at end of file diff --git a/barcode-text-customization/rightalign-barcode-text-for-itf-14-barcodes-by-setting-codetextparametersalignment-textalignmentright.cs b/barcode-text-customization/rightalign-barcode-text-for-itf-14-barcodes-by-setting-codetextparametersalignment-textalignmentright.cs index a693c0a..4acb52d 100644 --- a/barcode-text-customization/rightalign-barcode-text-for-itf-14-barcodes-by-setting-codetextparametersalignment-textalignmentright.cs +++ b/barcode-text-customization/rightalign-barcode-text-for-itf-14-barcodes-by-setting-codetextparametersalignment-textalignmentright.cs @@ -1,34 +1,41 @@ -// Title: Right-align text for ITF‑14 barcode -// Description: Demonstrates how to right‑align the human‑readable text of an ITF‑14 barcode using Aspose.BarCode. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on text formatting options. It showcases the use of BarcodeGenerator, EncodeTypes, and CodeTextParameters.Alignment to control human‑readable text placement. Developers often need to adjust text alignment for compliance with labeling standards or aesthetic requirements. +// Title: Right-align human‑readable text for ITF‑14 barcode +// Description: Demonstrates how to generate an ITF‑14 barcode and align its human‑readable text to the right. +// Category-Description: This example belongs to the Aspose.BarCode generation category, showcasing the use of BarcodeGenerator, EncodeTypes, and CodeTextParameters to customize barcode appearance. Typical scenarios include creating product packaging barcodes where text positioning matters. Developers often need to control text location, alignment, and output format when generating barcodes programmatically. // Prompt: Right-align barcode text for ITF‑14 barcodes by setting CodetextParameters.Alignment = TextAlignment.Right. -// Tags: itf-14, text alignment, barcode generation, png output, aspose.barcode, codetextparameters +// Tags: itf-14, barcode, text alignment, right align, aspose.barcode, generation, png, csharp using System; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Generates an ITF‑14 barcode with right‑aligned human‑readable text and saves it as a PNG image. +/// Demonstrates right‑aligning the human‑readable text of an ITF‑14 barcode using Aspose.BarCode. /// class Program { /// - /// Entry point of the example. Creates the barcode, applies right alignment to the text, and writes the image to disk. + /// Entry point that creates an ITF‑14 barcode, sets text location and alignment, and saves it as PNG. /// static void Main() { - // Initialize a BarcodeGenerator for ITF‑14 symbology with sample numeric data. - using (var generator = new BarcodeGenerator(EncodeTypes.ITF14, "1234567890123")) + // Define a sample ITF‑14 barcode value (14 digits) + const string codeText = "12345678901231"; + + // Initialize the barcode generator for the ITF‑14 symbology with the provided code text + using (var generator = new BarcodeGenerator(EncodeTypes.ITF14, codeText)) { - // Set the text alignment to the right side of the barcode. + // Position the human‑readable text below the barcode bars + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; + + // Align the human‑readable text to the right side generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Right; - // Save the generated barcode image to a PNG file. - generator.Save("itf14_right_aligned.png"); - } + // Specify the output file path and save the barcode as a PNG image + const string outputPath = "itf14_right_aligned.png"; + generator.Save(outputPath); - // Inform the user that the barcode image has been saved. - Console.WriteLine("ITF‑14 barcode with right‑aligned text saved as 'itf14_right_aligned.png'."); + // Inform the user where the barcode image was saved + Console.WriteLine($"Barcode saved to {outputPath}"); + } } } \ No newline at end of file diff --git a/barcode-text-customization/serialize-barcode-text-and-caption-settings-to-json-then-reload-them-to-recreate-identical-barcode-appearances.cs b/barcode-text-customization/serialize-barcode-text-and-caption-settings-to-json-then-reload-them-to-recreate-identical-barcode-appearances.cs index 8325bbf..f9e42be 100644 --- a/barcode-text-customization/serialize-barcode-text-and-caption-settings-to-json-then-reload-them-to-recreate-identical-barcode-appearances.cs +++ b/barcode-text-customization/serialize-barcode-text-and-caption-settings-to-json-then-reload-them-to-recreate-identical-barcode-appearances.cs @@ -1,129 +1,160 @@ -// Title: Serialize and Restore Barcode Captions via JSON -// Description: Demonstrates how to serialize barcode text and caption settings to a JSON file and then reload them to recreate identical barcode images. -// Category-Description: This example belongs to the Aspose.BarCode serialization and configuration category, illustrating the use of BarcodeGenerator, BarcodeParameters, and caption properties. Developers often need to persist barcode appearance settings for later reuse or for dynamic generation scenarios. The snippet shows typical steps: configure captions, serialize settings, deserialize, and regenerate the barcode. +// Title: Serialize and Reload Barcode Text and Caption Settings via JSON +// Description: Demonstrates how to capture barcode text and caption properties, serialize them to a JSON file, and then recreate the same barcode appearance by deserializing the settings. +// Category-Description: This example belongs to the Aspose.BarCode generation and serialization category. It shows how to use BarcodeGenerator, its Parameters (including CaptionAbove and CaptionBelow), and .NET System.Text.Json to persist barcode configuration. Typical use cases include saving barcode layouts for later reuse, sharing settings across services, or version‑controlling barcode designs. Developers often need to export and import barcode settings without re‑creating them manually. // Prompt: Serialize barcode text and caption settings to JSON, then reload them to recreate identical barcode appearances. -// Tags: barcode, serialization, json, caption, code128, aspnet, aspose.barcode, generation +// Tags: barcode, serialization, json, caption, code128, aspose.barcode, generation using System; using System.IO; using System.Text.Json; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing; namespace BarcodeJsonDemo { /// - /// Holds barcode and caption settings for JSON serialization. + /// Data transfer object that represents caption visual settings. + /// + public class CaptionSettings + { + public string Text { get; set; } + public string FontFamily { get; set; } + public float FontSize { get; set; } + public string Alignment { get; set; } // TextAlignment enum name + public int TextColorArgb { get; set; } + } + + /// + /// Data transfer object that aggregates barcode text and its caption settings. /// public class BarcodeSettings { public string CodeText { get; set; } - public string CaptionAboveText { get; set; } - public string CaptionBelowText { get; set; } - public string CaptionAboveFontFamily { get; set; } - public float CaptionAboveFontSize { get; set; } - public string CaptionBelowFontFamily { get; set; } - public float CaptionBelowFontSize { get; set; } - public string CaptionAboveAlignment { get; set; } - public string CaptionBelowAlignment { get; set; } - public bool CaptionAboveVisible { get; set; } - public bool CaptionBelowVisible { get; set; } + public CaptionSettings CaptionAbove { get; set; } + public CaptionSettings CaptionBelow { get; set; } } + /// + /// Demonstrates serialization of barcode settings to JSON and recreation of the barcode from those settings. + /// class Program { /// - /// Entry point. Creates a barcode with captions, serializes its settings to JSON, - /// then deserializes the settings to recreate an identical barcode image. + /// Entry point. Generates a barcode, saves its configuration to JSON, then reloads the JSON to produce an identical barcode. /// static void Main() { - const string originalImagePath = "barcode_original.png"; - const string restoredImagePath = "barcode_restored.png"; - const string settingsPath = "barcode_settings.json"; + // File paths for the generated images and the JSON settings file + const string originalImagePath = "barcodeOriginal.png"; + const string reloadedImagePath = "barcodeReloaded.png"; + const string jsonPath = "barcodeSettings.json"; - // ------------------------------------------------- - // 1. Create a barcode, configure captions, and save image - // ------------------------------------------------- + // ----------------------------------------------------------------- + // Create original barcode with text and caption settings + // ----------------------------------------------------------------- using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890")) { - // Configure caption above the barcode + // Configure caption displayed above the barcode generator.Parameters.CaptionAbove.Text = "Above Caption"; - generator.Parameters.CaptionAbove.Font.FamilyName = "Arial"; + generator.Parameters.CaptionAbove.Font.FamilyName = "Helvetica"; generator.Parameters.CaptionAbove.Font.Size.Point = 12f; generator.Parameters.CaptionAbove.Alignment = TextAlignment.Center; - generator.Parameters.CaptionAbove.Visible = true; + generator.Parameters.CaptionAbove.TextColor = Aspose.Drawing.Color.Blue; - // Configure caption below the barcode + // Configure caption displayed below the barcode generator.Parameters.CaptionBelow.Text = "Below Caption"; - generator.Parameters.CaptionBelow.Font.FamilyName = "Times New Roman"; + generator.Parameters.CaptionBelow.Font.FamilyName = "Helvetica"; generator.Parameters.CaptionBelow.Font.Size.Point = 10f; generator.Parameters.CaptionBelow.Alignment = TextAlignment.Right; - generator.Parameters.CaptionBelow.Visible = true; + generator.Parameters.CaptionBelow.TextColor = Aspose.Drawing.Color.Green; - // Save the original barcode image + // Save the original barcode image to disk generator.Save(originalImagePath); - // ------------------------------------------------- - // 2. Extract settings into a serializable object - // ------------------------------------------------- + // Capture the current barcode configuration into DTO objects var settings = new BarcodeSettings { CodeText = generator.CodeText, - CaptionAboveText = generator.Parameters.CaptionAbove.Text, - CaptionBelowText = generator.Parameters.CaptionBelow.Text, - CaptionAboveFontFamily = generator.Parameters.CaptionAbove.Font.FamilyName, - CaptionAboveFontSize = generator.Parameters.CaptionAbove.Font.Size.Point, - CaptionBelowFontFamily = generator.Parameters.CaptionBelow.Font.FamilyName, - CaptionBelowFontSize = generator.Parameters.CaptionBelow.Font.Size.Point, - CaptionAboveAlignment = generator.Parameters.CaptionAbove.Alignment.ToString(), - CaptionBelowAlignment = generator.Parameters.CaptionBelow.Alignment.ToString(), - CaptionAboveVisible = generator.Parameters.CaptionAbove.Visible, - CaptionBelowVisible = generator.Parameters.CaptionBelow.Visible + CaptionAbove = new CaptionSettings + { + Text = generator.Parameters.CaptionAbove.Text, + FontFamily = generator.Parameters.CaptionAbove.Font.FamilyName, + FontSize = generator.Parameters.CaptionAbove.Font.Size.Point, + Alignment = generator.Parameters.CaptionAbove.Alignment.ToString(), + TextColorArgb = generator.Parameters.CaptionAbove.TextColor.ToArgb() + }, + CaptionBelow = new CaptionSettings + { + Text = generator.Parameters.CaptionBelow.Text, + FontFamily = generator.Parameters.CaptionBelow.Font.FamilyName, + FontSize = generator.Parameters.CaptionBelow.Font.Size.Point, + Alignment = generator.Parameters.CaptionBelow.Alignment.ToString(), + TextColorArgb = generator.Parameters.CaptionBelow.TextColor.ToArgb() + } }; - // ------------------------------------------------- - // 3. Serialize settings to JSON file - // ------------------------------------------------- - using (var writeStream = new FileStream(settingsPath, FileMode.Create, FileAccess.Write)) - { - JsonSerializer.Serialize(writeStream, settings, new JsonSerializerOptions { WriteIndented = true }); - } + // Serialize the DTO to a formatted JSON string and write it to a file + var jsonOptions = new JsonSerializerOptions { WriteIndented = true }; + string json = JsonSerializer.Serialize(settings, jsonOptions); + File.WriteAllText(jsonPath, json); + } + + // ----------------------------------------------------------------- + // Reload settings from JSON and recreate identical barcode + // ----------------------------------------------------------------- + if (!File.Exists(jsonPath)) + { + Console.WriteLine($"JSON file not found: {jsonPath}"); + return; } - // ------------------------------------------------- - // 4. Load settings from JSON and recreate barcode - // ------------------------------------------------- - BarcodeSettings loadedSettings; - using (var readStream = new FileStream(settingsPath, FileMode.Open, FileAccess.Read)) + // Read the JSON content and deserialize it back into DTO objects + string jsonContent = File.ReadAllText(jsonPath); + var loadedSettings = JsonSerializer.Deserialize(jsonContent); + if (loadedSettings == null) { - loadedSettings = JsonSerializer.Deserialize(readStream); + Console.WriteLine("Failed to deserialize barcode settings."); + return; } + // Use the deserialized settings to generate a new barcode with the same appearance using (var generator = new BarcodeGenerator(EncodeTypes.Code128, loadedSettings.CodeText)) { - // Apply caption above settings - generator.Parameters.CaptionAbove.Text = loadedSettings.CaptionAboveText; - generator.Parameters.CaptionAbove.Font.FamilyName = loadedSettings.CaptionAboveFontFamily; - generator.Parameters.CaptionAbove.Font.Size.Point = loadedSettings.CaptionAboveFontSize; - generator.Parameters.CaptionAbove.Alignment = (TextAlignment)Enum.Parse(typeof(TextAlignment), loadedSettings.CaptionAboveAlignment); - generator.Parameters.CaptionAbove.Visible = loadedSettings.CaptionAboveVisible; + // Apply the "above" caption if it exists + if (loadedSettings.CaptionAbove != null) + { + generator.Parameters.CaptionAbove.Text = loadedSettings.CaptionAbove.Text; + generator.Parameters.CaptionAbove.Font.FamilyName = loadedSettings.CaptionAbove.FontFamily; + generator.Parameters.CaptionAbove.Font.Size.Point = loadedSettings.CaptionAbove.FontSize; + if (Enum.TryParse(loadedSettings.CaptionAbove.Alignment, out var alignAbove)) + { + generator.Parameters.CaptionAbove.Alignment = alignAbove; + } + generator.Parameters.CaptionAbove.TextColor = Aspose.Drawing.Color.FromArgb(loadedSettings.CaptionAbove.TextColorArgb); + } - // Apply caption below settings - generator.Parameters.CaptionBelow.Text = loadedSettings.CaptionBelowText; - generator.Parameters.CaptionBelow.Font.FamilyName = loadedSettings.CaptionBelowFontFamily; - generator.Parameters.CaptionBelow.Font.Size.Point = loadedSettings.CaptionBelowFontSize; - generator.Parameters.CaptionBelow.Alignment = (TextAlignment)Enum.Parse(typeof(TextAlignment), loadedSettings.CaptionBelowAlignment); - generator.Parameters.CaptionBelow.Visible = loadedSettings.CaptionBelowVisible; + // Apply the "below" caption if it exists + if (loadedSettings.CaptionBelow != null) + { + generator.Parameters.CaptionBelow.Text = loadedSettings.CaptionBelow.Text; + generator.Parameters.CaptionBelow.Font.FamilyName = loadedSettings.CaptionBelow.FontFamily; + generator.Parameters.CaptionBelow.Font.Size.Point = loadedSettings.CaptionBelow.FontSize; + if (Enum.TryParse(loadedSettings.CaptionBelow.Alignment, out var alignBelow)) + { + generator.Parameters.CaptionBelow.Alignment = alignBelow; + } + generator.Parameters.CaptionBelow.TextColor = Aspose.Drawing.Color.FromArgb(loadedSettings.CaptionBelow.TextColorArgb); + } - // Save the restored barcode image - generator.Save(restoredImagePath); + // Save the regenerated barcode image to disk + generator.Save(reloadedImagePath); } - // Output file locations for verification + // Inform the user where the output files are located Console.WriteLine($"Original barcode saved to: {originalImagePath}"); - Console.WriteLine($"Settings serialized to: {settingsPath}"); - Console.WriteLine($"Restored barcode saved to: {restoredImagePath}"); + Console.WriteLine($"Reloaded barcode saved to: {reloadedImagePath}"); + Console.WriteLine($"Settings JSON saved to: {jsonPath}"); } } } \ No newline at end of file diff --git a/barcode-text-customization/set-barcode-text-location-to-below-for-pdf417-barcodes-using-default-textlocationbelow-setting.cs b/barcode-text-customization/set-barcode-text-location-to-below-for-pdf417-barcodes-using-default-textlocationbelow-setting.cs index e5b2443..b2a26aa 100644 --- a/barcode-text-customization/set-barcode-text-location-to-below-for-pdf417-barcodes-using-default-textlocationbelow-setting.cs +++ b/barcode-text-customization/set-barcode-text-location-to-below-for-pdf417-barcodes-using-default-textlocationbelow-setting.cs @@ -1,36 +1,41 @@ // Title: Set PDF417 barcode text location below -// Description: Demonstrates how to position human‑readable text beneath a PDF417 barcode using Aspose.BarCode. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and CodeLocation to customize barcode appearance. Developers often need to control text placement for readability in printed or digital media, and this snippet shows the default Below setting for PDF417 symbology. +// Description: Demonstrates how to generate a PDF417 barcode with the human‑readable text positioned below the symbol using Aspose.BarCode. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on configuring text placement for 2‑D symbologies. It showcases the use of BarcodeGenerator, EncodeTypes, and CodeTextParameters to control the CodeLocation property. Developers often need to adjust human‑readable text positions for scanning applications, documentation, or labeling, and this snippet illustrates the default Below setting for PDF417 barcodes. // Prompt: Set barcode text location to below for PDF417 barcodes, using the default TextLocation.Below setting. -// Tags: pdf417, textlocation, below, barcode generation, aspose.barcode +// Tags: pdf417, barcode, textlocation, below, generation, aspose.barcode, png using System; +using System.IO; +using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Entry point for the PDF417 barcode text location example. +/// Demonstrates generating a PDF417 barcode with the human‑readable text placed below the symbol. /// class Program { /// - /// Generates a PDF417 barcode with the human‑readable text placed below the symbol and saves it as a PNG file. + /// Entry point that creates the barcode, configures text location, saves the image, and writes the output path. /// static void Main() { - // Initialize the barcode generator with PDF417 symbology and sample data - using (var generator = new BarcodeGenerator(EncodeTypes.Pdf417, "Sample PDF417 Text")) + // Define the output file path for the generated PNG image + string outputPath = "pdf417_below.png"; + + // Initialize a PDF417 barcode generator within a using block to ensure proper disposal + using (var generator = new BarcodeGenerator(EncodeTypes.Pdf417)) { - // Configure the text location to appear below the barcode (default setting) - generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; + // Assign the data that will be encoded into the barcode + generator.CodeText = "Sample PDF417 Text"; - // Define output file path - string outputPath = "pdf417_below.png"; + // Configure the human‑readable text to appear below the barcode (default setting) + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; - // Render and save the barcode image in PNG format + // Save the generated barcode as a PNG file at the specified location generator.Save(outputPath, BarCodeImageFormat.Png); - - // Inform the user where the file was saved - Console.WriteLine($"Barcode saved to {outputPath}"); } + + // Output the full path of the saved barcode image for verification + Console.WriteLine($"Barcode saved to {Path.GetFullPath(outputPath)}"); } } \ No newline at end of file diff --git a/barcode-text-customization/set-barcode-text-spacing-to-25-pixels-for-batch-of-aztec-barcodes-to-improve-readability.cs b/barcode-text-customization/set-barcode-text-spacing-to-25-pixels-for-batch-of-aztec-barcodes-to-improve-readability.cs index 8612388..d3c3866 100644 --- a/barcode-text-customization/set-barcode-text-spacing-to-25-pixels-for-batch-of-aztec-barcodes-to-improve-readability.cs +++ b/barcode-text-customization/set-barcode-text-spacing-to-25-pixels-for-batch-of-aztec-barcodes-to-improve-readability.cs @@ -1,8 +1,8 @@ -// Title: Generate batch of Aztec barcodes with custom text spacing -// Description: Demonstrates setting the human‑readable text spacing to 2.5 pixels for each Aztec barcode in a batch, then saving them as PNG images. -// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to configure barcode appearance using BarcodeGenerator, EncodeTypes, and CodeTextParameters. Typical use cases include creating multiple barcodes with consistent visual settings for inventory, ticketing, or packaging applications. Developers often need to adjust text spacing, size, or font to meet branding or readability requirements. +// Title: Set text spacing for batch Aztec barcodes +// Description: Demonstrates how to generate multiple Aztec barcodes with a custom human‑readable text spacing of 2.5 pixels, improving readability of the printed codes. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on Aztec symbology and visual customization. It showcases the use of BarcodeGenerator, EncodeTypes, and CodeTextParameters to adjust text layout. Developers often need to tweak text spacing, location, and other rendering options when creating batches of barcodes for labeling or packaging applications. // Prompt: Set barcode text spacing to 2.5 pixels for a batch of Aztec barcodes to improve readability. -// Tags: aztec, barcode, text spacing, generation, png, aspose.barcode +// Tags: aztec, barcode, text-spacing, batch, png, aspose.barcode using System; using System.IO; @@ -10,38 +10,46 @@ using Aspose.BarCode.Generation; /// -/// Demonstrates generating a batch of Aztec barcodes with custom text spacing. +/// Generates a batch of Aztec barcodes with custom text spacing. /// class Program { /// - /// Entry point. Generates Aztec barcodes from a list of code texts, sets text spacing to 2.5 pixels, and saves each as a PNG file. + /// Entry point that creates the output folder, defines sample texts, and saves each barcode image. /// static void Main() { - // Sample codetexts for the batch - string[] codetexts = { "ABC123", "XYZ789", "HELLO", "WORLD", "AZTEC" }; + // Prepare output folder for generated barcode images + string outputFolder = Path.Combine(Directory.GetCurrentDirectory(), "AztecBarcodes"); + if (!Directory.Exists(outputFolder)) + { + Directory.CreateDirectory(outputFolder); + } - // Ensure the output directory exists - string outputDir = "AztecBarcodes"; - Directory.CreateDirectory(outputDir); + // Sample code texts for the batch of barcodes + string[] codeTexts = new string[] + { + "ABC123", + "HelloWorld", + "1234567890", + "AztecTest", + "Sample5" + }; - // Iterate over each codetext and generate a barcode - for (int i = 0; i < codetexts.Length; i++) + // Iterate through each text value and generate an Aztec barcode + for (int i = 0; i < codeTexts.Length; i++) { - // Create a generator for the current codetext using Aztec symbology - using (var generator = new BarcodeGenerator(EncodeTypes.Aztec, codetexts[i])) + using (var generator = new BarcodeGenerator(EncodeTypes.Aztec, codeTexts[i])) { // Set human‑readable text spacing to 2.5 pixels generator.Parameters.Barcode.CodeTextParameters.Space.Point = 2.5f; - // Build the file path for the PNG output - string filePath = Path.Combine(outputDir, $"Aztec_{i + 1}.png"); - - // Save the barcode image in PNG format - generator.Save(filePath, BarCodeImageFormat.Png); + // Place the code text below the barcode for better visual separation + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; - // Log the saved file location + // Build the file path and save the barcode as a PNG image + string filePath = Path.Combine(outputFolder, $"Aztec_{i + 1}.png"); + generator.Save(filePath); Console.WriteLine($"Saved: {filePath}"); } } diff --git a/barcode-text-customization/set-bottom-caption-padding-to-8-pixels-for-datamatrix-barcodes-to-create-visual-separation-from-symbol.cs b/barcode-text-customization/set-bottom-caption-padding-to-8-pixels-for-datamatrix-barcodes-to-create-visual-separation-from-symbol.cs index 777870e..a73f342 100644 --- a/barcode-text-customization/set-bottom-caption-padding-to-8-pixels-for-datamatrix-barcodes-to-create-visual-separation-from-symbol.cs +++ b/barcode-text-customization/set-bottom-caption-padding-to-8-pixels-for-datamatrix-barcodes-to-create-visual-separation-from-symbol.cs @@ -1,38 +1,41 @@ // Title: Set bottom caption padding for DataMatrix barcode -// Description: Demonstrates how to apply an 8‑pixel bottom padding to the caption of a DataMatrix barcode, creating visual separation between the text and the symbol. -// Category-Description: This example belongs to the Aspose.BarCode generation category, focusing on caption customization for 2‑D symbologies. It showcases the use of BarcodeGenerator, EncodeTypes, and the Parameters.CaptionBelow API to adjust padding, text, and other visual aspects. Developers often need to fine‑tune caption layout for branding, readability, or design compliance when embedding barcodes in documents or UI. +// Description: Demonstrates how to set an 8‑pixel bottom padding for the caption of a DataMatrix barcode and save it as a PNG image. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to customize barcode appearance using the BarcodeGenerator class. It shows configuring caption text and padding, a common requirement when developers need visual separation between the barcode symbol and its descriptive text. Typical use cases include creating printable labels or UI elements where caption spacing improves readability. // Prompt: Set bottom caption padding to 8 pixels for DataMatrix barcodes to create visual separation from the symbol. -// Tags: datamatrix, caption, padding, barcode, generation, image, aspose.barcode +// Tags: datamatrix, caption, padding, barcode generation, aspnet, png, aspose.barcode using System; +using System.IO; using Aspose.BarCode.Generation; -using Aspose.BarCode; +using Aspose.Drawing; /// -/// Generates a DataMatrix barcode and sets an 8‑pixel bottom padding for its caption. +/// Demonstrates setting bottom caption padding for a DataMatrix barcode and saving it as PNG. /// class Program { /// - /// Entry point of the example. Creates a DataMatrix barcode, configures caption padding, and saves the image. + /// Entry point. Generates a DataMatrix barcode with a caption and custom bottom padding, then saves the image. /// static void Main() { - // Initialize a DataMatrix barcode generator with sample text. - using (var generator = new BarcodeGenerator(EncodeTypes.DataMatrix, "Sample DataMatrix")) + // Define the output file name + string outputPath = "datamatrix.png"; + + // Initialize a DataMatrix barcode generator with the desired text + using (var generator = new BarcodeGenerator(EncodeTypes.DataMatrix, "ABC123")) { - // Set the bottom padding of the caption (below the barcode) to 8 pixels. - // The Padding property uses Unit members; here we specify Pixels for the bottom side. - generator.Parameters.CaptionBelow.Padding.Bottom.Pixels = 8f; + // Configure the caption that appears below the barcode symbol + generator.Parameters.CaptionBelow.Text = "DataMatrix"; - // Optionally assign caption text to visualize the padding effect. - generator.Parameters.CaptionBelow.Text = "Bottom Caption"; + // Apply an 8‑pixel bottom padding to separate the caption from the symbol + generator.Parameters.CaptionBelow.Padding.Bottom.Point = 8f; - // Save the generated barcode image to a PNG file. - generator.Save("DataMatrixWithBottomPadding.png"); + // Render and save the barcode image in PNG format + generator.Save(outputPath, BarCodeImageFormat.Png); } - // Inform the user that the barcode has been generated. - Console.WriteLine("Barcode generated successfully."); + // Output the full path of the saved image for user reference + Console.WriteLine($"Barcode image saved to: {Path.GetFullPath(outputPath)}"); } } \ No newline at end of file diff --git a/barcode-text-customization/show-main-barcode-text-for-all-generated-code128-barcodes-by-setting-codetextparametersvisible-to-true.cs b/barcode-text-customization/show-main-barcode-text-for-all-generated-code128-barcodes-by-setting-codetextparametersvisible-to-true.cs index 7b6a208..9c4b67d 100644 --- a/barcode-text-customization/show-main-barcode-text-for-all-generated-code128-barcodes-by-setting-codetextparametersvisible-to-true.cs +++ b/barcode-text-customization/show-main-barcode-text-for-all-generated-code128-barcodes-by-setting-codetextparametersvisible-to-true.cs @@ -1,30 +1,51 @@ +// Title: Display Human‑Readable Text for Code128 Barcodes +// Description: Generates several Code128 barcodes and makes the main barcode text visible below each barcode. +// Category-Description: This example belongs to the Aspose.BarCode generation category, demonstrating how to configure CodeTextParameters (Location, Alignment, Visibility) for human‑readable output. Typical use cases include creating printable labels, inventory tags, or shipping documents where the encoded data must also be shown as text. Developers often need to adjust text placement and styling when working with BarcodeGenerator and related API classes such as Parameters, Barcode, and CodeTextParameters. +/// +/// Demonstrates how to generate Code128 barcodes with visible human‑readable text using Aspose.BarCode. +/// using System; -using System.Collections.Generic; +using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; -namespace BarcodeDemo +/// +/// Main program class. +/// +class Program { - class Program + /// + /// Entry point. Generates Code128 barcodes, shows the barcode text below each image, and saves them as PNG files. + /// + static void Main() { - static void Main() + // Define sample texts to encode. + string[] texts = { "ABC123", "1234567890", "CODE128" }; + + // Prepare output directory. + string outputDir = "Barcodes"; + Directory.CreateDirectory(outputDir); + + // Iterate over each text, generate a barcode, and save it. + for (int i = 0; i < texts.Length; i++) { - var samples = new List { "ABC123", "9876543210", "CODE128TEST" }; - int index = 1; - foreach (var text in samples) + string text = texts[i]; + string filePath = Path.Combine(outputDir, $"code128_{i + 1}.png"); + + // Create a BarcodeGenerator for Code128 with the current text. + using (var generator = new BarcodeGenerator(EncodeTypes.Code128, text)) { - using (var generator = new BarcodeGenerator(EncodeTypes.Code128, text)) - { - // Show the human‑readable text below the barcode - generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; - generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center; + // Show human‑readable text below the barcode. + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; + // Center the text horizontally. + generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center; - string fileName = $"code128_{index}.png"; - generator.Save(fileName); - Console.WriteLine($"Saved {fileName} with text '{text}'."); - } - index++; + // Save the barcode image as PNG. + generator.Save(filePath, BarCodeImageFormat.Png); } + + // Inform the user about the saved file. + Console.WriteLine($"Saved barcode for '{text}' to '{filePath}'."); } } } \ No newline at end of file diff --git a/barcode-text-customization/show-top-caption-for-pdf417-barcodes-by-setting-captionparameterstopvisible-to-true.cs b/barcode-text-customization/show-top-caption-for-pdf417-barcodes-by-setting-captionparameterstopvisible-to-true.cs index b9c8c6e..6770ed5 100644 --- a/barcode-text-customization/show-top-caption-for-pdf417-barcodes-by-setting-captionparameterstopvisible-to-true.cs +++ b/barcode-text-customization/show-top-caption-for-pdf417-barcodes-by-setting-captionparameterstopvisible-to-true.cs @@ -1,12 +1,12 @@ // Title: PDF417 Barcode with Top Caption -// Description: Demonstrates how to display a top caption on a PDF417 barcode using Aspose.BarCode. -// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on caption customization for 2D symbologies. It showcases the use of BarcodeGenerator, EncodeTypes, and CaptionParameters to add and style captions above the barcode. Developers often need to add descriptive text above or below barcodes for better readability in documents and labels. +// Description: Demonstrates how to generate a PDF417 barcode and display a caption above it using Aspose.BarCode. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and caption parameters to customize barcode appearance. Developers often need to add human‑readable text (captions) above or below barcodes for labeling, documentation, or UI purposes. The snippet shows typical steps: creating a generator, configuring caption visibility, text, and font, then saving the image. // Prompt: Show top caption for PDF417 barcodes by setting CaptionParameters.Top.Visible to true. -// Tags: pdf417, barcode, caption, top caption, aspnet, aspnetcore, aspose.barcode, image generation, 2d barcode, c# +// Tags: pdf417, barcode, caption, generation, image, aspose.barcode, csharp using System; -using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing; /// /// Generates a PDF417 barcode with a visible top caption and saves it as an image file. @@ -14,28 +14,26 @@ class Program { /// - /// Entry point of the application. Creates a PDF417 barcode, configures a top caption, and saves the result. + /// Entry point of the example. Creates a barcode, configures the top caption, and writes the result to disk. /// static void Main() { - // Initialize a PDF417 barcode generator with the desired text. - using (var generator = new BarcodeGenerator(EncodeTypes.Pdf417, "Sample PDF417 Text")) + // Initialize a PDF417 barcode generator with the desired data. + using (var generator = new BarcodeGenerator(EncodeTypes.Pdf417, "Sample PDF417")) { - // Enable the top caption (CaptionAbove) and assign its display text. + // Enable the caption that appears above the barcode. generator.Parameters.CaptionAbove.Visible = true; - generator.Parameters.CaptionAbove.Text = "Top Caption"; - // Customize the appearance of the top caption. - generator.Parameters.CaptionAbove.Font.FamilyName = "Arial"; + // Set the caption text and its font size. + generator.Parameters.CaptionAbove.Text = "Top Caption"; generator.Parameters.CaptionAbove.Font.Size.Point = 12f; - generator.Parameters.CaptionAbove.Alignment = TextAlignment.Center; - generator.Parameters.CaptionAbove.TextColor = Aspose.Drawing.Color.Black; - // Save the generated barcode image to a PNG file. - generator.Save("pdf417_with_top_caption.png"); - } + // Define the output file path and save the barcode as a PNG image. + string outputPath = "pdf417_with_caption.png"; + generator.Save(outputPath); - // Inform the user that the barcode image has been created. - Console.WriteLine("Barcode image generated: pdf417_with_top_caption.png"); + // Inform the user where the barcode image was saved. + Console.WriteLine($"Barcode saved to {outputPath}"); + } } } \ No newline at end of file diff --git a/barcode-text-customization/write-unit-tests-that-verify-toggling-codetextparametersvisible-correctly-shows-and-hides-main-barcode-text.cs b/barcode-text-customization/write-unit-tests-that-verify-toggling-codetextparametersvisible-correctly-shows-and-hides-main-barcode-text.cs index 888b415..a670470 100644 --- a/barcode-text-customization/write-unit-tests-that-verify-toggling-codetextparametersvisible-correctly-shows-and-hides-main-barcode-text.cs +++ b/barcode-text-customization/write-unit-tests-that-verify-toggling-codetextparametersvisible-correctly-shows-and-hides-main-barcode-text.cs @@ -1,58 +1,115 @@ -// Title: Toggle CodeText Visibility and Verify Image Height Change -// Description: Demonstrates how to hide and show the human‑readable text of a Code128 barcode and checks that the image height changes accordingly. -// Category-Description: This example belongs to the Aspose.BarCode generation category, focusing on barcode appearance customization. It uses BarcodeGenerator, CodeTextParameters, and CodeLocation to control the visibility of the main codetext. Developers often need to toggle human‑readable text for different output requirements, such as compact images or printable labels. The snippet shows typical steps for setting parameters, generating images, and performing a simple validation. +// Title: Demonstrate toggling barcode text visibility with CodeTextParameters.Location +// Description: Shows how to show or hide the human‑readable text of a barcode by setting CodeTextParameters.Location to Below or None, and verifies the behavior with simple assertions. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of the BarcodeGenerator and its Parameters.Barcode.CodeTextParameters API. Developers commonly need to control barcode text visibility for labeling, packaging, or UI display scenarios. The code demonstrates typical use cases such as setting text location, generating an image, and performing lightweight validation without external test frameworks. // Prompt: Write unit tests that verify toggling CodetextParameters.Visible correctly shows and hides the main barcode text. -// Tags: code128, codetextvisibility, bitmap, aspose.barcode, generation, unit-test, debug.assert +// Tags: barcode, code128, codetextparameters, visibility, unit-test, aspose.barcode, generation using System; -using System.Diagnostics; -using Aspose.BarCode; +using System.IO; using Aspose.BarCode.Generation; -using Aspose.Drawing; +using Aspose.BarCode.BarCodeRecognition; +using Aspose.BarCode; /// -/// Example program that toggles the visibility of the barcode's main codetext -/// and verifies the resulting image height changes as expected. +/// Contains simple test methods that verify showing and hiding barcode text using Aspose.BarCode. /// class Program { + // Counter for failed tests + static int _failedTests = 0; + /// - /// Entry point of the example. Generates two barcode images—one with - /// visible text and one without—and asserts that the image without text - /// is shorter, confirming the visibility toggle works. + /// Entry point. Executes the visibility tests and reports results. /// static void Main() { - // Initialize a BarcodeGenerator for Code128 with sample codetext. - using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "12345")) + // Run test that ensures barcode text is visible + TestShowCodeText(); + + // Run test that ensures barcode text is hidden + TestHideCodeText(); + + // Report overall test outcome + if (_failedTests == 0) { - // Set the default location of the human‑readable text to appear below the barcode. + Console.WriteLine("ALL TESTS PASSED"); + } + else + { + Console.WriteLine($"FAILED: {_failedTests} test(s) failed."); + } + } + + /// + /// Simple assertion helper that logs pass/fail and updates the failure counter. + /// + /// Result of the condition being tested. + /// Name of the test case. + static void Assert(bool condition, string testName) + { + if (!condition) + { + Console.WriteLine($"FAIL: {testName}"); + _failedTests++; + } + else + { + Console.WriteLine($"PASS: {testName}"); + } + } + + /// + /// Verifies that setting CodeTextParameters.Location to Below makes the barcode text visible. + /// + static void TestShowCodeText() + { + const string testName = "TestShowCodeText"; + + // Create a barcode generator for Code128 with sample data + using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "ABC123")) + { + // Show the human‑readable text by setting location to Below generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; - // Generate the first image where the text is visible. - using (Bitmap imageWithText = generator.GenerateBarCodeImage()) + // Verify the location property was set correctly + bool locationIsBelow = generator.Parameters.Barcode.CodeTextParameters.Location == CodeLocation.Below; + Assert(locationIsBelow, testName + " - Location set to Below"); + + // Save the barcode to a memory stream to ensure generation succeeds + using (var ms = new MemoryStream()) + { + generator.Save(ms, BarCodeImageFormat.Png); + // Simple sanity check: the stream should contain data + bool hasData = ms.Length > 0; + Assert(hasData, testName + " - Image generated"); + } + } + } + + /// + /// Verifies that setting CodeTextParameters.Location to None hides the barcode text. + /// + static void TestHideCodeText() + { + const string testName = "TestHideCodeText"; + + // Create a barcode generator for Code128 with different sample data + using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "XYZ789")) + { + // Hide the human‑readable text by setting location to None + generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None; + + // Verify the location property was set correctly + bool locationIsNone = generator.Parameters.Barcode.CodeTextParameters.Location == CodeLocation.None; + Assert(locationIsNone, testName + " - Location set to None"); + + // Save the barcode to a memory stream to ensure generation succeeds + using (var ms = new MemoryStream()) { - int heightWithText = imageWithText.Height; // Record height with text. - - // Hide the human‑readable text by moving it to the 'None' location. - generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None; - - // Generate the second image where the text is hidden. - using (Bitmap imageWithoutText = generator.GenerateBarCodeImage()) - { - int heightWithoutText = imageWithoutText.Height; // Record height without text. - - // Determine whether the image without text is shorter. - bool isHeightReduced = heightWithoutText < heightWithText; - - // Assert the height reduction and output the result. - Debug.Assert(isHeightReduced, "Image height should be reduced when CodeText is hidden."); - Console.WriteLine($"Height with text: {heightWithText}"); - Console.WriteLine($"Height without text: {heightWithoutText}"); - Console.WriteLine(isHeightReduced - ? "Test passed: Text visibility toggling correctly changes image size." - : "Test failed: Image size did not change as expected."); - } + generator.Save(ms, BarCodeImageFormat.Png); + // Simple sanity check: the stream should contain data + bool hasData = ms.Length > 0; + Assert(hasData, testName + " - Image generated"); } } }