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.
- Install font which is free on .net "3 of 9 Barcode"
- Create an ASP.NET project
- 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.
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);
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);
}
}
}