ITPub博客

首页 > 数据库 > 数据库开发技术 > Web使用热敏打印小票(IE环境)

Web使用热敏打印小票(IE环境)

原创 数据库开发技术 作者:后端Q 时间:2021-03-12 00:00:00 0 删除 编辑

概述

在html页下使用Epson P60II 热敏纸下打印小票,使用的打印方案为调用window.print()。

代码实现

1、定义窗体,设置宽度和高度


<body onload="window.external.Print(0,0);" style="margin-top:0px;" > <form id="form1" runat="server" > <div align="center" valign="top" id ="PrintDoc" > <table style="width:4.8cm; height:9.9cm; border-width:1px; border-color:Red; border-style:dashed" > <tr align="center" valign="top"> <td> <asp:Label id="Label_proname" runat="server" > </asp:Label> </td> </tr> </table> </div> </form></body>

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、设置隐藏模式打印

 <style media="print">.Noprint { DISPLAY: none }</style>

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

完整代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Print.aspx.cs" Inherits="Print"  enableEventValidation="false" validateRequest="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>好牛网移动优惠卷</title> <style media="print">.Noprint { DISPLAY: none }</style><script type='text/javascript'>
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();}</script> <script language="javascript"> function PrintCutrefresh(){ print_onclick(); } setTimeout('PrintCutrefresh()',7000); //指定7秒后切纸</script></head><body onload="window.external.Print(0,0);" style="margin-top:0px;" > <form id="form1" runat="server" > <div align="center" valign="top" id ="PrintDoc" > <table style="width:4.8cm; height:9.9cm; border-width:1px; border-color:Red; border-style:dashed" > <tr align="center" valign="top"> <td> <asp:Label id="Label_proname" runat="server" > </asp:Label> </td> </tr> </table> </div> </form></body></html>


原文作者:后端Q;如有侵权,请联系管理员删除。

请登录后发表评论 登录
全部评论

注册时间:2023-01-22

  • 博文量
    1540
  • 访问量
    725868