概述
在html页下使用Epson P60II 热敏纸下打印小票,使用的打印方案为调用window.print()。
代码实现1、定义窗体,设置宽度和高度
2、使用ActiveXObject,创建 Scripting.FileSystemObject
function print_onclick() {
var objfs = new ActiveXObject("Scripting.FileSystemObject");
var objprinter=objfs.CreateTextFile("LPT1:",true);
objprinter.Write(String.fromCharCode(0x1B) + "@");
objprinter.Write(String.fromCharCode(0x1B) + String.fromCharCode(0x69));
objprinter.Close();
}
3、设置隐藏模式打印
.Noprint { DISPLAY: none }
4、填充数据
private void ListBind()
{
try
{
string strVoucherID = Request.QueryString["voucherid"];
if (strVoucherID != null && strVoucherID != string.Empty)
{
this.Label_proname.Text = this.DataBase.GetShopVoucherDetail(strVoucherID);
this.DataBase.VoucherPrintUpdate(strVoucherID, this.DataBase.Areaid);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
完整代码
好牛网移动优惠卷
.Noprint { DISPLAY: none }
function print_onclick() {
var objfs = new ActiveXObject("Scripting.FileSystemObject");
var objprinter=objfs.CreateTextFile("LPT1:",true);
objprinter.Write(String.fromCharCode(0x1B) + "@");
objprinter.Write(String.fromCharCode(0x1B) + String.fromCharCode(0x69));
objprinter.Close();
}
function PrintCutrefresh()
{
print_onclick();
}
setTimeout('PrintCutrefresh()',7000); //指定7秒后切纸