问题描述
我想出了如何在POS打印机上打印基本文本,但是我想不出如何使转义符起作用(粗体,文本对齐等).现在,我仅在使用Microsoft PosPrinter Simulator进行测试.
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.
这就是我正在尝试的
_printer.PrintNormal(PrinterStation.Receipt, (char)27 + "|bC" + printText + (char)13 + (char)10);
我希望将我的printText
打印为粗体,然后换行.当我取出(char)27 + "|bC"
时,它可以正常工作.
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.
此处是转义代码的文档
我得到的错误是
我尝试了很多变化,但似乎无法将其包裹住.
I tried a bunch of variations but can't seem to wrap my head around it.
修改.这是堆栈跟踪.
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
推荐答案
您好,我刚刚找到了这个答案,这对我有用.试试这个.
Hi just found out this answer and this works for me. try this one.
string Bold = System.Text.ASCIIEncoding.ASCII.GetString(new byte[] { 27, (byte)'|', (byte)'b', (byte)'C' });
或者您可以简单地声明以下内容:
or You can simply declare this:
string ESC = System.Text.ASCIIEncoding.ASCII.GetString(new byte[] {27});
然后以您的格式或类似这样的文字使用它:
then use it in your format or text like this:
ESC +"| cA"-这是居中的. ESC +"| bC"-粗体.
ESC + "|cA" -- this is for center. ESC + "|bC" -- for bold.
ESC +"| bC" +"hello world"-这将使字符串加粗.
ESC + "|bC" + "hello world" -- this will bold the string.
这篇关于用于.Net打印格式的POS-不能使用转义符(char)27的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!