Ejemplo n.º 1
0
        public void PrintESC(int type)
        {
            System.IntPtr lhPrinter = new System.IntPtr();
            DOCINFO       di        = new DOCINFO();
            int           pcWritten = 0;

            di.pDocName  = "进退纸Document";
            di.pDataType = "RAW";

            try
            {
                PrintDirect.OpenPrinter(this.PrintPort, ref lhPrinter, 0);
                if (lhPrinter == IntPtr.Zero)
                {
                    return;
                }
                PrintDirect.StartDocPrinter(lhPrinter, 1, ref di);
                PrintDirect.StartPagePrinter(lhPrinter);
                string send = string.Empty;
                for (int j = 0; j < 3; j++)
                {
                    switch (type)
                    {
                    case 0:
                        send = "" + (char)(27) + (char)(64) + (char)(27) + 'j' + (char)(180);    //退纸
                        break;

                    case 1:
                        send = "" + (char)(27) + (char)(64) + (char)(27) + 'J' + (char)(180);    //进纸
                        break;

                    case 2:
                        send = "" + (char)(27) + (char)(64) + (char)(12);       //换行(未测试)
                        break;

                    default:
                        send = "" + (char)(27) + (char)(64) + (char)(12);       //换行(未测试)
                        break;
                    }
                    byte[] buf = new byte[80];
                    for (int i = 0; i < send.Length; i++)
                    {
                        buf[i] = (byte)send[i];
                    }
                    PrintDirect.WritePrinter(lhPrinter, send, send.Length, ref pcWritten);
                }
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.Message);
            }
            finally
            {
                if (lhPrinter != IntPtr.Zero)
                {
                    PrintDirect.EndPagePrinter(lhPrinter);
                    PrintDirect.EndDocPrinter(lhPrinter);
                    PrintDirect.ClosePrinter(lhPrinter);
                }
            }
        }
Ejemplo n.º 2
0
 public static extern long StartDocPrinter(IntPtr hPrinter, int Level, ref DOCINFO pDocInfo);