Click here to Skip to main content
15,888,610 members
Articles / Web Development / ASP.NET
Tip/Trick

Generating and Printing Barcodes on Zebra Printer

Rate me:
Please Sign up or sign in to vote.
2.23/5 (5 votes)
4 Jan 2011CPOL 81K   14   9
Access zebra printer from ASP.NET

It is really difficult to find something on internet to print from ASP.NET form yes what you will find is JavaScript to acheive the same. Also its easy to do from windows application.


Issue: When you use JavaScript, you have to save the image (barcode) on aspx page and then fire the javascript print command. It works well with lazer printer but has issue with Zebra printer as image gets generated but there, we are not able to scan it. So Barcode generated is no use if you are using Zebra printer


It allows you to print barcode and also access zebra printer from ASP.NET.



  1. Install font which is free on .net "3 of 9 Barcode"
  2. Create an ASP.NET project
  3. Add this code

Both aspx and cs file code is attached


Any one who wants to print barcodes using zebra printers can use it, using ASP.NET (webforms). Any one using JavaScript for printing and try to print on zebra printer has issues. AS barcode generated does not get scanned. So using the code the barcode generated is corrected printed by zebra printer.


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing.Printing;
using System.Text;
using System.Drawing;
using System.IO;
using System.ComponentModel;
namespace RahulMehtaGhatkopar100
{
    public partial class WebForm4 : System.Web.UI.Page
    { 
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        public void Submit_Click(object sender, EventArgs e)
        {
            try
            {
                PrintDocument pd = new PrintDocument();
                pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
                // Set the printer name. 
                //pd.PrinterSettings.PrinterName = "\\NS5\hpoffice
                //pd.PrinterSettings.PrinterName = "Zebra New GK420t"               
                pd.Print();
            }
            catch (Exception ex)
            {
                Response.Write("Error: " + ex.ToString());
            }
        }
        void pd_PrintPage(object sender, PrintPageEventArgs ev)
        {
            Font printFont = new Font("3 of 9 Barcode", 17);
            Font printFont1 = new Font("Times New Roman", 9, FontStyle.Bold);

            SolidBrush br = new SolidBrush(Color.Black);

            ev.Graphics.DrawString("*AAAAAAFFF*", printFont, br, 10, 65);
            ev.Graphics.DrawString("*AAAAAAFFF*", printFont1, br, 10, 85);  
        }
    }
}

License

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


Written By
Web Developer Imperial College London
United Kingdom United Kingdom
SUMMARY
Over 10 years of experience in the analysis, design, development, implementation of full life cycle of Web and Windows Based .Net applications.
Proven strength in trouble shooting, problem solving, coordination and analysis.
A good team player, self-motivated and good communication skills.
Domain knowledge of Finance and Health care.
Development experience using ASP .NET, VB .Net, C#, and SQL Server
Worked with companies and clients like Merrill Lynch , Glaxo SmithKline and ICICI Prudential Insurance.
CERTIFICATIONS
1. Certified professional Microsoft Certified Application Developer ( MCAD)

2. Exam 70-573:
TS: Microsoft SharePoint 2010, Application Development
(Year :2011)

http://www.microsoft.com/learning/en/us/exam.aspx?id=70-573


3. Microsoft® Community Contributor Award - 2011

https://www.microsoftcommunitycontributor.com/faq.aspx

TRAININGS
SharePoint 2007, WSS 3.0 , BizTalk Server, WPF, WWF, WCF

Active Member of Asp.net Group

Specialties: Asp.net C# (Both Windows and Web Application)

Interested in SharePoint 2007, WSS 3.0 , BizTalk Server, WPF, WWF, WCF.

Currently Working In UK.
Have worked in India, USA and Australia. Now working in Uk for around 4 years


http://uk.linkedin.com/pub/rahul-mehta/26/277/951

Comments and Discussions

 
QuestionExtraordinary Pin
Mrkraju21-May-15 6:34
Mrkraju21-May-15 6:34 
GeneralMy vote of 1 Pin
VICK22-Jan-15 1:15
professional VICK22-Jan-15 1:15 
Questioni use vb Pin
David Ortega20-Nov-13 6:15
David Ortega20-Nov-13 6:15 
QuestionWhat would the analagous event for a non-asp.net project? Pin
B. Clay Shannon4-Feb-13 14:13
professionalB. Clay Shannon4-Feb-13 14:13 
QuestionDoes not work from published code. Pin
faizkazi4u17-Dec-12 2:17
faizkazi4u17-Dec-12 2:17 
AnswerRe: Does not work from published code. Pin
rahulbhat22-Mar-17 23:05
rahulbhat22-Mar-17 23:05 
GeneralThank you Pin
Khybar Dev14-Oct-12 17:13
Khybar Dev14-Oct-12 17:13 
GeneralReason for my vote of 5 good job. Pin
CS140127-Jan-12 21:21
CS140127-Jan-12 21:21 
GeneralReason for my vote of 1 not Working Pin
ramomex220-Jun-11 12:25
ramomex220-Jun-11 12:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.