Class BarcodeGenerator

Class BarcodeGenerator

Namespace: Aspose.BarCode.Generation
Assembly: Aspose.BarCode.dll (25.2.0)

BarcodeGenerator for backend barcode images generation.

supported symbologies: 1D: Codabar, Code11, Code128, Code39, Code39FullASCII Code93, EAN13, EAN8, Interleaved2of5, MSI, Standard2of5, UPCA, UPCE, ISBN, GS1Code128, Postnet, Planet EAN14, SCC14, SSCC18, ITF14, SingaporePost ... 2D: Aztec, DataMatrix, PDf417, QR code ...

[XmlSerialization(Name = "Aspose.BarCode.Generator")]
public sealed class BarcodeGenerator : IDisposable

Inheritance

objectBarcodeGenerator

Implements

IDisposable

Inherited Members

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Examples

This sample shows how to create and save a barcode image.

using(var generator = new BarcodeGenerator(EncodeTypes.Code128))
  {
      generator.CodeText = "123ABC";
      generator.Save("code128.png");
  }

Constructors

BarcodeGenerator(BaseEncodeType)

Creates an instance of BarcodeGenerator.

public BarcodeGenerator(BaseEncodeType type)

Parameters

type BaseEncodeType

Barcode symbology type. Use Aspose.BarCode.Generation.EncodeTypes class to setup a symbology.

BarcodeGenerator(BaseEncodeType, string)

Creates an instance of BarcodeGenerator.

public BarcodeGenerator(BaseEncodeType type, string codeText)

Parameters

type BaseEncodeType

Barcode symbology type. Use Aspose.BarCode.Generation.EncodeTypes class to setup a symbology.

codeText string

Text to be encoded.

Properties

BarcodeType

Barcode symbology type.

[XmlSerialization(Type = XmlSerializationType.Element)]
public BaseEncodeType BarcodeType { get; set; }

Property Value

BaseEncodeType

CodeText

Text to be encoded.

[XmlSerialization(Type = XmlSerializationType.Element)]
public string CodeText { get; set; }

Property Value

string

Parameters

Generation parameters.

[XmlSerialization(Type = XmlSerializationType.Element)]
public BaseGenerationParameters Parameters { get; }

Property Value

BaseGenerationParameters

Methods

Dispose()

public void Dispose()

ExportToXml(string)

Exports BarCode properties to the xml-file specified

public bool ExportToXml(string xmlFile)

Parameters

xmlFile string

The name for the file

Returns

bool

Whether or not export completed successfully.

Returns True in case of success; False Otherwise

ExportToXml(Stream)

Exports BarCode properties to the xml-stream specified

public bool ExportToXml(Stream xml)

Parameters

xml Stream

The xml-stream

Returns

bool

Whether or not export completed successfully.

Returns True in case of success; False Otherwise

GenerateBarCodeImage()

Generate the barcode image under current settings.

public Bitmap GenerateBarCodeImage()

Returns

Bitmap

Barcode image. See System.Drawing.Bitmap.

Examples

This sample shows how to create and save a barcode image.

using(var generator = new BarcodeGenerator(EncodeTypes.Code128))
  {
      Bitmap barcode = generator.GenerateBarCodeImage();
      barcode.Save("test.png");
  }

ImportFromXml(string)

Imports BarCode properties from the xml-file specified and creates BarcodeGenerator instance.

public static BarcodeGenerator ImportFromXml(string xmlFile)

Parameters

xmlFile string

The name for the file

Returns

BarcodeGenerator

BarcodeGenerator instance

ImportFromXml(Stream)

Imports BarCode properties from the xml-stream specified and creates BarcodeGenerator instance.

public static BarcodeGenerator ImportFromXml(Stream xml)

Parameters

xml Stream

The xml-stream

Returns

BarcodeGenerator

BarcodeGenerator instance

Save(Stream, BarCodeImageFormat)

Save barcode image to stream in specific format.

public void Save(Stream stream, BarCodeImageFormat format)

Parameters

stream Stream

Output System.IO.Stream.

format BarCodeImageFormat

Specifies the file format of the output image.

Save(string, BarCodeImageFormat)

Save barcode image to specific file in specific format.

public void Save(string filename, BarCodeImageFormat format)

Parameters

filename string

Path to save to.

format BarCodeImageFormat

Specifies the file format of the output image.

Save(string)

Save barcode image to specific file.

public void Save(string filename)

Parameters

filename string

Path to save to.

SetCodeText(byte[])

Set codetext as sequence of bytes.

public void SetCodeText(byte[] codeBytes)

Parameters

codeBytes byte[]

Bytes of codetext

SetCodeText(string, Encoding)

Encodes codetext with byte order mark (BOM), using specified encoding: like UTF8, UTF16, UTF32, e.t.c.. 1D barcodes should use Encoding.ASCII or ISO/IEC 8859-1 - Encoding.GetEncoding(28591). 2D barcodes should use Encoding.UTF8.

public void SetCodeText(string codeText, Encoding encoding)

Parameters

codeText string

CodeText string

encoding Encoding

Applied encoding

Examples

This sample shows how to use SetCodeText with 1D and 2D barcodes

//Encode codetext of 1D barcodes with 7-bit ASCII encoding, byte order mark (BOM) is absent
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
    gen.SetCodeText("123ABCD", Encoding.ASCII);
    gen.Save("barcode.png", BarCodeImageFormat.Png);
}
//Encode codetext of 1D barcodes with 8-bit ISO/IEC 8859-1 encoding, byte order mark (BOM) is absent
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
    gen.SetCodeText("123ABCD", Encoding.GetEncoding(28591));
    gen.Save("barcode.png", BarCodeImageFormat.Png);
}
//Encode codetext of 2D barcodes with UTF8 encoding with byte order mark (BOM)
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
    gen.SetCodeText("123ABCD", Encoding.UTF8);
    gen.Save("barcode.png", BarCodeImageFormat.Png);
}

SetCodeText(string, Encoding, bool)

Encodes codetext with optional byte order mark (BOM) insertion, using specified encoding: like UTF8, UTF16, UTF32, e.t.c.. 1D barcodes should use Encoding.ASCII or ISO/IEC 8859-1 - Encoding.GetEncoding(28591). 2D barcodes should use Encoding.UTF8.

public void SetCodeText(string codeText, Encoding encoding, bool insertBOM)

Parameters

codeText string

CodeText string

encoding Encoding

Applied encoding

insertBOM bool

flag indicates insertion of the Encoding byte order mark (BOM). In case, the Encoding requires byte order mark (BOM) insertion: like UTF8, UTF16, UTF32, e.t.c. and flag is set to true, the BOM is added, in case of setting flag to false, the BOM insertion is ignored.

Examples

This sample shows how to use SetCodeText with 1D and 2D barcodes

//Encode codetext of 1D barcodes with 7-bit ASCII encoding, byte order mark (BOM) is absent
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
    gen.SetCodeText("123ABCD", Encoding.ASCII, true);
    gen.Save("barcode.png", BarCodeImageFormat.Png);
}
//Encode codetext of 1D barcodes with 8-bit ISO/IEC 8859-1 encoding, byte order mark (BOM) is absent
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
    gen.SetCodeText("123ABCD", Encoding.GetEncoding(28591), true);
    gen.Save("barcode.png", BarCodeImageFormat.Png);
}
//Encode codetext of 2D barcodes with UTF8 encoding with byte order mark (BOM)
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
    gen.SetCodeText("123ABCD", Encoding.UTF8, true);
    gen.Save("barcode.png", BarCodeImageFormat.Png);
}
//Encode codetext of 2D barcodes with UTF8 encoding without byte order mark (BOM)
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
    gen.SetCodeText("123ABCD", Encoding.UTF8, false);
    gen.Save("barcode.png", BarCodeImageFormat.Png);
}
 English