Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
This documentation covers how to set barcode text in the Aspose.BarCode Cloud SDK for PHP. The Barcode API supports multiple methods to generate barcodes in different formats using GET and POST requests through the GenerateApi
. 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.
The GenerateApi
interface includes methods for generating barcodes:
$data_type
: Specifies the type of data encoding (can be string, base64, or hex). If not set, the $data
value is used as plain text.$data
: A string that represents the data to be encoded.Value | Description |
---|---|
StringData (Default value) | Plain text |
Base64Bytes | Base64 encoded binary data |
HexBytes | Hexadecimal encoded binary data |
Below are examples to demonstrate barcode generation using the GenerateApi
methods.
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Aspose\BarCode\Configuration;
use Aspose\BarCode\GenerateApi;
use Aspose\BarCode\Model\{EncodeBarcodeType, EncodeData, EncodeDataType};
use Aspose\BarCode\Requests\GenerateRequestWrapper;
function makeConfiguration(): Configuration
{
$config = new Configuration();
$envToken = getenv("TEST_CONFIGURATION_ACCESS_TOKEN");
if (empty($envToken)) {
$config->setClientId("Client Id from https://dashboard.aspose.cloud/applications");
$config->setClientSecret("Client Secret from https://dashboard.aspose.cloud/applications");
} else {
$config->setAccessToken($envToken);
}
return $config;
}
function main(): void
{
$fileName = __DIR__ . '/../testdata/Qr.png';
$generateApi = new GenerateApi(null, makeConfiguration());
$getRequest = new GenerateRequestWrapper(EncodeBarcodeType::QR, "Aspose.BarCode.Cloud");
$getRequest->data_type = EncodeDataType::StringData;
$generated = $generateApi->generate($getRequest);
file_put_contents($fileName, $generated->fread($generated->getSize()));
echo "File '{$fileName}' generated.\n";
}
main();
Result Image is:
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Aspose\BarCode\Configuration;
use Aspose\BarCode\GenerateApi;
use Aspose\BarCode\Model\{GenerateParams, EncodeBarcodeType, EncodeData, EncodeDataType};
use Aspose\BarCode\Requests\GenerateBodyRequestWrapper;
function makeConfiguration(): Configuration
{
$config = new Configuration();
$envToken = getenv("TEST_CONFIGURATION_ACCESS_TOKEN");
if (empty($envToken)) {
$config->setClientId("Client Id from https://dashboard.aspose.cloud/applications");
$config->setClientSecret("Client Secret from https://dashboard.aspose.cloud/applications");
} else {
$config->setAccessToken($envToken);
}
return $config;
}
function main(): void
{
$fileName = __DIR__ . '/../testdata/Pdf417.png';
$generateApi = new GenerateApi(null, makeConfiguration());
$generateParams = new GenerateParams([
'barcode_type' => EncodeBarcodeType::Pdf417,
'encode_data' => new EncodeData([
'data' => 'QXNwb3NlLkJhckNvZGUuQ2xvdWQ=',
'data_type' => EncodeDataType::Base64Bytes
])
]);
$request = new GenerateBodyRequestWrapper($generateParams);
$generated = $generateApi->generateBody($request);
file_put_contents($fileName, $generated->fread($generated->getSize()));
echo "File '{$fileName}' generated.\n";
}
main();
Result Image is:
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Aspose\BarCode\Configuration;
use Aspose\BarCode\GenerateApi;
use Aspose\BarCode\Requests\GenerateMultipartRequestWrapper;
use Aspose\BarCode\Model\{EncodeBarcodeType, EncodeDataType};
function makeConfiguration(): Configuration
{
$config = new Configuration();
$envToken = getenv("TEST_CONFIGURATION_ACCESS_TOKEN");
if (empty($envToken)) {
$config->setClientId("Client Id from https://dashboard.aspose.cloud/applications");
$config->setClientSecret("Client Secret from https://dashboard.aspose.cloud/applications");
} else {
$config->setAccessToken($envToken);
}
return $config;
}
function main(): void
{
$fileName = __DIR__ . '/../testdata/Code128.png';
$generateApi = new GenerateApi(null, makeConfiguration());
$formRequest = new GenerateMultipartRequestWrapper(EncodeBarcodeType::Code128, "4173706F73652E426172436F64652E436C6F7564");
$formRequest->data_type = EncodeDataType::HexBytes;
$generated = $generateApi->generateMultipart($formRequest);
file_put_contents($fileName, $generated->fread($generated->getSize()));
echo "File '{$fileName}' generated.\n";
}
main();
Result Image is:
This documentation covers how to use the GenerateApi
to set barcodes text.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.