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,39 +1,38 @@
// Title: Adjust barcode text font and alignment
// Description: Demonstrates how to set the barcode's human‑readable text to Arial 12 pt and center it beneath the bars.
// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to customize CodeTextParameters such as font, size, alignment, and location. It uses the BarcodeGenerator class together with EncodeTypes and CodeTextParameters to produce barcodes with tailored human‑readable text. Developers often need to modify these settings to match branding guidelines or improve readability in printed materials.
// Title: Generate Code128 barcode with centered Arial text
// Description: Demonstrates creating a Code128 barcode, placing human‑readable text below the bars, centering it, and applying an Arial‑like 12 pt font.
// Category-Description: This example belongs to the Aspose.BarCode generation category, showcasing how to use BarcodeGenerator, EncodeTypes, and CodeTextParameters to produce barcodes with customized human‑readable text. Typical use cases include product labeling, inventory tracking, and shipping documents where readable text must accompany the barcode. Developers often need to adjust text position, alignment, and font styling to meet branding or regulatory requirements.
// Prompt: Adjust barcode text font to Arial, size 12 pt, and center the text beneath the bars.
// Tags: barcode, code128, font, alignment, textlocation, generation, aspnet, aspose.barcode
// Tags: code128, barcode generation, text formatting, png output, aspose.barcode, font settings

using System;
using Aspose.BarCode;
using Aspose.BarCode.Generation;
using Aspose.Drawing;

/// <summary>
/// Demonstrates adjusting barcode text font to Arial 12 pt and centering it below the bars.
/// Example program that creates a Code128 barcode with centered, Arial‑style text placed below the bars.
/// </summary>
class Program
{
/// <summary>
/// Generates a Code128 barcode with customized text appearance and saves it as PNG.
/// Entry point that configures barcode parameters and saves the image as PNG.
/// </summary>
static void Main()
{
// Initialize a barcode generator for Code128 with the sample value "1234567890"
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890"))
// Initialize a BarcodeGenerator for Code128 with the sample value "123456"
using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128, "123456"))
{
// Configure the human‑readable text font: Arial, 12 pt
generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial";
generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f;
// Position the human‑readable text below the barcode bars
generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below;

// Align the text to the center and position it below the barcode bars
// Align the text to the center of the barcode
generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center;
generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below;

// Set the font to Helvetica (Arial equivalent) with a size of 12 points
generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Helvetica";
generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f;

// Save the generated barcode image to a PNG file
generator.Save("barcode.png");
}

// Inform the user that the barcode has been created
Console.WriteLine("Barcode generated: barcode.png");
}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
// Title: Center-aligned barcode text with automatic scaling
// Description: Demonstrates how to center the human‑readable text of a Code128 barcode and enable automatic scaling to fit a narrow image width.
// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and related parameter classes to customize barcode appearance. Typical scenarios include creating compact barcodes for limited‑space labels while preserving readability. Developers often need to adjust text alignment, font sizing, and image dimensions to meet layout constraints.
// Title: Center barcode text and enable auto scaling for narrow width
// Description: Demonstrates how to center the human‑readable text of a Code128 barcode and automatically scale the image to fit a specified narrow width.
// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and barcode parameters such as CodeTextParameters.Alignment and AutoSizeMode. Developers often need to adjust text alignment and automatically resize barcodes for tight layout constraints in documents, labels, or web pages. The snippet shows typical steps for configuring alignment, scaling mode, and image dimensions before saving the barcode image.
// Prompt: Align barcode text to center and enable automatic scaling to fit within narrow barcode width.
// Tags: code128, text alignment, auto scaling, png, aspose.barcode, barcode generation
// Tags: code128, barcode, text alignment, autoscaling, image size, aspnet, aspose.barcode, generation, png

using System;
using Aspose.BarCode;
using Aspose.BarCode.Generation;
using Aspose.Drawing;

/// <summary>
/// Generates a Code128 barcode with centered human‑readable text and automatic scaling
/// to fit a narrow image width, then saves it as a PNG file.
/// Generates a Code128 barcode with centered human‑readable text and
/// automatically scales the image to fit a narrow width.
/// </summary>
class Program
{
/// <summary>
/// Entry point of the example. Creates a barcode, configures text alignment and scaling,
/// and writes the result to "barcode.png".
/// Entry point of the example. Configures barcode parameters,
/// applies text alignment and auto‑scaling, then saves the image.
/// </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 sample text
using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890"))
{
// Set the data that will be encoded in the barcode.
generator.CodeText = "1234567890";
// Center the human‑readable text beneath the barcode
generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center;

// Configure automatic scaling (interpolation) so the barcode adapts to the image size.
// Enable automatic scaling to fit a narrow width using interpolation
generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation;

// Define a narrow image width (150 points) and a suitable height (50 points).
// Set the desired image width (points); adjust as needed for layout constraints
generator.Parameters.ImageWidth.Point = 150f;
generator.Parameters.ImageHeight.Point = 50f;

// Center‑align the human‑readable text beneath the barcode.
generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center;

// Enable automatic font sizing so the text scales proportionally with the barcode.
generator.Parameters.Barcode.CodeTextParameters.FontMode = FontMode.Auto;
// Set the desired image height (points); optional—omit to preserve aspect ratio
generator.Parameters.ImageHeight.Point = 50f;

// Save the generated barcode image to a PNG file.
generator.Save("barcode.png");
// Save the generated barcode image; format inferred from file extension
generator.Save("centered_scaled.png");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,56 +1,63 @@
// Title: Center-aligned Code128 barcode with auto scaling for receipt printing
// Description: Generates a Code128 barcode with centered human‑readable text, automatic scaling, and a narrow image suitable for receipt printers.
// Category-Description: This example demonstrates Aspose.BarCode generation features such as setting image dimensions, resolution, text alignment, and auto‑scaling. It uses the BarcodeGenerator, EncodeTypes, and related parameter classes to create barcodes for point‑of‑sale scenarios where narrow, high‑resolution images are required. Developers often need to customize size, DPI, and text appearance for receipt or label printing.
// Title: Center-aligned Code128 barcode with auto-scaling for receipt printing
// Description: Demonstrates how to generate a narrow receipt‑friendly Code128 barcode, centering the human‑readable text and enabling automatic scaling to fit a specific image width.
// Category-Description: This example belongs to the Aspose.BarCode image generation category, illustrating use of BarcodeGenerator, EncodeTypes, and image formatting classes. Typical use cases include creating barcodes for point‑of‑sale receipts, tickets, or labels where space is limited. Developers often need to control text alignment, scaling mode, and output dimensions to produce clear, printable barcodes.
// Prompt: Align barcode text to center, enable automatic scaling, and generate image suitable for narrow receipt printing.
// Tags: code128, barcode, auto-scaling, receipt, png, aspose.barcode, generation
// Tags: code128, alignment, autoscaling, png, barcodegenerator, aspose.barcode, aspose.drawing

using System;
using System.IO;
using Aspose.BarCode;
using Aspose.BarCode.Generation;
using Aspose.Drawing;
using Aspose.Drawing.Imaging;

/// <summary>
/// Demonstrates how to generate a narrow, center‑aligned Code128 barcode with automatic scaling,
/// suitable for receipt printers.
/// Generates a Code128 barcode image that is centered, auto‑scaled, and sized for narrow receipt printers.
/// </summary>
class Program
{
/// <summary>
/// Entry point of the example. Creates a barcode, configures scaling and alignment,
/// and saves the result as a PNG image.
/// Entry point of the example. Creates the barcode, configures alignment and scaling, and saves it as a PNG file.
/// </summary>
static void Main()
{
// Text to be encoded in the barcode.
// Define the barcode content and output file name
const string codeText = "1234567890";
const string outputPath = "receipt_barcode.png";

// Initialize the barcode generator for Code128 symbology.
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, codeText))
// Ensure the output directory exists (creates it if missing)
string outputDir = Path.GetDirectoryName(Path.GetFullPath(outputPath));
if (!Directory.Exists(outputDir))
{
// Enable automatic scaling (interpolation) to fit the target image size.
generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation;
Directory.CreateDirectory(outputDir);
}

// Define a narrow receipt width and modest height (points).
generator.Parameters.ImageWidth.Point = 200f; // Width in points.
generator.Parameters.ImageHeight.Point = 50f; // Height in points.
// Initialize the barcode generator with Code128 symbology
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, codeText))
{
// Center the human‑readable text beneath the barcode
generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center;
generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below;

// Set the printer resolution typical for receipt printers (203 DPI).
generator.Parameters.Resolution = 203f;
// Enable automatic scaling (interpolation) to fit the target width
generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation;

// Center‑align the human‑readable text beneath the barcode.
generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center;
// Set the desired image width for a typical receipt printer (≈2.78 in)
generator.Parameters.ImageWidth.Point = 200f;
// Height is auto‑calculated based on content and scaling mode

// Ensure the text font scales automatically with the barcode size.
generator.Parameters.Barcode.CodeTextParameters.FontMode = FontMode.Auto;
// Use a small X‑dimension so the barcode fits within the narrow width
generator.Parameters.Barcode.XDimension.Point = 1f;

// Set barcode bar color to black and background to white.
// Define barcode and background colors (black on white)
generator.Parameters.Barcode.BarColor = Color.Black;
generator.Parameters.BackColor = Color.White;

// Save the generated barcode image to a PNG file.
const string outputPath = "receipt_barcode.png";
generator.Save(outputPath);
Console.WriteLine($"Barcode saved to {outputPath}");
// Save the generated barcode as a PNG image
generator.Save(outputPath, BarCodeImageFormat.Png);
}

// Inform the user where the image was saved
Console.WriteLine($"Barcode image saved to: {Path.GetFullPath(outputPath)}");
}
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
// Title: Align Code128 barcode text left with autoscaling for narrow column layout
// Description: Demonstrates how to left‑align human‑readable text, enable automatic scaling, and set image size for a narrow column using Aspose.BarCode.
// Category-Description: This example belongs to the Aspose.BarCode image generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and Parameters classes to customize barcode appearance. Typical scenarios include creating compact barcodes for reports, invoices, or mobile screens where space is limited. Developers often need to control text alignment, scaling mode, and image dimensions to fit specific layout constraints.
// Title: Align barcode text left with auto scaling for narrow column
// Description: Demonstrates how to left‑align the human‑readable text of a Code128 barcode, enable automatic scaling, and set image dimensions for a narrow column layout.
// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and barcode parameters such as CodeTextParameters, AutoSizeMode, and image size settings. Typical use cases include creating compact barcodes for reports, invoices, or mobile screens where space is limited. Developers often need to control text alignment and scaling to fit barcodes into constrained layouts.
// Prompt: Align barcode text to left, enable automatic scaling, and generate image suitable for narrow column layout.
// Tags: code128, alignment, autoscaling, png, barcodegenerator, parameters, aspose.barcode, imagegeneration
// Tags: code128, barcode, text-alignment, autoscaling, narrow-layout, png, aspose.barcode, generation

using System;
using Aspose.BarCode;
using Aspose.BarCode.Generation;
using Aspose.Drawing;

/// <summary>
/// Generates a Code128 barcode with left‑aligned text, automatic scaling, and a compact image size.
/// Generates a Code128 barcode with left‑aligned text, automatic scaling, and a narrow image size.
/// </summary>
class Program
{
/// <summary>
/// Entry point that creates and saves the barcode image.
/// Entry point that creates, configures, and saves the barcode image.
/// </summary>
static void Main()
{
// Initialize a barcode generator for Code128 with the sample value.
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890"))
// Initialize a barcode generator for Code128 with sample data
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "123456789"))
{
// Enable automatic scaling using interpolation to fit the specified dimensions.
generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation;

// Define image size (points) suitable for a narrow column layout.
generator.Parameters.ImageWidth.Point = 150f;
generator.Parameters.ImageHeight.Point = 50f;

// Align the human‑readable text to the left side of the barcode.
// Set human‑readable text alignment to the left side of the barcode
generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Left;

// Optional: adjust the module (X) dimension for clearer rendering at small sizes.
generator.Parameters.Barcode.XDimension.Point = 2f;
// Enable automatic scaling using interpolation to fit a narrow column
generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation;

// Save the generated barcode as a PNG file.
generator.Save("barcode.png");
}
// Define a narrow image width and a suitable height (points)
generator.Parameters.ImageWidth.Point = 150f; // narrow width
generator.Parameters.ImageHeight.Point = 50f; // appropriate height

// Inform the user that the image has been created.
Console.WriteLine("Barcode image generated: barcode.png");
// Generate the barcode image as a bitmap
using (Aspose.Drawing.Bitmap image = generator.GenerateBarCodeImage())
{
// Save the generated image as a PNG file
generator.Save("barcode.png");
}
}
}
}
Loading
Loading