Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// 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.
/// </summary>
class Program
{
/// <summary>
/// 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.
/// </summary>
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}");
}
}
Original file line number Diff line number Diff line change
@@ -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
/// <summary>
/// Generates a set of UPC‑A barcode images with left‑aligned human‑readable text.
/// </summary>
class Program
{
/// <summary>
/// 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.
/// </summary>
class Program
static void Main()
{
/// <summary>
/// Entry point. Generates several UPC‑A barcodes with left‑aligned text and writes each to a PNG file.
/// </summary>
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}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// 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.
/// </summary>
class Program
{
/// <summary>
/// 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.
/// </summary>
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.
Expand All @@ -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.");
}
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
// 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;
using Aspose.BarCode.Generation;
using Aspose.Drawing;

/// <summary>
/// Demonstrates applying different fonts to the barcode's main text and its caption.
/// Demonstrates setting different fonts for barcode code text and caption.
/// </summary>
class Program
{
/// <summary>
/// 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.
/// </summary>
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}");
}
}
}
Loading
Loading