I figured out how to print basic text to our POS printer, but I can't figure out how to get the escape characters to work (for bold, text alignment, etc). For now I'm just testing with the Microsoft PosPrinter Simulator.
Here's what I'm trying
_printer.PrintNormal(PrinterStation.Receipt, (char)27 + "|bC" + printText + (char)13 + (char)10);
I'd expect that to print my printText
in bold followed by a line break. When I take out (char)27 + "|bC"
then it works fine.
The documentation for the escape codes is here
The error I get is
A first chance exception of type 'System.FormatException' occurred in Microsoft.PointOfService.ControlBase.dll Input string was not in a correct format.
I tried a bunch of variations but can't seem to wrap my head around it.
Edit. Here's the stack trace..
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s, IFormatProvider provider)
at Microsoft.PointOfService.DeviceSimulators.PosPrinterSimulatorWindow.ProcessEscapes(String str)
at Microsoft.PointOfService.DeviceSimulators.PosPrinterSimulatorWindow.DisplayText(String str)
at Microsoft.PointOfService.DeviceSimulators.PosPrinterSimulator.PrintNormalImpl(PrinterStation station, PrinterState printerState, String data)
at Microsoft.PointOfService.BaseServiceObjects.PosPrinterBase.OutputRequestHandler(OutputRequest Request)
at Microsoft.PointOfService.Internal.PosCommonInternal.ProcessOutputRequest(OutputRequest request, Boolean asyncOperation)
at Microsoft.PointOfService.BaseServiceObjects.PosPrinterBase.ProcessRequest(PrintOperation operation)
at Microsoft.PointOfService.BaseServiceObjects.PosPrinterBase.PrintNormal(PrinterStation station, String data)
at MyProjectNamespace) in MyFile.cs:line 74
Androidz answer is correct. Also you can do some thing like below.
Assume you want to print bold.
That's it.
This string worked for me "\u001B"
Did you check if your printer supports Bold, Italic etc? i.e.
I ended up determining how many characters could be printed per line and created some alignment functions. At this point I think there is nothing built-in to POS for .Net.
Still can't figure out bold, italics, etc. formatting.
From my testing I think the printer simulator will not accept the ESC character.
I create the text to send to the printer using a number of constant substitutes like:
so I might send the following to the printer:
To avoid getting the error when using the printer simulator I need to do the following
That removes the error however the text printed to the simulator includes all the ESC formatting.
Hi just found out this answer and this works for me. try this one.
or You can simply declare this:
then use it in your format or text like this:
ESC + "|cA" -- this is for center. ESC + "|bC" -- for bold.
ESC + "|bC" + "hello world" -- this will bold the string.