Customize Barcode Appearance

This documentation explains how to customize the appearance of barcodes using the Aspose.BarCode Cloud SDK for Dart. It provides details on the available methods, customization options, and examples of usage.

Methods

  • generate: Generates a barcode via GET request.
  • generateBody: Generates a barcode via POST request with JSON or XML body.
  • generateMultipart: Generates a barcode via POST request with multipart form data.

Customization Options

When generating a barcode, you can customize various aspects of its appearance using the properties of the request classes.

Key Properties:

  • barcodeType: Specifies the type of barcode to generate (e.g. QR, Aztec, Pdf417, Code39, etc).
  • data: The data to encode in the barcode.
  • imageFormat: Specifies the output format of the barcode image (e.g., Png, Jpeg, Svg).
  • foregroundColor: Color of the barcode bars, supports standard color names or ARGB values (e.g., AliceBlue or #FF000000).
  • backgroundColor: Background color of the barcode image.
  • textLocation: Position of the code text relative to the barcode (Below, Above, None).
  • units: Measurement units for image dimensions (Pixel, Inch, Millimeter).
  • resolution: Resolution of the image in dpi.
  • imageHeight and imageWidth: Dimensions of the barcode image.
  • rotationAngle: Rotation angle of the barcode (e.g., 0, 90, 180).

Examples

Example 1: Generating a Barcode with GET Request

import 'dart:io';
import 'dart:typed_data';

import 'package:aspose_barcode_cloud/aspose_barcode_cloud.dart';

Configuration makeConfiguration() {
  final envToken = Platform.environment['TEST_CONFIGURATION_ACCESS_TOKEN'];
  if (envToken != null) {
    return Configuration(accessToken: envToken);
  } else {
    return Configuration(
      clientId: "Client Id from https://dashboard.aspose.cloud/applications",
      clientSecret:
          "Client Secret from https://dashboard.aspose.cloud/applications",
    );
  }
}

Future<void> main() async {
  final configuration = makeConfiguration();
  final apiClient = ApiClient(configuration);
  final generateApi = GenerateApi(apiClient);

  final fileName = '${Directory.current.path}${Platform.pathSeparator}qr.png';

  final Uint8List response = await generateApi.generate(
      EncodeBarcodeType.QR, "Aspose.BarCode.Cloud",
      imageFormat: BarcodeImageFormat.Png,
      foregroundColor: "Black",
      backgroundColor: "White",
      resolution: 300,
      imageHeight: 200,
      imageWidth: 200,
      textLocation: CodeLocation.Below);

  await File(fileName).writeAsBytes(response);

  print("File '$fileName' generated.");
}

Result Image is: Result image

Example 2: Generating a Barcode with POST Request (JSON Body)

import 'dart:io';
import 'dart:typed_data';

import 'package:aspose_barcode_cloud/aspose_barcode_cloud.dart';

Configuration makeConfiguration() {
  final envToken = Platform.environment['TEST_CONFIGURATION_ACCESS_TOKEN'];
  if (envToken != null) {
    return Configuration(accessToken: envToken);
  } else {
    return Configuration(
      clientId: "Client Id from https://dashboard.aspose.cloud/applications",
      clientSecret:
          "Client Secret from https://dashboard.aspose.cloud/applications",
    );
  }
}

Future<void> main() async {
  final configuration = makeConfiguration();
  final apiClient = ApiClient(configuration);
  final generateApi = GenerateApi(apiClient);

  final file = File(
    "${Directory.current.path}${Platform.pathSeparator}Code39.jpeg",
  );

  final imageParams = BarcodeImageParams()
    ..foregroundColor = "#FF0000"
    ..backgroundColor = "#FFFF00"
    ..imageFormat = BarcodeImageFormat.Jpeg
    ..rotationAngle = 90;

  final generateParams = GenerateParams(EncodeBarcodeType.Code39,
      EncodeData("Aspose", EncodeDataType.StringData), imageParams);

  final Uint8List response = await generateApi.generateBody(generateParams);

  file.writeAsBytes(response);

  print("File '${file.path}' generated.");
}

Result Image is: Result image

Example 3: Generating a Barcode with POST Request (Multipart Form)

import 'dart:io';
import 'dart:typed_data';

import 'package:aspose_barcode_cloud/aspose_barcode_cloud.dart';

Configuration makeConfiguration() {
  final envToken = Platform.environment['TEST_CONFIGURATION_ACCESS_TOKEN'];
  if (envToken != null) {
    return Configuration(accessToken: envToken);
  } else {
    return Configuration(
      clientId: "Client Id from https://dashboard.aspose.cloud/applications",
      clientSecret:
          "Client Secret from https://dashboard.aspose.cloud/applications",
    );
  }
}

Future<void> main() async {
  final configuration = makeConfiguration();
  final apiClient = ApiClient(configuration);
  final generateApi = GenerateApi(apiClient);

  final file = File(
    "${Directory.current.path}${Platform.pathSeparator}Pdf417.svg",
  );

  final Uint8List barcodeStream = await generateApi.generateMultipart(
    EncodeBarcodeType.Pdf417,
    "Aspose.BarCode.Cloud",
    textLocation: CodeLocation.Above,
    imageFormat: BarcodeImageFormat.Svg,
  );

  file.writeAsBytes(barcodeStream);

  print("File '${file.path}' generated.");
}

Result Image is: Result image