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 create barcode images using a barcode generator.
public void barcodeGenerator() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    Assert.assertNull(doc.getFieldOptions().getBarcodeGenerator());

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

    // Configure barcode parameters for a QR barcode
    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");

    // Save the generated barcode image to the file system
    BufferedImage img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
    ImageIO.write(img, "jpg", new File(getArtifactsDir() + "Field.BarcodeGenerator.QR.jpg"));

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

    // Configure barcode parameters for a 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() + "Field.BarcodeGenerator.EAN13.jpg"));
    builder.insertImage(img);

    // Configure barcode parameters for a 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() + "Field.BarcodeGenerator.CODE39.jpg"));
    builder.insertImage(img);

    // Configure barcode parameters for an 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() + "Field.BarcodeGenerator.ITF14.jpg"));
    builder.insertImage(img);

    doc.save(getArtifactsDir() + "Field.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 create barcode images using a barcode generator.
public void barcodeGenerator() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    Assert.assertNull(doc.getFieldOptions().getBarcodeGenerator());

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

    // Configure barcode parameters for a QR barcode
    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");

    // Save the generated barcode image to the file system
    BufferedImage img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
    ImageIO.write(img, "jpg", new File(getArtifactsDir() + "Field.BarcodeGenerator.QR.jpg"));

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

    // Configure barcode parameters for a 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() + "Field.BarcodeGenerator.EAN13.jpg"));
    builder.insertImage(img);

    // Configure barcode parameters for a 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() + "Field.BarcodeGenerator.CODE39.jpg"));
    builder.insertImage(img);

    // Configure barcode parameters for an 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() + "Field.BarcodeGenerator.ITF14.jpg"));
    builder.insertImage(img);

    doc.save(getArtifactsDir() + "Field.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 create barcode images using a barcode generator.
public void barcodeGenerator() throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    Assert.assertNull(doc.getFieldOptions().getBarcodeGenerator());

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

    // Configure barcode parameters for a QR barcode
    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");

    // Save the generated barcode image to the file system
    BufferedImage img = doc.getFieldOptions().getBarcodeGenerator().getBarcodeImage(barcodeParameters);
    ImageIO.write(img, "jpg", new File(getArtifactsDir() + "Field.BarcodeGenerator.QR.jpg"));

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

    // Configure barcode parameters for a 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() + "Field.BarcodeGenerator.EAN13.jpg"));
    builder.insertImage(img);

    // Configure barcode parameters for a 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() + "Field.BarcodeGenerator.CODE39.jpg"));
    builder.insertImage(img);

    // Configure barcode parameters for an 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() + "Field.BarcodeGenerator.ITF14.jpg"));
    builder.insertImage(img);

    doc.save(getArtifactsDir() + "Field.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.