Browser 是否从网站/web应用程序打印到标签打印机?

Browser 是否从网站/web应用程序打印到标签打印机?,browser,printing,cross-browser,label,Browser,Printing,Cross Browser,Label,是否有任何已知的标签打印机可以接受来自网站或web应用程序的打印命令 特别是一次性标签打印机,如Dymo、Brother、Zebra等 是否有人成功打印到这些打印机上(不使用仅限Internet Explorer的黑客或ActiveX控件) 我认为,随着我们进入一个更加以浏览器为中心的世界,最终必须有一个解决方案。跨浏览器/平台兼容的网页/网页脚本不具备将打印机语言命令(如Zebra printer language[ZPL])传输到打印机所需的低级访问权限。为此,需要ActiveX控件/浏览器

是否有任何已知的标签打印机可以接受来自网站或web应用程序的打印命令

特别是一次性标签打印机,如Dymo、Brother、Zebra等

是否有人成功打印到这些打印机上(不使用仅限Internet Explorer的黑客或ActiveX控件)


我认为,随着我们进入一个更加以浏览器为中心的世界,最终必须有一个解决方案。

跨浏览器/平台兼容的网页/网页脚本不具备将打印机语言命令(如Zebra printer language[ZPL])传输到打印机所需的低级访问权限。为此,需要ActiveX控件/浏览器插件/小程序/类似位的可执行代码。此限制不特定于打印机,来自浏览器,而不是打印机制造商


然而,许多标签打印机允许您像普通打印机一样对它们进行打印——只是那些打印到非常小的纸张上的打印机。您可以使用HTML/CSS布局标签。显示结果时,指示用户转到“文件>打印”,并在单击打印之前选择标签打印机

希望这有帮助,

Ben

您可以从已签名的Java小程序或应用程序打印:

如果您格式化打印输出,使其适合标签,那么这应该是可行的


请注意,大多数现代浏览器都限制了对Java小程序的支持,因此您可能会在使用小程序时遇到问题,具体取决于使用的浏览器。特别是,谷歌浏览器将会。这些限制不适用于Java Web Start,它应该继续工作。

Dymo打印机有一个浏览器插件,允许您从中打印。非常容易使用

几年后重新审视这个问题


联网的Zebra打印机易于打印。在一个项目中,我让Web应用程序打开打印机的插座,并在ZPL中为其提供指令

哇。我知道这是4年前提出的,但为了寻找一种从网络应用程序打印标签的强大方法,我花了整整一周的时间,我不得不在这里发言

以下是我的发现:

  • DYMO似乎最有可能成为卓越的候选人。但事实证明,它只打印(a)自己的应用程序,或(b)使用SDK的东西。DYMO SDK使用的XML绘图模型过于复杂,并且在布局和样式方面受到限制。文档分散且难以理解(例如,常见标签尺寸的
    值是多少?任何地方都没有标签参数的描述!)如此令人沮丧,如此令人失望

  • 有一个,它可以为说EPL、ZPL、FGL、ESC/POS、EPCL和CPCL的设备启用浏览器打印。。。其中包括斑马系列。它需要大量集成(在标签打印机连接的设备上运行web服务器),但它可以工作

  • 有一个设计良好的,适用于DYMO(除其他外),但需要从浏览器打印到PDF的中间步骤。他们还假设你永远不会将你想要打印的内容缩小到70%以下,这是不正确的

OP说:“我认为,随着我们进入一个更以浏览器为中心的世界,最终必须有一个解决方案。”四年后,我会更进一步,并建议任何不能在浏览器上打印的标签打印机(或只是表现得像一个带小纸张的普通打印机)都远远没有发挥其潜力。HTML+CSS中的布局是一个快照。浏览器完美地解析它,并以任何分辨率将其呈现给任何输出设备。这似乎很明显


如果有人知道从浏览器打印的热敏标签打印机,而不是将你囚禁在陈旧的集成方法中,我非常想知道

您还可以尝试查找提供云打印解决方案的打印机,这意味着您可以通过互联网直接打印到任何打印机。

Zebra现在有一个名为“BrowserPrint”的工具,它的工作原理与专为Zebra打印机设计的PrintNode类似。(与Printnode不同,它可以免费与Zebra打印机一起使用)

一些打印机还具有可用的ppd文件和/或可以在linux平台系统上的cups中配置,或者也可以通过linux进行连接和通话。(这意味着,通过构建一个简单的服务器守护进程,或者在linux机器上设置apache或lighttpd,甚至连接到打印机的raspberry pi,可以使用shell脚本、php、perl或其他方法打印到它)


这是我在C#中创建的,效果非常好。这是一个web应用程序。

+1好主意。虽然以PDF格式发送标签可能更好,但这样比使用HTML更好地控制输出格式。“许多标签打印机允许您像普通打印机一样打印标签”。是否有任何打印机不允许我们像普通打印机一样打印!??我们有一个Dymo LabelWriter 450 Twin Turbo,可以通过浏览器打印。打印html时,我们在控制页边距方面遇到问题,但它确实会打印。@Timguiter-您能从浏览器中以静默方式打印吗?i、 e.在不出现打印对话框的情况下?@MarkCooper您可以使用chrome的kiosk打印模式进行打印。我已经成功地从页面打印到zebra打印机,而不需要用户做任何事情。@JayShepherd但我想这只适用于Chrome?-如此有限的用例:-(我在回顾你的步骤,我发现整个打印机世界的倒退非常令人惊讶。直接从浏览器进行打印似乎是一个明显的竞争优势,但通用解决方案仍然很少。我从Dymo for Mac下载了一个SDK,但我认为这是一个笑话,在经历了大量的VISE安装程序之后屏幕我最终得到了一堆applescript文件。到目前为止,最好的选择似乎是Zebra浏览器打印SDK。该选项很快将无法作为各种浏览器制造商使用
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Management;
using System.Reflection;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        GetAllPrinterList();
        this.textBox1.Attributes.Add(
    "onkeypress", "button_click(this,'" + this.Button1.ClientID + "')");
        this.lstPrinterList.Attributes.Add(
    "onkeypress", "button_click(this,'" + this.Button1.ClientID + "')");

    }

    private void GetAllPrinterList()
    {
        //ManagementScope objScope = new ManagementScope(ManagementPath.DefaultPath); //For the local Access
        //objScope.Connect();

        //SelectQuery selectQuery = new SelectQuery();
        //selectQuery.QueryString = "Select * from win32_Printer";
        //ManagementObjectSearcher MOS = new ManagementObjectSearcher(objScope, selectQuery);
        //ManagementObjectCollection MOC = MOS.Get();
        //foreach (ManagementObject mo in MOC)
        //{
        //    lstPrinterList.Items.Add(mo["Name"].ToString());
        //    //lstPrinterList.Items.Add(new ListItem(mo["Name"].ToString()));

        //}

        lstPrinterList.Items.Add("\\\\10.32.65.6\\Parcel-Zebra-FDX ZM400");
        lstPrinterList.Items.Add("\\\\10.32.65.4\\Singles_Station_Z_Printer");
        lstPrinterList.Items.Add("\\\\10.32.65.12\\ZebraZ4M-Packaging");
        if (lstPrinterList.Items.Count > 3)
        {
        lstPrinterList.Items.RemoveAt(5);
        lstPrinterList.Items.RemoveAt(4);
        lstPrinterList.Items.RemoveAt(3);

        }

        //LocalPrintServer printServer = new LocalPrintServer();
        //string printer;
        //printer = LocalPrintServer.DefaultPrintQueue;
        //System.Management.ObjectQuery oquery =
        //        new System.Management.ObjectQuery("SELECT * FROM Win32_Printer");

        //    System.Management.ManagementObjectSearcher mosearcher =
        //        new System.Management.ManagementObjectSearcher(oquery);

        //    System.Management.ManagementObjectCollection moc = mosearcher.Get();

        //    foreach (ManagementObject mo in moc)
        //    {
        //        System.Management.PropertyDataCollection pdc = mo.Properties;
        //        foreach (System.Management.PropertyData pd in pdc)
        //        {
        //           // if ((bool)mo["Network"])
        //           // {
        //                lstPrinterList.Items.Add(mo["Name"].ToString());
        //           // }
        //        }
        //    }

        //}
        //        using (var printServer = new PrintServer(string.Format(@"\\{0}", PrinterServerName)))
        //{
        //    foreach (var queue in printServer.GetPrintQueues())
        //    {
        //        if (!queue.IsShared)
        //        {
        //            continue;
        //        }
        //        Debug.WriteLine(queue.Name);
        //     }
        // }
        //foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
        //{
        //MessageBox.Show(printer);
        //System.Web.UI.WebControls.ListBox lstPrinterList = new System.Web.UI.WebControls.ListBox();
        //System.Web.UI.WebControls.ListBox lstPrinterList = (System.Web.UI.WebControls.ListBox)Page.FindControl("lstPrinterList");
        //lstPrinterList.Text = "Zebra 110PAX4 (203 ;dpi)";

        //lstPrinterList.Items.Add(printer.ToString());
        //lstPrinterList.Items.Add(new ListItem(printer));
        //lstPrinterList.Items.Add(printer);
        //System.Web.UI.WebControls.ListBox lstPrinterList = (System.Web.UI.WebControls.ListBox)Page.FindControl("ListBox1");
        //Zebra 110PAX4 (203 dpi)
        //lstPrinterList.Items.Insert(printer);
        //}
    }


    //private void lstPrinterList_OnClick(object sender, System.EventArgs e)
    //{
    //    // Get the currently selected item in the ListBox.
    //    string curItem = lstPrinterList.SelectedItem.ToString();

    //    // Find the string in ListBox2.
    //    int index = lstPrinterList.DataTextField(curItem);
    //    //int index = lstPrinterList.FindString(curItem);
    //    //lstPrinterList.DataTextField(curItem);
    //    // If the item was not found in ListBox 2 display a message box, otherwise select it in ListBox2.
    //    if (index == -1)
    //        MessageBox.Show("Item is not available in ListBox2");
    //    else
    //        lstPrinterList.SetSelected(index, true);
    //}

    //private void button1_Click(object sender, System.EventArgs e)
    //{

    //    string str = File.ReadAllText("lpn.prn");
    //    str = str.Replace("BOX_TYPE", "boom");
    //    str = str.Replace("11111111", textBox1.Text);
    //    File.WriteAllText("lpn.prn", str);
    //            // Print the file to the printer.
    // RawPrinterHelper.SendFileToPrinter("\\\\Zebra-FDX ZM400 200 dpi (ZPL)", "C:\\Users\\Administrator\\Documents\\Visual Studio 2015\\Projects\\WindowsFormsApplication4\\Prn Print\\bin\\Debug\\lpn.prn");  
    //}

    public void button1_Click(object sender, System.EventArgs e)
    {
        String prnFile = "lpn2.prn";
        string s = File.ReadAllText(prnFile);
        string printer;
        String Printer = lstPrinterList.SelectedItem.ToString();
        s = s.Replace("*description*", "snuffles");
        s = s.Replace("*barcode*", textBox1.Text);
        //File.WriteAllText("PPlpn.prn", s);
        //s = "^XA^LH30,30\n^FO20,10^ADN,90,50^AD^FDHello World^FS\n^XZ";
        printer = lstPrinterList.SelectedItem.Value;
        PrintDialog pd = new PrintDialog();
        pd.PrinterSettings = new PrinterSettings();
        RawPrinterHelper.SendStringToPrinter(printer, s); 
        //RawPrinterHelper.SendStringToPrinter(Printer, s);
        //Response.Redirect(Request.RawUrl.Replace(Request.Url.Query, "?__VIEWSTATE=%2%3D&ctl00%24MainContent%24textBox1=bp300&ctl00%24MainContent%24lstPrinterList=Shipping+Printer"));




    }
    protected void textBox1_TextChanged(object sender, EventArgs e)
    {

    }
}




public class RawPrinterHelper
{
    // Structure and API declarions:
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public class DOCINFOA
    {
        [MarshalAs(UnmanagedType.LPStr)]
        public string pDocName;
        [MarshalAs(UnmanagedType.LPStr)]
        public string pOutputFile;
        [MarshalAs(UnmanagedType.LPStr)]
        public string pDataType;
    }
    [DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out IntPtr hPrinter, IntPtr pd);

    [DllImport("winspool.Drv", EntryPoint = "ClosePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool ClosePrinter(IntPtr hPrinter);

    [DllImport("winspool.Drv", EntryPoint = "StartDocPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool StartDocPrinter(IntPtr hPrinter, Int32 level, [In, MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di);

    [DllImport("winspool.Drv", EntryPoint = "EndDocPrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool EndDocPrinter(IntPtr hPrinter);

    [DllImport("winspool.Drv", EntryPoint = "StartPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool StartPagePrinter(IntPtr hPrinter);

    [DllImport("winspool.Drv", EntryPoint = "EndPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool EndPagePrinter(IntPtr hPrinter);

    [DllImport("winspool.Drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten);

    // SendBytesToPrinter()
    // When the function is given a printer name and an unmanaged array
    // of bytes, the function sends those bytes to the print queue.
    // Returns true on success, false on failure.
    public static bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, Int32 dwCount)
    {
        Int32 dwError = 0, dwWritten = 0;
        IntPtr hPrinter = new IntPtr(0);
        DOCINFOA di = new DOCINFOA();
        bool bSuccess = false; // Assume failure unless you specifically succeed.
        di.pDocName = "My C#.NET RAW Document";
        di.pDataType = "RAW";

        // Open the printer.
        if (OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero))
        {
            // Start a document.
            if (StartDocPrinter(hPrinter, 1, di))
            {
                // Start a page.
                if (StartPagePrinter(hPrinter))
                {
                    // Write your bytes.
                    bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
                    EndPagePrinter(hPrinter);
                }
                EndDocPrinter(hPrinter);
            }
            ClosePrinter(hPrinter);
        }
        // If you did not succeed, GetLastError may give more information
        // about why not.
        if (bSuccess == false)
        {
            dwError = Marshal.GetLastWin32Error();
        }
        return bSuccess;
    }

    public static bool SendFileToPrinter(string szPrinterName, string szFileName)
    {
        // Open the file.
        FileStream fs = new FileStream(szFileName, FileMode.Open);
        // Create a BinaryReader on the file.
        BinaryReader br = new BinaryReader(fs);
        // Dim an array of bytes big enough to hold the file's contents.
        Byte[] bytes = new Byte[fs.Length];
        bool bSuccess = false;
        // Your unmanaged pointer.
        IntPtr pUnmanagedBytes = new IntPtr(0);
        int nLength;

        nLength = Convert.ToInt32(fs.Length);
        // Read the contents of the file into the array.
        bytes = br.ReadBytes(nLength);
        // Allocate some unmanaged memory for those bytes.
        pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
        // Copy the managed byte array into the unmanaged array.
        Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
        // Send the unmanaged bytes to the printer.
        bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, nLength);
        // Free the unmanaged memory that you allocated earlier.
        Marshal.FreeCoTaskMem(pUnmanagedBytes);
        return bSuccess;
    }

    public static bool SendStringToPrinter(string szPrinterName, string szString)
    {
        IntPtr pBytes;
        Int32 dwCount;
        // How many characters are in the string?
        dwCount = szString.Length;
        // Assume that the printer is expecting ANSI text, and then convert
        // the string to ANSI text.
        pBytes = Marshal.StringToCoTaskMemAnsi(szString);
        // Send the converted ANSI string to the printer.
        SendBytesToPrinter(szPrinterName, pBytes, dwCount);
        Marshal.FreeCoTaskMem(pBytes);
        return true;
    }
}