Skip to content

Commit 5e8f336

Browse files
author
agent-aspose-barcode-examples
committed
feat(one-dimensional-barcode-types): Add 126 Aspose.BarCode .NET C# examples for One Dimensional Barcode Types — Aspose.BarCode for .NET 26.6.0
1 parent b7273b5 commit 5e8f336

126 files changed

Lines changed: 4101 additions & 4071 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
1+
// Title: Adjust barcode text font and alignment
2+
// Description: Demonstrates how to set the barcode's human‑readable text to Arial 12 pt and center it beneath the bars.
3+
// 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.
4+
// Prompt: Adjust barcode text font to Arial, size 12 pt, and center the text beneath the bars.
5+
// Tags: barcode, code128, font, alignment, textlocation, generation, aspnet, aspose.barcode
6+
17
using System;
28
using Aspose.BarCode;
39
using Aspose.BarCode.Generation;
410

511
/// <summary>
6-
/// Demonstrates generating a Code128 barcode using Aspose.BarCode and saving it as a PNG file.
12+
/// Demonstrates adjusting barcode text font to Arial 12 pt and centering it below the bars.
713
/// </summary>
814
class Program
915
{
1016
/// <summary>
11-
/// Entry point of the application. Creates a barcode, configures its appearance, and saves it.
17+
/// Generates a Code128 barcode with customized text appearance and saves it as PNG.
1218
/// </summary>
1319
static void Main()
1420
{
15-
// Initialize a BarcodeGenerator for Code128 with the desired text
16-
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "Sample123"))
21+
// Initialize a barcode generator for Code128 with the sample value "1234567890"
22+
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890"))
1723
{
18-
// Configure the human‑readable text font: Arial, 12 pt
24+
// Configure the human‑readable text font: Arial, 12pt
1925
generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial";
2026
generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f;
2127

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

26-
// Save the generated barcode image to a PNG file named "barcode.png"
32+
// Save the generated barcode image to a PNG file
2733
generator.Save("barcode.png");
2834
}
2935

30-
// Inform the user that the barcode has been generated and saved
31-
Console.WriteLine("Barcode generated and saved as 'barcode.png'.");
36+
// Inform the user that the barcode has been created
37+
Console.WriteLine("Barcode generated: barcode.png");
3238
}
3339
}
Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
1+
// Title: Center-aligned barcode text with automatic scaling
2+
// Description: Demonstrates how to center the human‑readable text of a Code128 barcode and enable automatic scaling to fit a narrow image width.
3+
// 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.
4+
// Prompt: Align barcode text to center and enable automatic scaling to fit within narrow barcode width.
5+
// Tags: code128, text alignment, auto scaling, png, aspose.barcode, barcode generation
6+
17
using System;
28
using Aspose.BarCode;
39
using Aspose.BarCode.Generation;
10+
using Aspose.Drawing;
411

512
/// <summary>
6-
/// Demonstrates generating a Code128 barcode image using Aspose.BarCode.
13+
/// Generates a Code128 barcode with centered human‑readable text and automatic scaling
14+
/// to fit a narrow image width, then saves it as a PNG file.
715
/// </summary>
816
class Program
917
{
1018
/// <summary>
11-
/// Entry point of the application. Generates a barcode and saves it to a PNG file.
19+
/// Entry point of the example. Creates a barcode, configures text alignment and scaling,
20+
/// and writes the result to "barcode.png".
1221
/// </summary>
1322
static void Main()
1423
{
15-
// Define the output file path for the generated barcode image.
16-
string outputPath = "barcode.png";
17-
18-
// Create a BarcodeGenerator instance configured for Code128 encoding.
24+
// Initialize a barcode generator for the Code128 symbology.
1925
using (var generator = new BarcodeGenerator(EncodeTypes.Code128))
2026
{
21-
// Set the text that will be encoded into the barcode.
27+
// Set the data that will be encoded in the barcode.
2228
generator.CodeText = "1234567890";
2329

24-
// Align the human‑readable text (the code text) to the center of the barcode.
25-
generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center;
26-
27-
// Enable automatic scaling to fit a narrow width while preserving image quality.
30+
// Configure automatic scaling (interpolation) so the barcode adapts to the image size.
2831
generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation;
2932

30-
// Specify the desired image dimensions in points (1 point = 1/72 inch).
31-
generator.Parameters.ImageWidth.Point = 150f; // Narrow width
32-
generator.Parameters.ImageHeight.Point = 50f; // Height
33+
// Define a narrow image width (150 points) and a suitable height (50 points).
34+
generator.Parameters.ImageWidth.Point = 150f;
35+
generator.Parameters.ImageHeight.Point = 50f;
3336

34-
// Save the generated barcode image to the specified file path.
35-
generator.Save(outputPath);
36-
}
37+
// Center‑align the human‑readable text beneath the barcode.
38+
generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center;
3739

38-
// Inform the user that the barcode image has been saved.
39-
Console.WriteLine($"Barcode image saved to: {outputPath}");
40+
// Enable automatic font sizing so the text scales proportionally with the barcode.
41+
generator.Parameters.Barcode.CodeTextParameters.FontMode = FontMode.Auto;
42+
43+
// Save the generated barcode image to a PNG file.
44+
generator.Save("barcode.png");
45+
}
4046
}
4147
}
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,56 @@
1+
// Title: Center-aligned Code128 barcode with auto scaling for receipt printing
2+
// Description: Generates a Code128 barcode with centered human‑readable text, automatic scaling, and a narrow image suitable for receipt printers.
3+
// 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.
4+
// Prompt: Align barcode text to center, enable automatic scaling, and generate image suitable for narrow receipt printing.
5+
// Tags: code128, barcode, auto-scaling, receipt, png, aspose.barcode, generation
6+
17
using System;
28
using Aspose.BarCode;
39
using Aspose.BarCode.Generation;
10+
using Aspose.Drawing;
411

512
/// <summary>
6-
/// Demonstrates generating a Code128 barcode image suitable for narrow receipts using Aspose.BarCode.
13+
/// Demonstrates how to generate a narrow, center‑aligned Code128 barcode with automatic scaling,
14+
/// suitable for receipt printers.
715
/// </summary>
816
class Program
917
{
1018
/// <summary>
11-
/// Entry point of the application. Generates a barcode and saves it to a PNG file.
19+
/// Entry point of the example. Creates a barcode, configures scaling and alignment,
20+
/// and saves the result as a PNG image.
1221
/// </summary>
1322
static void Main()
1423
{
15-
// Define the output file path for the generated barcode image.
16-
string outputPath = "receipt_barcode.png";
24+
// Text to be encoded in the barcode.
25+
const string codeText = "1234567890";
1726

18-
// Initialize a BarcodeGenerator for Code128 with the sample data "1234567890".
19-
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890"))
27+
// Initialize the barcode generator for Code128 symbology.
28+
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, codeText))
2029
{
21-
// ------------------------------------------------------------
22-
// Configure image sizing and resolution
23-
// ------------------------------------------------------------
24-
25-
// Enable automatic scaling (interpolation) to adapt the barcode to narrow receipt widths.
30+
// Enable automatic scaling (interpolation) to fit the target image size.
2631
generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation;
2732

28-
// Set the target image dimensions in points (1 point = 1/72 inch).
29-
generator.Parameters.ImageWidth.Point = 200f; // Width of the barcode image.
30-
generator.Parameters.ImageHeight.Point = 80f; // Height of the barcode image.
31-
32-
// Use a high resolution (dots per inch) for crisp printing on receipts.
33-
generator.Parameters.Resolution = 300f;
33+
// Define a narrow receipt width and modest height (points).
34+
generator.Parameters.ImageWidth.Point = 200f; // Width in points.
35+
generator.Parameters.ImageHeight.Point = 50f; // Height in points.
3436

35-
// ------------------------------------------------------------
36-
// Configure human‑readable text appearance
37-
// ------------------------------------------------------------
37+
// Set the printer resolution typical for receipt printers (203 DPI).
38+
generator.Parameters.Resolution = 203f;
3839

39-
// Center the barcode's human‑readable text horizontally beneath the bars.
40+
// Center‑align the human‑readable text beneath the barcode.
4041
generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center;
4142

42-
// Set a readable font size for the human‑readable text (in points).
43-
generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 10f;
43+
// Ensure the text font scales automatically with the barcode size.
44+
generator.Parameters.Barcode.CodeTextParameters.FontMode = FontMode.Auto;
4445

45-
// ------------------------------------------------------------
46-
// Configure padding around the barcode within the image
47-
// ------------------------------------------------------------
48-
49-
// Apply a small uniform padding to keep the barcode away from the image edges.
50-
generator.Parameters.Barcode.Padding.Left.Point = 2f;
51-
generator.Parameters.Barcode.Padding.Right.Point = 2f;
52-
generator.Parameters.Barcode.Padding.Top.Point = 2f;
53-
generator.Parameters.Barcode.Padding.Bottom.Point = 2f;
54-
55-
// ------------------------------------------------------------
56-
// Save the generated barcode image to the specified file
57-
// ------------------------------------------------------------
46+
// Set barcode bar color to black and background to white.
47+
generator.Parameters.Barcode.BarColor = Color.Black;
48+
generator.Parameters.BackColor = Color.White;
5849

50+
// Save the generated barcode image to a PNG file.
51+
const string outputPath = "receipt_barcode.png";
5952
generator.Save(outputPath);
53+
Console.WriteLine($"Barcode saved to {outputPath}");
6054
}
61-
62-
// Inform the user where the barcode image has been saved.
63-
Console.WriteLine($"Barcode image saved to: {outputPath}");
6455
}
6556
}
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
1+
// Title: Align Code128 barcode text left with auto‑scaling for narrow column layout
2+
// Description: Demonstrates how to left‑align human‑readable text, enable automatic scaling, and set image size for a narrow column using Aspose.BarCode.
3+
// 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.
4+
// Prompt: Align barcode text to left, enable automatic scaling, and generate image suitable for narrow column layout.
5+
// Tags: code128, alignment, autoscaling, png, barcodegenerator, parameters, aspose.barcode, imagegeneration
6+
17
using System;
28
using Aspose.BarCode;
39
using Aspose.BarCode.Generation;
10+
using Aspose.Drawing;
411

512
/// <summary>
6-
/// Demonstrates generation of a narrow‑column Code128 barcode using Aspose.BarCode.
13+
/// Generates a Code128 barcode with left‑aligned text, automatic scaling, and a compact image size.
714
/// </summary>
815
class Program
916
{
1017
/// <summary>
11-
/// Entry point of the application. Generates a barcode image and saves it to disk.
18+
/// Entry point that creates and saves the barcode image.
1219
/// </summary>
1320
static void Main()
1421
{
15-
// Define the file path where the generated barcode image will be saved.
16-
string outputPath = "narrow_column_barcode.png";
17-
18-
// Create a BarcodeGenerator instance for Code128 with the sample text "123456".
19-
// The generator is wrapped in a using statement to ensure proper disposal.
20-
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "123456"))
22+
// Initialize a barcode generator for Code128 with the sample value.
23+
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890"))
2124
{
22-
// Align the human‑readable text (the encoded value) to the left side of the barcode.
23-
generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Left;
24-
25-
// Enable automatic scaling so the barcode fits the specified image dimensions.
25+
// Enable automatic scaling using interpolation to fit the specified dimensions.
2626
generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation;
2727

28-
// Set the target image width and height (in points) to create a narrow column appearance.
29-
generator.Parameters.ImageWidth.Point = 150f; // narrow width
30-
generator.Parameters.ImageHeight.Point = 50f; // appropriate height
28+
// Define image size (points) suitable for a narrow column layout.
29+
generator.Parameters.ImageWidth.Point = 150f;
30+
generator.Parameters.ImageHeight.Point = 50f;
31+
32+
// Align the human‑readable text to the left side of the barcode.
33+
generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Left;
3134

32-
// Optionally increase the resolution to 300 DPI for higher quality output.
33-
generator.Parameters.Resolution = 300f;
35+
// Optional: adjust the module (X) dimension for clearer rendering at small sizes.
36+
generator.Parameters.Barcode.XDimension.Point = 2f;
3437

35-
// Save the generated barcode image to the specified file path.
36-
generator.Save(outputPath);
38+
// Save the generated barcode as a PNG file.
39+
generator.Save("barcode.png");
3740
}
3841

39-
// Inform the user that the barcode image has been saved.
40-
Console.WriteLine($"Barcode image saved to: {outputPath}");
42+
// Inform the user that the image has been created.
43+
Console.WriteLine("Barcode image generated: barcode.png");
4144
}
4245
}

0 commit comments

Comments
 (0)