-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-powershell-module-accepting-barcode-data-outputting-code-16k-png-with-specified-quiet-zones.cs
More file actions
64 lines (55 loc) · 2.99 KB
/
Copy pathcreate-powershell-module-accepting-barcode-data-outputting-code-16k-png-with-specified-quiet-zones.cs
File metadata and controls
64 lines (55 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Title: Generate Code 16K barcode PNG with custom quiet zones
// Description: Demonstrates creating a Code 16K barcode image using Aspose.BarCode, allowing input data and quiet‑zone coefficients via command‑line arguments.
// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, showcasing the BarcodeGenerator class with EncodeTypes.Code16K. It illustrates typical use cases such as customizing quiet zones and exporting to PNG, which developers often need when integrating barcode creation into scripts or CI pipelines.
// Prompt: Create PowerShell module accepting barcode data, outputting Code 16K PNG with specified quiet zones.
// Tags: code16k, barcode, generation, png, quietzone, aspose.barcode, csharp
using System;
using System.IO;
using Aspose.BarCode;
using Aspose.BarCode.Generation;
namespace Code16KGenerator
{
/// <summary>
/// Generates a Code 16K barcode image (PNG) using Aspose.BarCode.
/// Accepts optional command‑line arguments for the barcode data and quiet‑zone coefficients.
/// </summary>
class Program
{
/// <summary>
/// Entry point of the application.
/// Parses arguments, configures the barcode generator, and saves the PNG file.
/// </summary>
/// <param name="args">
/// args[0] – barcode data (default: "1234567890123456")
/// args[1] – left quiet‑zone coefficient (default: 10)
/// args[2] – right quiet‑zone coefficient (default: 1)
/// </param>
static void Main(string[] args)
{
// Default barcode data and quiet‑zone coefficients
string codeText = "1234567890123456";
int leftQuietZone = 10; // default left coefficient
int rightQuietZone = 1; // default right coefficient
// Override defaults with command‑line arguments, if provided
if (args.Length > 0 && !string.IsNullOrWhiteSpace(args[0]))
codeText = args[0];
if (args.Length > 1 && int.TryParse(args[1], out int left))
leftQuietZone = left;
if (args.Length > 2 && int.TryParse(args[2], out int right))
rightQuietZone = right;
// Output file name for the generated PNG image
string outputPath = "code16k.png";
// Initialize the barcode generator for Code 16K symbology
using (var generator = new BarcodeGenerator(EncodeTypes.Code16K, codeText))
{
// Apply the specified quiet‑zone coefficients
generator.Parameters.Barcode.Code16K.QuietZoneLeftCoef = leftQuietZone;
generator.Parameters.Barcode.Code16K.QuietZoneRightCoef = rightQuietZone;
// Save the barcode image as PNG
generator.Save(outputPath);
}
// Inform the user where the file was saved
Console.WriteLine($"Code 16K barcode saved to '{Path.GetFullPath(outputPath)}'.");
}
}
}