使用Asp.Net从客户端[在客户端计算机]打印条形码 [英] Print Barcode from Client Side[At client machine] using Asp.Net

查看:171
本文介绍了使用Asp.Net从客户端[在客户端计算机]打印条形码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,
我需要从客户端计算机上打印条形码,而在Visual Studio中运行该程序时,条形码可以完美打印,而一旦代码发布&将条形码不打印在IIS服务器中,而是在服务器端打印.

即使我尝试从客户端计算机进行打印也无法正常工作,一旦条形码打印机计算机与服务器连接,它就会打印客户端计算机以及服务器中给出的所有条形码.条形码仅打印条形码打印机与服务器而不是客户端连接.
我需要从客户端计算机上打印条形码".我的代码:

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:

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;
    }

推荐答案

您要么需要在服务器上进行工作,然后将文件发送给客户端(例如他们可以打印的pdf文件)或使用JavaScript中的诸如window.print()之类的方法从客户端进行打印,只要您可以创建要打印的网页即可.
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.


您必须将条形码创建为图片,然后通过html img标签显示它并使用javascript window.print()打印(本文描述了这两种情况)
另一种选择是创建一个本地报告RDLC,通过也支持客户端打印的ReportViewer控件显示它.此处的更多详细信息 http://www.gotreportviewer.com/
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/


这篇关于使用Asp.Net从客户端[在客户端计算机]打印条形码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆