Example #1
0
        public static void Print(String printer, String text, String textEncoding)
        {
            //Console.WriteLine("printer=" + printer + "| textEncoding=" + textEncoding + "|");
            //Console.WriteLine(text);
            byte[]   dstBytes    = (MazoviaEncoding.GetEncoding(textEncoding)).GetBytes(text);
            GCHandle pinnedArray = GCHandle.Alloc(dstBytes, GCHandleType.Pinned);
            IntPtr   pointer     = pinnedArray.AddrOfPinnedObject();

            RawPrinterHelper.SendBytesToPrinter(printer, pointer, dstBytes.Length);
            pinnedArray.Free();
        }
Example #2
0
        public void Print(string input)
        {
            string[] data = input.Split(new string[] { "@@@@" }, StringSplitOptions.RemoveEmptyEntries);

            LoadConfiguration(data);

            switch (printerModel)
            {
            case PrinterModel.Epson:
                printerCodes = new EpsonPrinterCodes();
                break;

            case PrinterModel.Seikosha:
                printerCodes = new SeikoshaPrinterCodes();
                break;

            case PrinterModel.OkiML320:
                printerCodes = new OkiML320PrinterCodes();
                break;

            case PrinterModel.IBM:
                printerCodes = new IBMPrinterCodes();
                break;

            default:
                throw new ArgumentException("Unknown printer model.");
            }

            XmlAttribute printerSelectionMode = configuration.DocumentElement.Attributes["selectPrinterByName"];

            if (IsPrinterSelectedByName(printerSelectionMode))
            {
                RawPrinterHelper.Print(portName, printerCodes.ReplaceChars(data[1]), textEncoding);
            }
            else
            {
                LptHelper.LptPrint(portName, printerCodes.ReplaceChars(data[1]), textEncoding);
            }
        }