alimertaytar
alimertaytar

Reputation: 105

Generate barcode in MVC

I'm using BarcodeLib. How can i use like this in controller ? I was using that in aspx with IHttpHandler but how to use in controller ?

<img src="/StokBarkod/Barrr?barcodeText=Hello" />

/////

public ActionResult Barcode(string barcodeText)
{
    BarcodeLib.Barcode barcode = new BarcodeLib.Barcode
    {
        IncludeLabel = false,

        Alignment = BarcodeLib.AlignmentPositions.CENTER,
        LabelPosition = LabelPositions.BOTTOMCENTER,
        RotateFlipType = RotateFlipType.RotateNoneFlipNone,
        //LabelFont = new Font("Arial", 18 * 1),
        Width = 135,
        Height = 22,
        BackColor = System.Drawing.Color.White,
        ForeColor = System.Drawing.Color.Black
    };

    //var yeniKod = barcodeText.Replace("//", "%");
    System.Drawing.Image img = barcode.Encode(BarcodeLib.TYPE.CODE128, barcodeText);


    Byte[] bytdizi = new Byte[-1 + 1];
    bytdizi = (Byte[])imageToByteArray(img);

    System.IO.Stream ms = new System.IO.MemoryStream(bytdizi);

    byte[] buffer = new byte[4096];
    int byteSeq = ms.Read(buffer, 0, 4096);

    HttpContext.Current.Response.ContentType = "image/jpeg";
    while (byteSeq > 0)
    {

        HttpContext.Current.Response.OutputStream.Write(buffer, 0, byteSeq);
        byteSeq = ms.Read(buffer, 0, 4096);
    }

}

Help me please ?

Upvotes: 0

Views: 2501

Answers (1)

Seyed Reza Dadrezaei
Seyed Reza Dadrezaei

Reputation: 583

use JsBarcode. its easily generate barcode in JS.

Upvotes: 1

Related Questions