com.aspose.words
Interface IBarcodeGenerator


public interface IBarcodeGenerator 

Public interface for barcode custom generator. Implementation should be provided by user. Generator instance should be passed through the FieldOptions.BarcodeGenerator property.

Example:

Shows how to use a barcode generator.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// We can use a custom IBarcodeGenerator implementation to generate barcodes,
// and then insert them into the document as images.
doc.getFieldOptions().setBarcodeGenerator(new CustomBarcodeGenerator());

// Below are four examples of different barcode types that we can create using our generator.
// For each barcode, we specify a new set of barcode parameters, and then generate the image.
// Afterwards, we can insert the image into the document, or save it to the local file system.
// 1 -  QR code:
BarcodeParameters barcodeParameters = new BarcodeParameters();
{
    barcodeParameters.setBarcodeType("QR");
    barcodeParameters.setBarcodeValue("ABC123");
    barcodeParameters.setBackgroundColor("0xF8BD69");
    barcodeParameters.setForegroundColor("0xB5413B");
    barcodeParameters.setErrorCorrectionLevel("3");
    barcodeParameters.setScalingFactor("250");
    barcodeParameters.setSymbolHeight("1000");
    barcodeParameters.setSymbolRotation("0");
}

BufferedImage img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
ImageIO.write(img, "jpg", new File(getArtifactsDir() + "FieldOptions.BarcodeGenerator.QR.jpg"));

builder.insertImage(img);

// 2 -  EAN13 barcode:
barcodeParameters = new BarcodeParameters();
{
    barcodeParameters.setBarcodeType("EAN13");
    barcodeParameters.setBarcodeValue("501234567890");
    barcodeParameters.setDisplayText(true);
    barcodeParameters.setPosCodeStyle("CASE");
    barcodeParameters.setFixCheckDigit(true);
}

img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
ImageIO.write(img, "jpg", new File(getArtifactsDir() + "FieldOptions.BarcodeGenerator.EAN13.jpg"));
builder.insertImage(img);

// 3 -  CODE39 barcode:
barcodeParameters = new BarcodeParameters();
{
    barcodeParameters.setBarcodeType("CODE39");
    barcodeParameters.setBarcodeValue("12345ABCDE");
    barcodeParameters.setAddStartStopChar(true);
}

img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
ImageIO.write(img, "jpg", new File(getArtifactsDir() + "FieldOptions.BarcodeGenerator.CODE39.jpg"));
builder.insertImage(img);

// 4 -  ITF14 barcode:
barcodeParameters = new BarcodeParameters();
{
    barcodeParameters.setBarcodeType("ITF14");
    barcodeParameters.setBarcodeValue("09312345678907");
    barcodeParameters.setCaseCodeStyle("STD");
}

img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
ImageIO.write(img, "jpg", new File(getArtifactsDir() + "FieldOptions.BarcodeGenerator.ITF14.jpg"));
builder.insertImage(img);

doc.save(getArtifactsDir() + "FieldOptions.BarcodeGenerator.docx");

Method Summary
abstract java.awt.image.BufferedImagegetBarcodeImage(BarcodeParameters parameters)
           Generate barcode image using the set of parameters (for DisplayBarcode field).
abstract java.awt.image.BufferedImagegetOldBarcodeImage(BarcodeParameters parameters)
           Generate barcode image using the set of parameters (for old-fashioned Barcode field).
 

Method Detail

getBarcodeImage

public abstract java.awt.image.BufferedImage getBarcodeImage(BarcodeParameters parameters)
                                           throws java.lang.Exception
Generate barcode image using the set of parameters (for DisplayBarcode field).
Parameters:
parameters - The set of parameters
Returns:
Image representing generated barcode.

Example:

Shows how to use a barcode generator.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// We can use a custom IBarcodeGenerator implementation to generate barcodes,
// and then insert them into the document as images.
doc.getFieldOptions().setBarcodeGenerator(new CustomBarcodeGenerator());

// Below are four examples of different barcode types that we can create using our generator.
// For each barcode, we specify a new set of barcode parameters, and then generate the image.
// Afterwards, we can insert the image into the document, or save it to the local file system.
// 1 -  QR code:
BarcodeParameters barcodeParameters = new BarcodeParameters();
{
    barcodeParameters.setBarcodeType("QR");
    barcodeParameters.setBarcodeValue("ABC123");
    barcodeParameters.setBackgroundColor("0xF8BD69");
    barcodeParameters.setForegroundColor("0xB5413B");
    barcodeParameters.setErrorCorrectionLevel("3");
    barcodeParameters.setScalingFactor("250");
    barcodeParameters.setSymbolHeight("1000");
    barcodeParameters.setSymbolRotation("0");
}

BufferedImage img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
ImageIO.write(img, "jpg", new File(getArtifactsDir() + "FieldOptions.BarcodeGenerator.QR.jpg"));

builder.insertImage(img);

// 2 -  EAN13 barcode:
barcodeParameters = new BarcodeParameters();
{
    barcodeParameters.setBarcodeType("EAN13");
    barcodeParameters.setBarcodeValue("501234567890");
    barcodeParameters.setDisplayText(true);
    barcodeParameters.setPosCodeStyle("CASE");
    barcodeParameters.setFixCheckDigit(true);
}

img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
ImageIO.write(img, "jpg", new File(getArtifactsDir() + "FieldOptions.BarcodeGenerator.EAN13.jpg"));
builder.insertImage(img);

// 3 -  CODE39 barcode:
barcodeParameters = new BarcodeParameters();
{
    barcodeParameters.setBarcodeType("CODE39");
    barcodeParameters.setBarcodeValue("12345ABCDE");
    barcodeParameters.setAddStartStopChar(true);
}

img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
ImageIO.write(img, "jpg", new File(getArtifactsDir() + "FieldOptions.BarcodeGenerator.CODE39.jpg"));
builder.insertImage(img);

// 4 -  ITF14 barcode:
barcodeParameters = new BarcodeParameters();
{
    barcodeParameters.setBarcodeType("ITF14");
    barcodeParameters.setBarcodeValue("09312345678907");
    barcodeParameters.setCaseCodeStyle("STD");
}

img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
ImageIO.write(img, "jpg", new File(getArtifactsDir() + "FieldOptions.BarcodeGenerator.ITF14.jpg"));
builder.insertImage(img);

doc.save(getArtifactsDir() + "FieldOptions.BarcodeGenerator.docx");

getOldBarcodeImage

public abstract java.awt.image.BufferedImage getOldBarcodeImage(BarcodeParameters parameters)
                                              throws java.lang.Exception
Generate barcode image using the set of parameters (for old-fashioned Barcode field).
Parameters:
parameters - The set of parameters
Returns:
Image representing generated barcode.

Example:

Shows how to use a barcode generator.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// We can use a custom IBarcodeGenerator implementation to generate barcodes,
// and then insert them into the document as images.
doc.getFieldOptions().setBarcodeGenerator(new CustomBarcodeGenerator());

// Below are four examples of different barcode types that we can create using our generator.
// For each barcode, we specify a new set of barcode parameters, and then generate the image.
// Afterwards, we can insert the image into the document, or save it to the local file system.
// 1 -  QR code:
BarcodeParameters barcodeParameters = new BarcodeParameters();
{
    barcodeParameters.setBarcodeType("QR");
    barcodeParameters.setBarcodeValue("ABC123");
    barcodeParameters.setBackgroundColor("0xF8BD69");
    barcodeParameters.setForegroundColor("0xB5413B");
    barcodeParameters.setErrorCorrectionLevel("3");
    barcodeParameters.setScalingFactor("250");
    barcodeParameters.setSymbolHeight("1000");
    barcodeParameters.setSymbolRotation("0");
}

BufferedImage img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
ImageIO.write(img, "jpg", new File(getArtifactsDir() + "FieldOptions.BarcodeGenerator.QR.jpg"));

builder.insertImage(img);

// 2 -  EAN13 barcode:
barcodeParameters = new BarcodeParameters();
{
    barcodeParameters.setBarcodeType("EAN13");
    barcodeParameters.setBarcodeValue("501234567890");
    barcodeParameters.setDisplayText(true);
    barcodeParameters.setPosCodeStyle("CASE");
    barcodeParameters.setFixCheckDigit(true);
}

img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
ImageIO.write(img, "jpg", new File(getArtifactsDir() + "FieldOptions.BarcodeGenerator.EAN13.jpg"));
builder.insertImage(img);

// 3 -  CODE39 barcode:
barcodeParameters = new BarcodeParameters();
{
    barcodeParameters.setBarcodeType("CODE39");
    barcodeParameters.setBarcodeValue("12345ABCDE");
    barcodeParameters.setAddStartStopChar(true);
}

img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
ImageIO.write(img, "jpg", new File(getArtifactsDir() + "FieldOptions.BarcodeGenerator.CODE39.jpg"));
builder.insertImage(img);

// 4 -  ITF14 barcode:
barcodeParameters = new BarcodeParameters();
{
    barcodeParameters.setBarcodeType("ITF14");
    barcodeParameters.setBarcodeValue("09312345678907");
    barcodeParameters.setCaseCodeStyle("STD");
}

img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
ImageIO.write(img, "jpg", new File(getArtifactsDir() + "FieldOptions.BarcodeGenerator.ITF14.jpg"));
builder.insertImage(img);

doc.save(getArtifactsDir() + "FieldOptions.BarcodeGenerator.docx");

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.