Custom Function: Generate a barcode

This function generates a barcode image from an id. This could be used for a variety of purposes such as product labeling, event tickets, or shipping labels, to name a few. A variety of different barcode types are supported.

Important: This function uses a third-party library called the Barcode Image Generation Library to generate the barcodes. Copy the .dll file as needed to the Application\Bin folder, Scheduler folders, and WebService\Bin folder.

Arguments (Min - Max): 3 - 3


  • BarcodeLib.dll,
  • System.Drawing.dll


  • WebReports.Api.Common,
  • WebReports.Api.Reports,
  • BarcodeLib,
  • System.Drawing,
  • System.Drawing.Imaging


Barcode(x, y, z)

  • x is the input id
  • y is the type of barcode (see Barcode Image Generation Library for the valid types)
  • z is the index of the current cell, in the format "A#", where A is the letter of the cell row, and # is the number of the cell column. This is necessary to scale the barcode to the cell size.


string inputValue = args[0].ToString();
string inputCodeType = args[1].ToString();
string inputCell = args[2].ToString().ToLower();

int col = (inputCell[0] - 96) - 1;
int row = int.Parse(inputCell.Substring(1)) - 1;

BarcodeLib.Barcode barcode = new BarcodeLib.Barcode();

// scale barcode to cell size
barcode.Height = sessionInfo.Report.Rows[row].Height;
barcode.Width = sessionInfo.Report.Columns[col].Width;

// set other barcode attributes
barcode.ForeColor = Color.Black;
barcode.BackColor = Color.White;
barcode.Alignment = AlignmentPositions.CENTER;
barcode.IncludeLabel = true;
barcode.ImageFormat = ImageFormat.Png;

BarcodeLib.TYPE type = BarcodeLib.TYPE.CODE128;

switch (inputCodeType)
  case "UPC-A": type = BarcodeLib.TYPE.UPCA; break;
  case "UPC-E": type = BarcodeLib.TYPE.UPCE; break;
  case "UPC 2 Digit Ext": type = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_2DIGIT; break;
  case "UPC 5 Digit Ext": type = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_5DIGIT; break;
  case "EAN-13": type = BarcodeLib.TYPE.EAN13; break;
  case "JAN-13": type = BarcodeLib.TYPE.JAN13; break;
  case "EAN-8": type = BarcodeLib.TYPE.EAN8; break;
  case "ITF-14": type = BarcodeLib.TYPE.ITF14; break;
  case "Codabar": type = BarcodeLib.TYPE.Codabar; break;
  case "PostNet": type = BarcodeLib.TYPE.PostNet; break;
  case "Bookland-ISBN": type = BarcodeLib.TYPE.BOOKLAND; break;
  case "Code 11": type = BarcodeLib.TYPE.CODE11; break;
  case "Code 39": type = BarcodeLib.TYPE.CODE39; break;
  case "Code 39 Extended": type = BarcodeLib.TYPE.CODE39Extended; break;
  case "Code 93": type = BarcodeLib.TYPE.CODE93; break;
  case "LOGMARS": type = BarcodeLib.TYPE.LOGMARS; break;
  case "MSI": type = BarcodeLib.TYPE.MSI_Mod10; break;
  case "Interleaved 2 of 5": type = BarcodeLib.TYPE.Interleaved2of5; break;
  case "Standard 2 of 5": type = BarcodeLib.TYPE.Standard2of5; break;
  case "Code 128": type = BarcodeLib.TYPE.CODE128; break;
  case "Code 128-A": type = BarcodeLib.TYPE.CODE128A; break;
  case "Code 128-B": type = BarcodeLib.TYPE.CODE128B; break;
  case "Code 128-C": type = BarcodeLib.TYPE.CODE128C; break;
  case "Telepen": type = BarcodeLib.TYPE.TELEPEN; break;
  case "FIM (Facing Identification Mark)": type = BarcodeLib.TYPE.FIM; break;
  case "Pharmacode": type = BarcodeLib.TYPE.PHARMACODE; break;
  default: break;

barcode.Encode(type, inputValue);

// convert the barcode image to a byte array
byte[] barCodeData = barcode.GetImageData(SaveTypes.PNG);

// create an Exago UdfLoadImageData class to tell us that we have image data
UdfLoadImageData imageData = new UdfLoadImageData();

// set the ImageTag to the byte array converted to Base64
imageData.ImageTag = Base64Encoding.Encode(barCodeData);

// set the ImageType to Db
imageData.ImageType = UdfLoadImageType.Db;

// return the UdfLoadImageData object
return imageData;

Hidden Article Information

Article Author
Exago Development
created 2016-08-17 17:28:27 UTC
updated 2017-06-22 15:36:18 UTC

functions, example, custom function, bar, code,
Have more questions? Submit a request