Search code examples
c#asp.netbarcode

Barcode generation usingBarcode Rendering Framework in web application


I am using Barcode Rendering Framework for generating a barcode. I have downloaded their dll's. I can see,how it can be done in windows application. I want to do the same i.e, generating the barcode and using it in web application. Following is the link for the question that can be used. Free Barcode API for .NET and following is the code :

Code39BarcodeDraw barcode39 = BarcodeDrawFactory.Code39WithoutChecksum;
System.Drawing.Image img = barcode39.Draw("Hello World", 40);
pictureBox1.Image = barcode39.Draw("Hello World", 40);

How can I use the same functionality in web application?


Solution

  • You can use the same code in ASP.NET, but you need to output the image via HTTP.

    Say you have an ASP.NET web page that contains the following:

    <IMG SRC="BarCode.aspx?par1=HelloWorld40OrWhatever" />
    

    Then your BarCode.aspx page must generate and output the image:

    Code39BarcodeDraw barcode39 = BarcodeDrawFactory.Code39WithoutChecksum;
    System.Drawing.Image img = barcode39.Draw("Hello World", 40);
    
    Response.Clear();
    Response.Type = "image/png";
    img.Save(Response.OutputStream, Imaging.ImageFormat.Png);
    Response.Flush();
    Response.End();