This is a simple library that lets you do one thing very easily: generate an
Code128, on the other hand, has out-of-the-box support for all 128 low-order ASCII characters.
Image for a Code128 BARCODE with a single line of code.Code128, on the other hand, has out-of-the-box support for all 128 low-order ASCII characters.
Basic usage
Create MVC web application. Below code add to the View which it will take input string and one button to generate BarCode Image.
Now Add the below code in controller (HTTPPOST). Here get the entered text and send that text to
Code128Rendering.MakeBarcodeImage(Bacodetext.Trim(), int.Parse(txtWeight), true)
Method which it will take the input as
There are three parameters:
string InputData:The message to be encodedint BarWeight:The baseline width of the bars in the output. Usually, 1 or 2 is good.bool AddQuietZone:Iffalse, omits the required white space at the start and end of the barcode. If your layout doesn't already provide good margins around theImage, you should usetrue
You can save the images in folder location different type (.bmp/ .png / .jpeg)
- [HttpPost]
- public ActionResult Index(string btnSubmit, FormCollection formcoll)
- {
- try
- {
- if (!ReferenceEquals(formcoll["btnGenarate"], null))
- {
- string Bacodetext = formcoll["txtInput"].ToString();
- string txtWeight = "2";
- const int MaxLength = 10;
- // Genarate barcode
- Image myimg = Code128Rendering.MakeBarcodeImage(Bacodetext.Trim(), int.Parse(txtWeight), true);
- var imgName = Bacodetext;
- if (imgName.Length > MaxLength)
- {
- imgName = imgName.Substring(0, MaxLength); // Image name trim
- }
- // save image in folder location different type (.bmp/ .png / .jpeg)
- string ImageFolder = Server.MapPath("~/Images");
- myimg.Save(ImageFolder + "/" + imgName.Trim() + ".bmp");
- //image to displa in view
- var virtualPath = string.Format("~/Images/{0}.bmp", imgName.Trim());
- ViewBag.Path = virtualPath;
- }
- }
- catch (Exception ex)
- {
- }
- return View();
- }
- }
GenCode128 namespace, in a static class called Code128Rendering)
Output

Hopefully, this helps you to generate barcode using web application.

Sameh AwwadPosted Jun 18, 2018, 2:57 PM
Sorry if this is a stupid question how to pass the parameters with ajax, and how to print the barcode image?