/** Returns a random code text string. */
 private static String getRandomCodeText(BarCodeBuilder barCode) {
   // Some barcode standard specifications have certain restrictions of the
   // number of digits in the code
   switch ((int) barCode.getSymbologyType()) {
     case (int) Symbology.EAN13:
       return getRandomDigits(12);
     case (int) Symbology.EAN8:
       return getRandomDigits(7);
     case (int) Symbology.UPCA:
     case (int) Symbology.UPCE:
       return getRandomDigits(10);
     default:
       return getRandomDigits(12);
   }
 }
  /**
   * Called for every merge field encountered in the document. We can either return some data to the
   * mail merge engine or do something else with the document. In this case we choose to modify cell
   * formatting.
   */
  private static void fillProperties(Document doc, BarCodeBuilder barCode) throws Exception {
    String[] fieldNames =
        new String[] {
          "SymbologyType", "CodeText", "SupplementData", "RotationAngle", "ImageQuality"
        };
    Object[] fieldValues =
        new Object[] {
          getNameOfEnumValue(Symbology.class, barCode.getSymbologyType()),
          barCode.getCodeText(),
          barCode.getSupplementData(),
          barCode.getRotationAngleF(),
          getNameOfEnumValue(ImageQualityMode.class, barCode.getImageQuality())
        };

    // Execute mail merge
    doc.getMailMerge().execute(fieldNames, fieldValues);
  }