Services / Barcode Services / Generate Barcode from Texts
Generate Barcode from Texts

This section demonstrates how to call the Web API service through a client application and generate barcode image from the desired text.

Step 1: Call the Service

Step 2: Run the Client Project

The following image shows the barcode generated after completing the steps above:


The following example makes a call to the Web API service through HTML as well as WinForms client applications. These clients send a GET request to the service, which returns a barcode stream in response. This response stream can then be saved as image, as the barcode image above.

In the following example, the service url takes 1234567890 in Text parameter and encoding type parameter as Code39x, to generate the above image.

Step 1: Call the Service

Complete the following steps to call the Web API service.

  1. Create a WinForms application, as discussed in Configure Client for REST API service. Add one C1Label, C1TextBox and one C1Button control. Your form will appear as shown below.
  2. Define a method (for example: GetBarcode()) in form class of your WinForms application, to call the service application, as shown below.
    C#
    Copy Code
    public void GetBarcode() {
      var apiURL = string.IsNullOrEmpty(c1TextBox1.Text) ?
      "https://demos.componentone.com/ASPNET/5/C1WebAPI/3.0.20193.222/api/barcode?Text=1234567890" : c1TextBox1.Text;
      WebRequest request = WebRequest.Create(apiURL);
      WebResponse response = request.GetResponse();
      var fileStream = File.Create("D:\\BarcodeImg.Png"); 
            //The file format specified here should be same as that         specified in the
      request url
      response.GetResponseStream().CopyTo(fileStream);
    }
    
  3. Call the GetBarcode() method on button-click event of Generate Barcode button.

Back to Top

Step 2: Run the Client Project

WinForms Application

HTML Application

Explore detailed demo samples of REST API service to generate barcode at:

Back to Top