Set Barcode Text
Contents
[
Hide
]
This documentation covers how to set barcode text in the Aspose.BarCode Cloud SDK for .NET. The Barcode API supports multiple methods to generate barcodes in different formats using GET and POST requests through the IGenerateApi
. Barcodes can be generated by specifying various parameters such as barcode type, data to encode, image format and display options. The data encoding process involves defining the type of data and the actual content.
IGenerateApi
The IGenerateApi
interface includes methods for generating barcodes:
- GET Request: Uses parameters in the URL route and query string.
- POST Request (JSON/XML): Parameters are provided in the request body.
- POST Request (Multipart Form): Parameters are sent as URL-encoded form data.
Methods
- GenerateAsync: Generates a barcode via GET request.
- GenerateBodyAsync: Generates a barcode via POST request with JSON or XML body.
- GenerateMultipartAsync: Generates a barcode via POST request with multipart form data.
Setting Barcode Text
Properties
DataType
: Specifies the type of data encoding (can be string, base64, or hex). If not set, theData
value is used as plain text.Data
: A string that represents the data to be encoded.
Supported Data Types
Value | Description |
---|---|
StringData (Default value) | Plain text |
Base64Bytes | Base64 encoded binary data |
HexBytes | Hexadecimal encoded binary data |
Barcode Generation Example
Below are examples to demonstrate barcode generation using the IGenerateApi
methods.
Example 1: Generating a Barcode with GET Request
using Aspose.BarCode.Cloud.Sdk.Api;
using Aspose.BarCode.Cloud.Sdk.Interfaces;
using Aspose.BarCode.Cloud.Sdk.Model;
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
namespace GenerateSnippets;
internal static class Program
{
private static Configuration MakeConfiguration()
{
var config = new Configuration();
string? envToken = Environment.GetEnvironmentVariable("TEST_CONFIGURATION_ACCESS_TOKEN");
if (string.IsNullOrEmpty(envToken))
{
config.ClientId = "Client Id from https://dashboard.aspose.cloud/applications";
config.ClientSecret = "Client Secret from https://dashboard.aspose.cloud/applications";
}
else
{
config.JwtToken = envToken;
}
return config;
}
public static async Task Main(string[] args)
{
string fileName = Path.GetFullPath(Path.Join("Tests", "test_data",
"qr.png"
));
GenerateApi generateApi = new GenerateApi(MakeConfiguration());
Stream generated = await generateApi.GenerateAsync(EncodeBarcodeType.QR, "Aspose.BarCode.Cloud", dataType: EncodeDataType.StringData);
await using FileStream stream = File.Create(fileName);
await generated.CopyToAsync(stream);
Console.WriteLine($"File '{fileName}' generated.");
}
}
Result Image is:
Example 2: Generating a Barcode with POST Request (JSON Body)
using Aspose.BarCode.Cloud.Sdk.Api;
using Aspose.BarCode.Cloud.Sdk.Interfaces;
using Aspose.BarCode.Cloud.Sdk.Model;
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
namespace GenerateSnippets;
internal static class Program
{
private static Configuration MakeConfiguration()
{
var config = new Configuration();
string? envToken = Environment.GetEnvironmentVariable("TEST_CONFIGURATION_ACCESS_TOKEN");
if (string.IsNullOrEmpty(envToken))
{
config.ClientId = "Client Id from https://dashboard.aspose.cloud/applications";
config.ClientSecret = "Client Secret from https://dashboard.aspose.cloud/applications";
}
else
{
config.JwtToken = envToken;
}
return config;
}
public static async Task Main(string[] args)
{
string fileName = Path.GetFullPath(Path.Join("Tests", "test_data",
"Pdf417.png"
));
GenerateApi generateApi = new GenerateApi(MakeConfiguration());
var generateParams = new GenerateParams
{
BarcodeType = EncodeBarcodeType.Pdf417,
EncodeData = new EncodeData
{
DataType = EncodeDataType.Base64Bytes,
Data = "QXNwb3NlLkJhckNvZGUuQ2xvdWQ="
}
};
Stream generated = await generateApi.GenerateBodyAsync(generateParams);
await using FileStream stream = File.Create(fileName);
await generated.CopyToAsync(stream);
Console.WriteLine($"File '{fileName}' generated.");
}
}
Result Image is:
Example 3: Generating a Barcode with POST Request (Multipart Form)
using Aspose.BarCode.Cloud.Sdk.Api;
using Aspose.BarCode.Cloud.Sdk.Interfaces;
using Aspose.BarCode.Cloud.Sdk.Model;
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
namespace GenerateSnippets;
internal static class Program
{
private static Configuration MakeConfiguration()
{
var config = new Configuration();
string? envToken = Environment.GetEnvironmentVariable("TEST_CONFIGURATION_ACCESS_TOKEN");
if (string.IsNullOrEmpty(envToken))
{
config.ClientId = "Client Id from https://dashboard.aspose.cloud/applications";
config.ClientSecret = "Client Secret from https://dashboard.aspose.cloud/applications";
}
else
{
config.JwtToken = envToken;
}
return config;
}
public static async Task Main(string[] args)
{
string fileName = Path.GetFullPath(Path.Join("Tests", "test_data",
"Code128.png"
));
GenerateApi generateApi = new GenerateApi(MakeConfiguration());
Stream generated = await generateApi.GenerateMultipartAsync(EncodeBarcodeType.Code128, "4173706F73652E426172436F64652E436C6F7564", dataType: EncodeDataType.HexBytes);
await using FileStream stream = File.Create(fileName);
await generated.CopyToAsync(stream);
Console.WriteLine($"File '{fileName}' generated.");
}
}
Result Image is:
This documentation covers how to use the IGenerateApi
to set barcodes text.