3

Following is my previous question that is working fine and generating the barcode. My previous Question

Now, I just want the characters(forming the barcode) to be written under this barcode(image). How can i achieive that.? I am using Barcode Rendering Framework for generating the barcode. Please help.

Can I do it by taking a panel and adding the image and the text(barcode characters) and printing the panel.??

Community
  • 1
  • 1
Ankur
  • 1,023
  • 7
  • 27
  • 42
  • 1
    I've put up together a Javascript [SVG Barcode](https://barcode.windegger.wtf/) generator. Maybe that helps you solve your requirement. – superreeen Apr 27 '19 at 16:05

1 Answers1

0

I did it by using asp panel in which i added the barcode image that is created. Under that I added the string i.e my barcode characters. Then using the print helper function I am able to print them. Following is my code for adding image and text to panel.

Code39BarcodeDraw barcode39 = BarcodeDrawFactory.Code39WithoutChecksum;
           // Panel pnl = new Panel();
            Label str = new Label();
            str.Text="SER1012308131";
           // System.Drawing.Image img = barcode39.Draw("SER1012308131", 40);
            //string path = Server.MapPath("~/Uploads/") + img+".jpeg";
            string path = @"~/Uploads/abcd.jpeg";
          //  img.Save(path);
            Image imgg = new Image();
            imgg.ImageUrl=path;
            pnlpnl.Width = Unit.Pixel(300);
            pnlpnl.Height = Unit.Pixel(45);
            pnlpnl.Controls.Add(imgg);
            pnlpnl.Controls.Add(str);
            Session["ctrl"] = pnlpnl;
            ClientScript.RegisterStartupScript
                (this.GetType(), "onclick", "<script language=javascript>window.open('Print.aspx','PrintMe','height=45px,width=300px,scrollbars=1');</script>");

Print helper function.

public PrintHelper()
    {
    }

    public static void PrintWebControl(Control ctrl)
    {
        PrintWebControl(ctrl, string.Empty);
    }

    public static void PrintWebControl(Control ctrl, string Script)
    {
        StringWriter stringWrite = new StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
        if (ctrl is WebControl)
        {
            Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w;
        }
        Page pg = new Page();
        pg.EnableEventValidation = false;
        if (Script != string.Empty)
        {
            pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
        }
        HtmlForm frm = new HtmlForm();
        pg.Controls.Add(frm);
        frm.Attributes.Add("runat", "server");
        frm.Controls.Add(ctrl);
        pg.DesignerInitialize();
        pg.RenderControl(htmlWrite);
        string strHTML = stringWrite.ToString();
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Write(strHTML);
        HttpContext.Current.Response.Write("<script>window.print();</script>");
        HttpContext.Current.Response.End();
    }
Ankur
  • 1,023
  • 7
  • 27
  • 42