IBarcodeGenerator Interface
Public interface for barcode custom generator. Implementation should be provided by user.

Namespace: Aspose.Words.Fields
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.11
Syntax
public interface IBarcodeGenerator

The IBarcodeGenerator type exposes the following members.

Methods
  NameDescription
Public methodCode exampleGetBarcodeImage
Generate barcode image using the set of parameters (for DisplayBarcode field).
Public methodCode exampleGetOldBarcodeImage
Generate barcode image using the set of parameters (for old-fashioned Barcode field).
Remarks
Generator instance should be passed through the BarcodeGenerator property.
Examples
Shows how to create barcode images using a barcode generator.
public void BarcodeGenerator()
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    Assert.IsNull(doc.FieldOptions.BarcodeGenerator);

    // Barcodes generated in this way will be images, and we can use a custom IBarcodeGenerator implementation to generate them
    doc.FieldOptions.BarcodeGenerator = new CustomBarcodeGenerator();

    // Configure barcode parameters for a QR barcode
    BarcodeParameters barcodeParameters = new BarcodeParameters();
    barcodeParameters.BarcodeType = "QR";
    barcodeParameters.BarcodeValue = "ABC123";
    barcodeParameters.BackgroundColor = "0xF8BD69";
    barcodeParameters.ForegroundColor = "0xB5413B";
    barcodeParameters.ErrorCorrectionLevel = "3";
    barcodeParameters.ScalingFactor = "250";
    barcodeParameters.SymbolHeight = "1000";
    barcodeParameters.SymbolRotation = "0";

    // Save the generated barcode image to the file system
    System.Drawing.Image img = doc.FieldOptions.BarcodeGenerator.GetBarcodeImage(barcodeParameters);
    img.Save(ArtifactsDir + "Field.BarcodeGenerator.QR.jpg");

    // Insert the image into the document
    builder.InsertImage(img);

    // Configure barcode parameters for a EAN13 barcode
    barcodeParameters = new BarcodeParameters();
    barcodeParameters.BarcodeType = "EAN13";
    barcodeParameters.BarcodeValue = "501234567890";
    barcodeParameters.DisplayText = true;
    barcodeParameters.PosCodeStyle = "CASE";
    barcodeParameters.FixCheckDigit = true;

    img = doc.FieldOptions.BarcodeGenerator.GetBarcodeImage(barcodeParameters);
    img.Save(ArtifactsDir + "Field.BarcodeGenerator.EAN13.jpg");
    builder.InsertImage(img);

    // Configure barcode parameters for a CODE39 barcode
    barcodeParameters = new BarcodeParameters();
    barcodeParameters.BarcodeType = "CODE39";
    barcodeParameters.BarcodeValue = "12345ABCDE";
    barcodeParameters.AddStartStopChar = true;

    img = doc.FieldOptions.BarcodeGenerator.GetBarcodeImage(barcodeParameters);
    img.Save(ArtifactsDir + "Field.BarcodeGenerator.CODE39.jpg");
    builder.InsertImage(img);

    // Configure barcode parameters for an ITF14 barcode
    barcodeParameters = new BarcodeParameters();
    barcodeParameters.BarcodeType = "ITF14";
    barcodeParameters.BarcodeValue = "09312345678907";
    barcodeParameters.CaseCodeStyle = "STD";

    img = doc.FieldOptions.BarcodeGenerator.GetBarcodeImage(barcodeParameters);
    img.Save(ArtifactsDir + "Field.BarcodeGenerator.ITF14.jpg");
    builder.InsertImage(img);

    doc.Save(ArtifactsDir + "Field.BarcodeGenerator.docx");
}
See Also