public static void main(String[] args) {
    // The path to the documents directory.
    String dataDir = Utils.getDataDir(BarcodeImageBorders.class);

    String dst = dataDir + "barcode-image-borders.jpg";

    // Instantiate barcode object
    BarCodeBuilder bb = new BarCodeBuilder();

    // Set the Code text for the barcode
    bb.setCodeText("1234567");

    // Set the symbology type to code128
    bb.setSymbologyType(Symbology.Code128);

    // Set border style to solid
    bb.setBorderDashStyle(BorderDashStyle.Solid);

    // Set border margins by assigning an instance of MarginsF
    bb.setMargins(new MarginsF(2f, 2f, 2f, 2f));

    // Set border width
    bb.setBorderWidth(0.5f);

    // Enable border to be shown in the barcode
    bb.setBorderVisible(true);

    // Save the image
    bb.save(dst);

    System.out.println("Barcode saved successfully.");
  }
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    BarCodeBuilder b = new BarCodeBuilder();
    b.setSymbologyType(Symbology.Code128);
    b.setCodeText("12345678");
    BufferedImage image = b.getBarCodeImage();

    response.setContentType("image/png");
    OutputStream outputStream = response.getOutputStream();
    ImageIO.write(image, "png", outputStream);
    outputStream.close();
  }
  public static void main(String[] args) {
    // The path to the resource directory.
    String dataDir = Utils.getDataDir(SpecifySymbology.class) + "Barcode/BasicFeatures/";

    // Generate and save the image to file
    BarCodeBuilder builder = new BarCodeBuilder();
    // Set code text
    builder.setCodeText("test-123");
    // Set Symbology type
    builder.setSymbologyType(Symbology.Code39Standard);

    builder.save(dataDir + "Code39Standard.jpg");
  }
  /** Generates a barcode with random settings. */
  private static BarCodeBuilder createBarCode() {
    // Instantiate a LinearBarCode object
    BarCodeBuilder barCode = new BarCodeBuilder();

    // Call necessary methods each of which returns a random value for the
    // corresponding barcode property
    barCode.setSymbologyType(getRandomSymbology());
    barCode.setCodeText(getRandomCodeText(barCode));
    barCode.setSupplementData(getRandomSupplementData());
    barCode.setImageQuality((int) getRandomImageQualityMode());
    barCode.setRotationAngleF(getRandomRotationAngle());

    return barCode;
  }