前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Web使用热敏打印小票(IE环境)

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

作者头像
zls365
发布2021-03-16 16:19:08
1.4K0
发布2021-03-16 16:19:08
举报
文章被收录于专栏:CSharp编程大全CSharp编程大全

概述

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

代码实现

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

代码语言:javascript
复制

<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

代码语言: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();
}

3、设置隐藏模式打印

代码语言:javascript
复制
 <style media="print">.Noprint { DISPLAY: none }</style>

4、填充数据

代码语言:javascript
复制
 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);
        }

    }

完整代码

代码语言:javascript
复制
<%@ 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>
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2021-03-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 CSharp编程大全 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 概述
  • 代码实现
  • 完整代码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档