2010-11-02 7 views
24

Esistono stampanti di etichette note che accettano comandi di stampa da un sito Web o un'applicazione web?Stampare su una stampante per etichette da un sito Web/un'applicazione Web?

In particolare, le stampanti di etichette una tantum, come Dymo, Fratello, Zebra, ecc

Qualcuno ha avuto successo nella stampa di queste stampanti (senza l'utilizzo di un Internet Explorer-Only incidere o il controllo ActiveX)

Penso che, alla fine, ci dovrebbe essere una soluzione mentre ci spostiamo in un mondo più incentrato sui browser.

+0

Questo sembra promettente: [PrinterShare] (http://www.printeranywhere.com/) – drudge

risposta

3

Uno script di pagina Web/pagina Web compatibile con browser o piattaforme non ha l'accesso di basso livello necessario per trasmettere comandi di stampa della stampante (come Zebra Printer Language [ZPL]) alla stampante. Per fare ciò, è richiesto un controllo ActiveX/plugin per browser/applet/simile bit di codice eseguibile. Questa limitazione non è specifica della stampante, proveniente dal browser e non dal produttore della stampante.

Tuttavia, molte stampanti di etichette consentono di stampare su di esse come se fossero normali stampanti, solo quelle che stampano su fogli di carta molto piccoli. Potresti impaginare la tua etichetta usando HTML/CSS. Quando si visualizzano i risultati, chiedere all'utente di andare su "File> Stampa" e selezionare la stampante di etichette prima di fare clic su Stampa.

Spero che questo aiuti,
Ben

+2

+1 Buona idea. Anche se probabilmente è meglio inviare le etichette come PDF, in questo modo si ha un migliore controllo sulla formattazione dell'output rispetto all'utilizzo di HTML. – sleske

0

È possibile stampare da un applet Java firmato, o da una Java Web Start applicazione:

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

Che dovrebbe funzionare, se si formatta l'output di stampa in modo si adatta alle etichette.

Si noti che la maggior parte dei browser moderni limita il supporto per le applet Java, pertanto è possibile che si verifichino problemi con un'applet, a seconda dei browser in uso. In particolare, Google Chrome sarà stop supporting Java applets in September 2015. Queste restrizioni fanno non si applicano a Java Web Start, che dovrebbe continuare a funzionare.

+0

Questa opzione sarà presto inutilizzabile in quanto i vari produttori di browser limitano e quindi rimuovono la possibilità per le applet Java di eseguire https://support.google.com/chrome/answer/1247383?hl=it –

+0

Inoltre; https://support.google.com/chrome/answer/6213033 –

+0

@MarkCooper: Grazie per l'informazione; Ho modificato la mia risposta. – sleske

9

Le stampanti Dymo dispongono di un plug-in del browser che consente di stampare da javascript. Molto facile da usare.

Rivisitare questa domanda alcuni anni dopo.

Le stampanti di rete Zebra sono facili da stampare. In un progetto ho avuto l'applicazione web aprire un socket per la stampante e alimentarlo istruzioni in ZPL.

+0

Grazie per aver aggiunto un collegamento a questo avrei avuto difficoltà a trovare questo senza sapere che esistesse. – Sam

23

Wow. So che questo è stato chiesto più di 4 anni fa, ma dopo aver bruciato la parte migliore di una settimana alla ricerca di un metodo affidabile per stampare etichette da un'applicazione web, ho dovuto intervenire qui.

Ecco cosa ho trovato:

  • DYMO sembra il candidato più probabile per l'eccellenza. Ma no, risulta solo stampe da (a) la sua app, o (b) qualcosa che usa il suo SDK. DYMO SDK utilizza un modello di disegno XML troppo complesso e limitato nel layout e nello stile. La documentazione è sparsa e incomprensibile (ad esempio, quali sono i valori dello standard <Bounds> per le dimensioni comuni dell'etichetta? Non c'è alcuna descrizione dei parametri del tag da nessuna parte!) Così frustrante, così deludente.

  • C'è qz (was jzebra), che consente la stampa del browser per dispositivi che parlano EPL, ZPL, FGL, ESC/POS, EPCL e CPCL ... che include la serie Zebra. Richiede un carico di integrazione (esecuzione di un server Web sul dispositivo a cui è collegata la stampante per etichette), ma funziona.

  • C'è un 3rd party app by Peninsula ben progettato, che funziona per DYMO (tra gli altri), ma richiede una fase intermedia di stampa dal browser al PDF. Suppongono anche che non ridimensionerai mai ciò che desideri stampato meno del 70%, il che non è corretto.

Il PO dice: "Mi sembra che, alla fine, ci dovrebbe essere una soluzione come ci muoviamo in un mondo più del browser-centrica". Quattro anni più tardi, farei un ulteriore passo avanti e suggerirei che qualsiasi stampante di etichette che non è in grado di stampare da un browser (o semplicemente si comporta come una normale stampante con carta di piccole dimensioni) sta cadendo WAY meno del suo potenziale. Layout in HTML + CSS è un gioco da ragazzi. I browser lo analizzano perfettamente e lo rendono a qualsiasi risoluzione su qualsiasi dispositivo di output. Sembra così ovvio.

Se qualcuno sa di una stampante termica per etichette che stampa dal browser invece di imprigionarla in metodi di integrazione arcaica, mi piacerebbe molto sapere!

+0

Abbiamo un Dymo LabelWriter 450 Twin Turbo che possiamo stampare da un browser. Abbiamo problemi a controllare il margine quando stampi html, ma stampa. –

+0

@TimGautier: è possibile ottenere questa stampa da un browser in silenzio? vale a dire senza la finestra di dialogo di stampa che appare? –

+0

No. Penso che avresti bisogno di una sorta di plugin per il browser per fare qualcosa del genere. Tutto il resto passerà attraverso la finestra di dialogo di stampa del browser. –

4

Si potrebbe anche provare a cercare PrintNode che forniscono una soluzione di stampa cloud e significa che è possibile stampare direttamente su qualsiasi stampante su Internet.

1

Zebra ora ha uno strumento chiamato "BrowserPrint" che funziona come PrintNode specificamente per le stampanti Zebra. (a differenza di Printnode, è gratuito da usare con le stampanti Zebra)

Alcune stampanti hanno anche file ppd disponibili e/o possono essere configurati in cups su un sistema di piattaforma linux o altrimenti collegati e parlati anche via linux. (che significa quindi che non è impossibile usare qualcosa da shell scripting, php, perl o altri metodi per stamparlo creando un semplice demone server o impostando qualcosa come apache o lighttpd su una linux box o anche un raspberry pi collegato al stampante)

+0

Ecco il link: https://www.zebra.com/us/en/products/software/barcode-printers/link-os/browser-print.html – David

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

Questo è quello che ho creato in C# e ha funzionato benissimo. Questa è un'app web.