是否有任何已知的标签打印机可以接受来自网站或网络应用程序的打印命令?
具体来说,Dymo,Brother,Zebra等一次性标签打印机
是否有人成功打印过这些打印机(不使用仅限Internet Explorer的黑客或ActiveX控件)
我认为,最终,当我们进入一个更加以浏览器为中心的世界时,必须有一个解决方案。
答案 0 :(得分:28)
哇。我知道这是在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中的布局非常简单。浏览器完美地解析它,并以任何分辨率呈现给任何输出设备。这似乎很明显。
如果有人知道从浏览器打印的热敏标签打印机而不是用古老的集成方法监禁你,我非常想知道!
答案 1 :(得分:9)
Dymo打印机有一个浏览器插件,可让您从javascript进行打印。非常容易使用。
几年后重新审视这个问题。
联网的Zebra打印机易于打印。在一个项目中,我让webapplication打开一个插槽到打印机并在ZPL中提供说明。
答案 2 :(得分:6)
您还可以尝试查看提供云打印解决方案的PrintNode,这意味着您可以通过互联网直接打印到任何打印机。
答案 3 :(得分:4)
跨浏览器/平台兼容的网页/网页脚本没有将打印机语言命令(例如Zebra打印机语言[ZPL])传输到打印机所需的低级访问权限。为此,需要ActiveX控件/浏览器插件/ applet /类似位的可执行代码。此限制是非打印机特定的,来自浏览器而非打印机制造商。
然而,许多标签打印机允许您打印到它们,就像它们是普通打印机一样 - 只打印到非常小的纸张上。您可以使用HTML / CSS布局标签。显示结果时,指示用户转到“文件&gt;打印”并在单击打印前选择其标签打印机。
希望这有帮助,
本
答案 4 :(得分:2)
Zebra现在有一个名为“BrowserPrint”的工具,它的工作方式类似于PrintNode,专门用于Zebra打印机。 (与Printnode不同,它可以与Zebra打印机一起使用)
某些打印机也有可用的ppd文件和/或可以在Linux平台系统上以杯形配置,或者通过linux连接和说出。 (这意味着通过构建一个简单的服务器守护程序或在linux盒子上设置类似apache或lighttpd的东西甚至是连接到它的覆盆子pi,使用shell脚本,php,perl或其他方法来打印它是不可能的。打印机)
答案 5 :(得分:0)
您可以从已签名的Java小程序或Java Web Start应用程序打印:
http://java.sun.com/javase/technologies/desktop/printing/
如果您将打印输出格式化以使其适合标签,那么这应该可行。
请注意,大多数现代浏览器都限制对Java applet的支持,因此您可能会遇到applet的问题,具体取决于所使用的浏览器。特别是,谷歌浏览器将stop supporting Java applets in September 2015。这些限制不适用于Java Web Start,它应继续有效。
答案 6 :(得分: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#中创建的,效果很好。这是一个网络应用程序。