Click here to Skip to main content
15,847,077 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Sir,
I need to print barcode from client Machine, While running the program in Visual studio Barcode prints perfectly whereas once code is published & Put into IIS server the barcode is not printing in client machine rather it prints in server side.

Even if i try to print from client machine it will not work, once barcode printer machine connects with server it prints all the barcode given in client machine as well as in server. Barcode is printing only barcode printer is connected with server not with client.
"I NEED TO PRINT BARCODE FROM CLIENT MACHINE".MY CODE:
C#
protected void btnPrint_Click(object sender, EventArgs e)
    {
        List<string> list = new List<string>();
        foreach (String printer in PrinterSettings.InstalledPrinters)
        {
            list.Add(printer.ToString());
        }
        string printerName = "";
        for (int i = 0; i < list.Count; i++) // Loop through List with for
        {
            printerName = list[i].ToString().ToLower();
            if (printerName.Equals(@"tsc ttp-244 plus"))
            {
                // Console.WriteLine("Printer = " + printer["Name"]);
                if (list[i].ToString().ToLower().Equals("true"))
                {
                    // printer is offline by user
                    //lblMsg.Text = "Your Plug-N-Play printer is not connected.";
                }
                else
                {
                    // printer is not offline               
                    PrintDocument pd = new PrintDocument();
                    pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
                    pd.PrinterSettings.PrinterName = "TSC TTP-244 Plus";
                    pd.DefaultPageSettings.PaperSize = new PaperSize("Label", 197, 98);//Document No Size                    
                    // pd.DefaultPageSettings.Margins = new Margins(70, 12, 12, 12);
                    // pd.DefaultPageSettings.Margins.Left = 100;            
                    pd.Print();
                }
            }
        }
        PlBarcodeFileNo.Controls.Add(_BarcodeImageView(lblBarcode.Text));
    }


 private System.Web.UI.WebControls.Image _BarcodeImageView(string barCodeimgNo)
    {
        System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
        using (Bitmap bitMap = new Bitmap(barCodeimgNo.Length * 40, 80))
        {
            using (Graphics graphics = Graphics.FromImage(bitMap))
            {
                Font oFont = new Font("IDAutomationHC39M", 16);
                PointF point = new PointF(2f, 2f);
                SolidBrush blackBrush = new SolidBrush(Color.Black);
                SolidBrush whiteBrush = new SolidBrush(Color.White);
                graphics.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height);
                graphics.DrawString("*" + barCodeimgNo + "*", oFont, blackBrush, point);
            }
            using (MemoryStream ms = new MemoryStream())
            {
                bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                byte[] byteImage = ms.ToArray();

                Convert.ToBase64String(byteImage);
                imgBarCode.ImageUrl = "data:image/png;base64," +                     Convert.ToBase64String(byteImage);
            }
        }
        return imgBarCode;
    }
Posted
Updated 30-Apr-14 1:38am
v3
Comments
[no name] 30-Apr-14 7:10am    
If you want to print on the client side, you have to write client side code.
Saleem Mudeen 30-Apr-14 8:13am    
Above program works perfectly for server side printing barcode but i need print that barcode from client side..
[no name] 30-Apr-14 8:28am    
Yes we probably all get that. If you want to print on the client side, then you probably should be writing client side code instead of server side code.
Nelek 30-Apr-14 12:47pm    
Who knows if he really wrote the server side.
[no name] 30-Apr-14 19:46pm    
Well I would say he didn't but I would prefer to give them the benefit of the doubt. :-)

You either need to do the work on the server and then send a file to the client (such as a pdf which they can print) or do the printing from client side with something like window.print() in JavaScript as long as you can create a webpage that has what you want printed.
 
Share this answer
 
You have to create the barcode as an image, then display it through an html img tag and print it using javascript window.print() (this article describes both scenarios)
Another alternative is you create a local report RDLC, display it through the ReportViewer control which support client printing too. Further details here http://www.gotreportviewer.com/
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900