0

i have star micronics and im implementing SDK in my app, but i cant print the € symbol

[mutableData appendData:[@"\x1b\x1d\x74\x04 123" dataUsingEncoding:NSMacOSRomanStringEncoding allowLossyConversion:YES]];

but print other character

also try with

 [mutableData appendData:[@"\xE2\x82\xac\r\n 123" dataUsingEncoding: NSUTF8StringEncoding allowLossyConversion:YES]];

someone knows what is the code to print it?

rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

1

This will do the trick:

builder is your ISCBBuilder variable.

builder.append(.CP858)
builder.appendByte(0xd5)
Shahriyar
  • 520
  • 7
  • 18
0

NSString in Objective-C is internally encoded as UTF-16, and the euro symbol has code 0x20AC. So first you need to define your string like so:

    NSString *euroSymbol1 = @"\u20AC";
    NSString *euroSymbol2 = @"€"; // same as euroSymbol1
    if ([euroSymbol1 isEqualToString:euroSymbol2])
        NSLog(@"equivalent"); // this is printed
    NSString *price = [NSString stringWithFormat:@"%@ %.2f", euroSymbol1, 123.45];
    NSLog(@"%@", price); // prints: "€ 123.45"

Note that if you just write "€" the compiler is smart to re-encode your source code encoding to the NSString encoding, so it is trivial to read.

Then you need to understand what encoding does your printer support. If it supports Unicode, you should try it first, because it definitely contains the euro symbol. Note that the whole mutableData must be in the same encoding, so if you have appended other strings before this one, you need to make sure that all of them use the same encoding (for example NSUTF8StringEncoding).

If you need to use NSMacOSRomanStringEncoding, then the euro symbol might not be supported (see this reply), although here in the table you can still see it under the code 219.

battlmonstr
  • 5,841
  • 1
  • 23
  • 33