如何在没有提示的情况下从Internet Explorer直接打印到标签打印机 [英] How to print directly to label printer from Internet Explorer without prompt

查看:87
本文介绍了如何在没有提示的情况下从Internet Explorer直接打印到标签打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含upc号码的mysql数据库,我想用斑马打印机(LP2824)打印到标签上。我想以某种方式将这些号码直接发送到我的标签打印机,这不是默认打印机,没有提示用户。

I have a mysql database containing upc numbers that I would like to print to labels with a zebra printer (LP2824). I would like to somehow be able to send those numbers directly to my label printer, which is not the default printer without the user being prompted.

据我所知IE是唯一的选择,因为需要某种类型的activeX控件来实现这一点。我在meadroid.com上使用ScriptX找到了直接打印示例,但我不愿意支付他们的许可费。我还找到了一个使用VBScript的示例,该示例将页面发送到默认打印机而不提示用户。我的问题是我无法弄清楚如何删除IE中的默认页眉和页脚,我无法选择使用哪个打印机。

As far as I can tell, IE is the only option as some type of activeX control is required to make this happen. I found a direct printing example at meadroid.com using ScriptX, but I'm not willing to pay their licensing fee. I also found an example using VBScript that will send the page to the default printer without prompting the user. My problem with that is I can't figure out how to remove the default header and footer present in IE and I can't choose which printer to use.

我的问题是:

是否有一个activeX控件,我可以通过类似于MeadCo的ScriptX的javascript使用但没有许可,或者VBScript方法会更好,在这种情况下如何一个人可以删除页眉和页脚,并打印到默认设置的标签打印机?将一系列命令直接发送到打印机的能力是理想的。

Is there an activeX control out there that I can use via javascript similar to MeadCo's ScriptX but without licensing, or would the VBScript approach be better, in which case how can a person remove the header and footer, and print to the label printer which is not set at default? The ability to just send a series of commands directly to the printer would be ideal.

这是我到目前为止的测试代码:

Here is the test code I have so far:

<head>
<script language='VBScript'>
Sub Print()
       OLECMDID_PRINT = 6
       OLECMDEXECOPT_DONTPROMPTUSER = 2
       OLECMDEXECOPT_PROMPTUSER = 1
       call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
End Sub
document.write "<object ID='WB' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
</script>

</head>

<body>
Helo!!!
<a href="javascript:window.print();">Print</a>

</body>


推荐答案

基于网络我遇到了这个问题ERP系统,当我们需要在将货物放入存储货架之前打印进货的物品标签。我们最初的问题是我们无法将IE打印到我们为标签打印机配置的指定标签尺寸(Zebra TLP-2844)。 IE始终使用默认打印机的A4格式。要打印正常方式,还会导致大量额外的点击和设置,只需要为这个简单的任务进行,只需在基于Windows的应用程序中单击一下(您可以更好地控制打印机设置)。

I've had this exact problem with a web based ERP system when we needed to print article labels for incoming deliveries before putting the goods on the storing shelfs. Our initial problem was that we couldn't get IE to print to a specified label size that we configured for the label printer (Zebra TLP-2844). IE always used the default printer's A4 format. To print the "normal way" also resulted in a lot of extra clicks and settings that had to be made just for this simple task that would only take one click in a windows based application (where you have more control over the printer settings).

我做了很多研究,发现一些ActiveX控件能够详细控制打印机设置,但最后正常的打印方式仍然会导致不必要的点击次数,客户希望它非常简单,超级快。

I made a lot of research and found some ActiveX control that were able to control the printer settings in detail but in the end the normal way of printing still would result in an unnecessary number of clicks and the customer wanted it to be super simple and super fast.

由于我以前有使用标签打印机开发应用程序的经验,我知道打印机的内部打印机语言可以使用。在Zebra打印机中,它被称为EPL / ZPL。它是一种简单的基于文本的协议,可以通过打印机提供的任何接口使用,例如Parallell端口,串行端口,USB或10/100以太网。我之前刚刚使用过串口接口,但是在这个项目中,我必须能够通过互联网,通过防火墙,打印到客户办公室本地网络上连接的Zebra打印机。经过一些研究,这实际上非常简单,最终成为客户真正理想的解决方案。

As I have former experience developing applications using label printers I knew of the printer's internal printer language that could be used. In Zebra printers it's called EPL/ZPL. It's a simple text based protocol that can be used through any of the interfaces that the printer offer e.g. Parallell Port, Serial Port, USB or 10/100 Ethernet. I have just used the serial port interface before but in this project I had to be able to print over the internet, through the firewall, to a Zebra printer connected on the local network at the customers office. After some research this proved to be quite easy actually and it ended up to be a really great solution for the customer.

基本的EPL语言有其局限性但通常你只是想要一个非常简单的打印输出,包括一些文字和一些条形码或其他东西。您只能使用五种尺寸的固定宽度标准字体。可以将字体宽度和高度设置为原始大小的倍数。如果您需要更高级的打印输出,包括图片或某些布局,字体,大小等,可以通过使用特殊标签设计应用程序创建模板来完成。模板可以包含调用模板时可以使用的变量。

The basic EPL language has its limits but often you just want a quite simple printout including some text and some bar codes or something. You are limited to a fixed width standard font in five sizes. It's possible to set the font width and height to a multiple of the original size. If you need more advanced printouts including pictures or certain layouts, fonts, sizes, etc, that could be done by creating templates with a special Label Design Application. The templates can contain variables that can be used when calling the template.

为了完全理解我的小例子和更多细节,我建议你下载EPL程序员手册。您可能还必须将打印机配置为能够接受命令,该过程应该在手册中。

To fully understand my little example and for more details I recommend you to download the EPL Programmers manual. You also might have to configure the printer to be able to accept the commands, the procedure should be in the manual.

下面是一个ASP.NET 2.0的简单示例(C#)。因为我最初制作了一个用于测试的控制台应用程序,所以我刚刚注释了一些错误处理。该示例基于功能齐全的客户解决方案,但我已排除并重写了一些部分,以使示例更易于理解。我已经测试了基本功能,返回的字符串似乎还可以,但我还没有测试打印到Zebra打印机,因为我现在无法访问任何内容,所以要注意意外的错误。 :)但它应该没问题。

Below you find a simple example for ASP.NET 2.0 (C#). As I initially made a console application for testing there is some error handling that I just commented out. The example is based on a fully functional customer solution but I have excluded and rewritten some parts to make the example more understandable. I have tested the basic functionality and the returned strings seems to be ok, but I haven't tested to print to a Zebra printer as I don't have access to any at the moment, so be aware of unexpected bugs. :) But it should be ok.

祝你好运!

资源:

Zebra - 资源库

注意:您需要注册才能下载EPL程序员手册

Note: You need to register to be able to download the EPL Programmers Manual

示例代码:

<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Text" %>
<%@ Import Namespace = "System.Net.Sockets" %>
<%@ Import Namespace = "System.IO" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script language="C#" runat="server">
    public String strPrintOutput;

    void Page_Load(Object sender,EventArgs e)
    {
        // Build output string - Example - Printer Settings
        //strPrintOutput = BuildString1();

        // Build output string - Example - Print Label with Barcode and some text (Prints two labels)
        strPrintOutput = BuildString2("123456", "2010-01-02", "1234567890", "123", "Harddrive", "D31", "123456", "2");

        // Print output to HTML-page
        txtPrintout.Text = strPrintOutput;

        // Send output to Zebra Printer
        // xxx.xxx.xxx.xxx = The IP of the Zebra printer
        // 9100 = The default printer port, but that could be changed on the printer
        // For external access (e.g. through the internet) you need to use the IP/domain name of the router/firewall and also open a port in the firewall and forward the traffic to the internal IP and port set on the printer
        // Note that for external access appropriate security measures should be added in some way.
        Connect("xxx.xxx.xxx.xxx", 9100, strPrintOutput);
    }

  public void Connect(String ip, Int32 port, String strMessage)
  {
    try
    {
      // Convert String to Byte Array with encoding Windows-1252
      //Byte[] data = System.Text.Encoding.ASCII.GetBytes(strMessage);
      Byte[] data = System.Text.Encoding.GetEncoding(1252).GetBytes(strMessage);

      // Create connection to printer
      TcpClient printer = new TcpClient(ip, port);

      // Get stream object of printer
      NetworkStream strm = printer.GetStream();

      // Write message to stream
      strm.Write(data, 0, data.Length);

      // Status Message
      //Console.WriteLine("Sent: {0}", strMessage);

      // Close stream
      strm.Close();

      //Close connection to printer
      printer.Close();

    } // end try

    catch (ArgumentNullException e)
    {
        //Console.WriteLine("ArgumentNullException: {0}", e);
    }

    catch (SocketException e)
    {
        //Console.WriteLine("SocketException: {0}", e);
    }

    //Console.WriteLine("\n Press Enter to continue...");
    //Console.Read();
  }

  /*
   * \n = LF (Line Feed)
   * \r = CR (Carriage Return)
   * \r\n = CrLf
   * Printer ignores CR when sent
   * CR cannot be used in place of LF
  */
  public String BuildString1()
  {
    StringBuilder sb = new StringBuilder();

    //Clears out printer buffer
    sb.Append("\n");

        //Print the current printer configuration
    sb.Append("U\n");

    return sb.ToString();
  }

  public String BuildString2(String strBarCode, String strDate, String strArticleNumber, String strPurchaseOrderNumber, String strArticleName, String strLocation, String strOrderNumber, String strNoOfLabels)
  {
    StringBuilder sb = new StringBuilder();

    //Clears out printer buffer
    sb.Append("\n");

    //Clears out the image buffer
    sb.Append("N\n");

    //Set 8-bit, CodePage Windows 1252 (Latin 1), KDU Sweden (Printer with display)
    sb.Append("I8,A,046\n");

        // Create Print Objects
    sb.Append("B35,5,0,3C,3,6,60,N,\"" + strBarCode + "\"\n");
    sb.Append("A35,75,0,3,1,1,N,\"Article No:\"\n");
    sb.Append("A35,100,0,3,1,1,N,\"Article Name:\"\n");
    sb.Append("A35,125,0,3,1,1,N,\"Location:\"\n");
    sb.Append("A35,150,0,3,1,1,N,\"Order:\"\n");

    sb.Append("A205,75,0,3,1,1,N,\"" + strArticleNumber + "\"\n");
    sb.Append("A205,100,0,3,1,1,N,\"" + strArticleName + "\"\n");
    sb.Append("A205,125,0,3,1,1,N,\"" + strLocation + "\"\n");
    sb.Append("A205,150,0,3,1,1,N,\"" + strOrderNumber + "\"\n");

    sb.Append("A432,49,0,3,1,1,N,\"" + strDate + "\"\n");
    sb.Append("A530,75,0,3,1,1,N,\"" + strPurchaseOrderNumber + "\"\n");
    sb.Append("P" + strNoOfLabels + "\nN\n\n");

    return sb.ToString();
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Print to Zebra Label Printer</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:Panel runat="server">
        <asp:TextBox id="txtPrintout" TextMode="MultiLine" runat="server" BackColor="LightBlue" Width="100%" Height="800px"></asp:TextBox>
      </asp:Panel>
    </form>
</body>
</html>

这篇关于如何在没有提示的情况下从Internet Explorer直接打印到标签打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆