public bool SendToPrinter(string printerName) { var success = true; foreach (var page in Pages) { success = RawPrinterHelper.SendManagedBytesToPrinter(printerName, page); if (!success) { break; } } return(success); }
static private void Print(PackageComponent PrintComponent, string guid) { //nugget: sending raw ESCape codes to dot matrix printer (Epson's "ESC/P" standard) //nugget: ESC/P reference manual: http://files.support.epson.com/pdf/general/escp2ref.pdf //ESC @ = reset //ESC x n = quality: 0 = Draft, 1 = NLQ //ESC k n = font: 0 = Roman, 1 = Sans serif font //ESC M = 12 cpi //reinitialize the page every time by filling the array with spaces plus a line feed at the end of every line... Buffer.BlockCopy(Encoding.ASCII.GetBytes(pageinit), 0, pagebytes, 0, pageinit.Length); // "flattening a 2D array": http://www.dotnetperls.com/flatten-array // logicalrow = row * pagewidth byte[] rowbytes = Encoding.ASCII.GetBytes(new string(' ', pagewidth)); rowbytes[pagewidth - 1] = 0x0A; // linefeed (LF) pagebytes[pagebytes.Length - 1] = 0x0C; // form feed (FF) //apparently simple for-loop is the recommended best practice for this drudgery //http://stackoverflow.com/questions/1897555/what-is-the-equivalent-of-memset-in-c //http://stackoverflow.com/questions/6150097/initialize-a-byte-array-to-a-certain-value-other-than-the-default-null for (int row = 0; row < pageheight; row++) { PrintBytesAtPos(rowbytes, 0, row); } PrintStringAtPos(String.Format("{0}{0}{0}{0}{0}{0}{0}{0}{0}123456", "1234567890"), 0, 0); PrintStringAtPos(String.Format("2 1{0}2{0}3{0}4{0}5{0}6{0}7{0}8{0}9", " "), 0, 1); for (int row = 2; row < pageheight; row++) { //we need to leave FormField data definition 0-based to be consistent with v1... //but want to view in 1-based on the hardcopy PrintStringAtPos((row + 1).ToString(), 0, row); } RawPrinterHelper.SendManagedBytesToPrinter(Setting.Local["POPrinter"], pagebytes); return; using (Proc TaxForm_print = new Proc("TaxForm_print")) { TaxForm_print["@TaxFormGUID"] = guid; //for testprint, pass Guid.Empty i.e. '00000000-0000-0000-0000-000000000000' TaxForm_print["@PrintComponent"] = (int)PrintComponent; TaxForm_print.ExecuteDataSet(); Printer POPrinter = InitDotMatrix(Setting.Local["POPrinter"]); //coding defensively, reset printer settings with every print... so agents can readily power cycle the printer with no ramifications, etc. Printer AbwPrinter = ((Setting.Local["POPrinter"] == Setting.Local["AbwPrinter"])) ? POPrinter : InitDotMatrix(Setting.Local["AbwPrinter"]); //don't re-init the same printer if (guid == Guid.Empty.ToString()) //test mode... { SetCurrentXY(POPrinter, 0, 0); POPrinter.Write(String.Format("{0}{0}{0}{0}{0}{0}{0}{0}{0}123456", "1234567890")); SetCurrentXY(POPrinter, 0, 1); POPrinter.Write(String.Format("2 1{0}2{0}3{0}4{0}5{0}6{0}7{0}8{0}9", " ")); for (int i = 2; i <= 63; i++) { //we need to leave FormField data definition 0-based to be consistent with v1... SetCurrentXY(POPrinter, 0, i); //but want to view in 1-based on the hardcopy POPrinter.Write((i + 1).ToString()); } } PrintFields(POPrinter, TaxForm_print.dataSet.Tables[0].Rows); PrintFields(AbwPrinter, TaxForm_print.dataSet.Tables[1].Rows); } }