2010-11-02 133 views
24

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

具体地,一次性标签打印机如戴莫,兄弟,斑马等

有没有人有在印刷到这些打印机成功(不使用一个Internet Explorer-只有劈或ActiveX控件)

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

+0

这看起来很有前途:[PrinterShare](http://www.printeranywhere.com/) – drudge 2010-11-02 22:04:34

回答

3

跨浏览器/平台兼容的网页/网页脚本没有将打印机语言命令(如Zebra打印机语言[ZPL])传输到打印机所需的低级访问权限。为了做到这一点,需要ActiveX控件/浏览器插件/小程序/类似的可执行代码。这个限制是非打印机专用的,来自浏览器而不是打印机制造商。

但是,许多标签打印机允许您打印到它们,就好像它们是普通打印机 - 只是打印到非常小的纸张上的打印机。你可以使用HTML/CSS布局你的标签。当显示结果时,指示用户在点击打印前转到“文件>打印”并选择他们的标签打印机。

希望这有助于

+2

+1好主意。虽然将标签作为PDF发送可能会更好,但这样可以比使用HTML更好地控制输出格式。 – sleske 2010-11-02 22:05:41

0

您可以从一个签名的Java小程序打印,或从Java Web Start应用:

http://java.sun.com/javase/technologies/desktop/printing/

这应该工作,如果格式化您的打印​​输出,它适合标签。

请注意,大多数现代浏览器都限制对Java小程序的支持,因此您可能会遇到applet问题,具体取决于所使用的浏览器。特别是,Google Chrome将stop supporting Java applets in September 2015。这些限制做不是适用于Java Web Start,它应该继续工作。

+0

由于各种浏览器制造商限制并删除了运行Java小程序的功能,因此该选项很快将无法使用https://support.google.com/chrome/answer/1247383?hl=zh-CN – 2015-07-08 11:15:11

+0

此外; https://support.google.com/chrome/answer/6213033 – 2015-07-08 11:20:30

+0

@MarkCooper:感谢您的信息;我编辑了我的答案。 – sleske 2015-07-08 12:43:18

9

Dymo打印机有一个浏览器插件,可让您从javascript打印。非常容易使用。

几年后重温这个问题。

联网的Zebra打印机易于打印。在一个项目中,我使用网络应用程序打开了打印机的套接字,并在ZPL中提供了它的说明。

+0

感谢您添加一个链接到这个我会很难找到它,而不知道它存在。 – Sam 2016-06-14 08:27:51

23

哇。我知道这是在4年前被问及的,但是为了寻找从网络应用程序打印标签的强大方法而烧毁了一周的更好时间,我不得不在这里发表意见。

这里是我发现:

  • DYMO似乎卓越最有可能的人选。但是,不,结果是它只能从(a)自己的应用程序打印,或者(b)使用其SDK。 DYMO SDK使用的XML绘图模型过于复杂并且在布局和样式上受到限制。文档分散且难以理解(例如常见标签尺寸的<Bounds>值是什么?在任何地方都没有关于标签参数的描述!)令人沮丧,非常令人失望。

  • 这里有qz (was jzebra),它可以使用说EPL,ZPL,FGL,ESC/POS,EPCL和CPCL的设备进行浏览器打印,其中包括Zebra系列。它需要一个集成负载(在标签打印机所连接的设备上运行Web服务器),但它可以工作。

  • 有一个精心设计的3rd party app by Peninsula,它适用于DYMO(等等),但需要从浏览器打印到PDF的中间步骤。他们还假设你永远不会缩放你想要打印的内容小于70%,这是不正确的。

的OP说:“我认为,最终,就必须解决我们进入一个更加浏览器为中心的世界。”四年后,我会更进一步,并建议任何不能打印浏览器的标签打印机(或者只是像普通的小纸张打印机一样)的打印速度远远低于其潜力。 HTML + CSS中的布局非常简单。浏览器可以完美地解析它,并以任何分辨率呈现给任何输出设备。这似乎很明显。

如果有人知道热敏标签打印机是从浏览器打印出来的,而不是使用古老的集成方法将您囚禁起来,我非常想知道!

+0

我们有一个Dymo LabelWriter 450 Twin Turbo,我们可以从浏览器打印。打印html时,我们遇到了控制边距的问题,但它确实打印出来了。 – 2015-06-12 17:18:04

+0

@TimGautier - 你可以静静地从浏览器中获得这种打印吗?即没有打印对话框出现? – 2015-07-08 11:08:59

+0

没有。我认为你需要某种浏览器插件来做类似的事情。其他任何内容都将通过浏览器的打印对话框。 – 2015-07-08 19:35:02

4

您也可以尝试寻找PrintNode,它们提供云打印解决方案,并且意味着您可以通过互联网直接打印到任何打印机。

1

斑马现在有一个名为'BrowserPrint'的工具,它像PrintNode专为Zebra打印机工作。 (与Printnode不同,它可以免费使用Zebra打印机)

某些打印机也有可用的ppd文件和/或可以在linux平台系统中的杯子中配置,或者通过其他方式连接并通过linux进行语音。 (这意味着通过构建一个简单的服务器守护进程或在Linux机器上设置诸如apache或lighttpd之类的东西,或者甚至连接到一个树莓派上的树莓派,使用shell脚本,php,perl或其他方法来打印它也不是不可能的打印机)

+0

链接:https://www.zebra.com/us/en/products/software/barcode-printers/link-os/browser-print.html – David 2017-06-30 16:11:08

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

这就是我在C#中创建的,它工作得很好。这是一个网络应用程序。