Example #1
0
        public void WriteLine(string lineToPrint)
        {
            if (!this.isPrinterReady)
            {
                throw new InvalidOperationException("No se ha Inicializado la Impresora");
            }

            if (!lineToPrint.EndsWith("\r\n"))
            {
                lineToPrint = lineToPrint + "\r\n";
            }

            int dwCount = lineToPrint.Length;

            // Assume that the printer is expecting ANSI text, and then convert
            // the string to ANSI text.
            IntPtr pBytes = Marshal.StringToCoTaskMemAnsi(lineToPrint);

            if (this.myHandle != IntPtr.Zero)
            {
                try
                {
                    int dataWrittenSize;
                    if (RawPrinterComponent.WritePrinter(this.myHandle, pBytes, dwCount, out dataWrittenSize))
                    {
                        if (dwCount != dataWrittenSize)
                        {
                            Trace.WriteLine("Advertencia Al Imprimir BarCodeEPL");
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Error Al Imprimir BarCodeEPL");
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Error Al Imprimir BarCodeEPL : " + ex.Message);
                }
            }

            Marshal.FreeCoTaskMem(pBytes);
        }