Manual - Aztec

Introduction

Aztec code comes from the 2D barcode family. You can encode a large amount of information within a single barcode.
All the ASCII characters from 0 to 255 are supported. The barcode size will be determined by the number of data encoded and the chosen error correction level.
You can pass in ECI mode with the function setTilde().

This class inherits the BCGBarcode2D class.

Example

Methods

BCGaztec's Methods

BCGBarcode2D's Methods

BCGBarcode's Methods

Code Example

'use strict';

import { createServer } from 'http';
import { BCGColor, BCGDrawing, createSurface, toBuffer } from '@barcode-bakery/barcode-nodejs';
import { BCGaztec } from '@barcode-bakery/barcode-nodejs/aztec';

http.createServer(function (request, response) {
    const colorBlack = new BCGColor(0, 0, 0);
    const colorWhite = new BCGColor(255, 255, 255);

    // Barcode Part
    const code = new BCGaztec();
    code.setScale(2); // Resolution
    code.setForegroundColor(colorBlack); // Color of bars
    code.setBackgroundColor(colorWhite); // Color of spaces
    code.parse('Aztec');

    // Drawing Part
    const drawing = new BCGDrawing(createSurface);
    toBuffer(drawing, BCGDrawing.ImageFormat.Png, function (err, buffer) {
        response.writeHead(200, { "Content-Type": "image/png" });
        response.end(buffer);
    });
}).listen(8124);

Method explanations

  • getErrorLevel() — Gets the error correction level of the barcode
    Description
    The error correction level percentage.
    Returns
    int - value between 0 and 99
  • setErrorLevel(level) — Sets the error correction level of the barcode
    Description
    The error correction level percentage before drawing the barcode.
    The level must be between 5 and 99.
    The default value is 23.
  • getSize() — Gets the size of the barcode
    Description
    Gets the size mode of the final barcode.
    See setSize() for more details.
    Returns
    int - constant value defined in setSize()
  • setSize(value) — Sets the size of the barcode
    Description
    The size of the final barcode will be decided automatically depending on the data you give and the error correction level percentage you have chosen.
    You can, however, specify a different value in order to get a different code. Here are the possible values:
    - BCGaztec.Size.Smallest : The code will be the smallest possible
    - BCGaztec.Size.Compact : The code will try to be a compact code if possible
    - BCGaztec.Size.Full : The code will be in full mode (with the reference grid)
    The default value is BCGaztec.Size.Smallest.
  • setStructuredAppend(snum, st, sname) — Specifies that data will be expanded between multiple barcodes
    Description
    The Aztec code data can be separated throughout many different barcodes.
    The first argument is the barcode number (beginning with 1), the second argument is the total number of barcodes you have. The last argument is optional, it specifies an identifier for you barcodes group. This argument must stay the same for every barcode in the group.
    It is possible to encode the data on a maximum of 26 different barcodes.
    Returns
    bool - true on success, false on failure
  • getTilde() — Gets if the behavior for tilde ~ is modified
    Description
    Gets if the behavior for tilde ~ is modified.
    See setTilde() for more details.
    Returns
    bool - true if activated, false otherwise
  • setTilde(accept) — Modifies the use of the tilde character ~
    Description
    By setting true in this argument, the tilde characters (ASCII 126 ~) will be processed as special characters. These are the special characters you can write.
    - ~~ : Writes a simple tilde
    - ~F : Writes the FNC1 character
    - ~Exxxxxx : Writes the ECI xxxxxx character with x representing an integer from 0 to 9
    The default value is false.
  • getRune() — Gets the Rune number to draw
    Description
    Gets the Rune number to draw.
    Returns
    int - Rune number or false if no Rune will be drawn
  • setRune(runeNumber) — Specifies to draw a Rune
    Description
    The Rune number runeNumber will be drawn to the screen. Runes are special symbols.
    The Rune number has to be between 0 and 255.
    The default value is -1.
  • setScaleX(scaleX) — Sets the scaling X for the barcode
    Description
    The width in pixel of one module.
    The default value is 1.
    Note that this method is protected.
  • setScaleY(scaleY) — Sets the scaling Y for the barcode
    Description
    The height in pixel of one module.
    The default value is 1.
    Note that this method is protected.
  • parse(text) — Analyzes a text message to draw afterwards
    Description
    The data you pass to the text argument must be supported by the type of barcode you use.
    Check each barcode's introduction section to obtain more information on how to use this method within each symbology.
  • draw(image) — Draws the barcode on the image
    Description
    The value of the image argument must be an image resource. The size of the image can be defined by the value received from getDimension().
  • getDimension(width, height) — Returns an array containing the required size for the image
    Description
    Returns an array in which the first index is the image width and the second index is the image height.
    The arguments are used to specify the starting point of the drawing. Should be 0 for both.
    The BCGDrawing class uses this method to create the image resource.
    Returns
    array(int, int) - [0] is the width, [1] is the height
  • getScale() — Gets the scale of the barcode
    Description
    Gets the scale of the barcode. The value is the number of the "smallest" unit in pixel.
    Returns
    int - value in pixels
  • setScale(scale) — Sets the scale of the barcode
    Description
    The barcode will be x times bigger. Then a pixel will be x by x for its size.
  • getForegroundColor() — Gets the color of the bars
    Description
    Gets the color of the bars of the barcode.
    Returns
  • setForegroundColor(color) — Sets the color of the bars
    Description
    Sets the color of the bars of the barcode. By default, the color is black. This argument can be a BCGColor class or any other argument that BCGColor can accept in its constructor.
  • getBackgroundColor() — Gets the color of the spaces
    Description
    Gets the color of the spaces of the barcode.
    Returns
  • setBackgroundColor(color) — Sets the color of the spaces
    Description
    Sets the color of the spaces of the barcode. By default, the color is white. This argument can be a BCGColor class or any other argument that BCGColor can accept in its constructor.
  • setColor(foregroundColor, backgroundColor) — Sets the color of the bars and spaces
    Description
    An easy and fast method to set the color of the bars and spaces. Check the setForegroundColor() and setBackgroundColor().
  • getOffsetX() — Gets the X offset
    Description
    Gets the X offset of the barcode in pixels. The value isn't multiplied by the scale.
    Returns
    int - value in pixels
  • setOffsetX(value) — Sets the X offset
    Description
    Specifies the X offset of the barcode in pixels multiplied by the scale. The required size returned by getDimension() will be modified accordingly.
  • getOffsetY() — Gets the Y offset
    Description
    Gets the Y offset of the barcode in pixels. The value isn't multiplied by the scale.
    Returns
    int - value in pixels
  • setOffsetY(value) — Sets the Y offset
    Description
    Specifies the Y offset of the barcode in pixels multiplied by the scale. The required size returned by getDimension() will be modified accordingly.
  • addLabel(label) — Adds a label to the graphic
    Description
    Adds a BCGLabel object to the drawing.
  • removeLabel(label) — Removes a label from the graphic
    Description
    Removes a specific BCGLabel object from the drawing.
  • clearLabels() — Removes the labels from the graphic
    Description
    Clears the BCGLabel objects from the drawing.