title: Print barcode from client side using ASP.NET
body: <p>I need to print a barcode from client Machine, While running the program in Visual Studio, the barcode prints perfectly but when the code is published &amp; put into the IIS server, the barcode is not printing on the client machine but rather prints on the server side. </p>
  
  <p>Even if I try to print from client machine it does not work. Once the barcode printer machine connects with the server it prints all the barcode given on client machine as well as on the server. The printer is dedicated to barcode printing only and is connected to the server and not the client. </p>
  
  <p>"The barcode <strong>MUST</strong> print on the <strong>CLIENT MACHINE</strong>"</p>
  
  <p>MY CODE:</p>
  
  <pre><code>protected void btnPrint_Click(object sender, EventArgs e)
  {
      List&lt;string&gt; list = new List&lt;string&gt;();
      foreach (String printer in PrinterSettings.InstalledPrinters)
      {
          list.Add(printer.ToString());
      }
      string printerName = "";
      for (int i = 0; i &lt; 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;
  }
  </code></pre>