Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4257454
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:30:50+00:00 2026-05-21T05:30:50+00:00

Below is some sample code showing ESC/POS commands from Epson, and unfortunately I’m a

  • 0

Below is some sample code showing ESC/POS commands from Epson, and unfortunately I’m a newbie with respect to character formatting and objective c.

PRINT #1, CHR$(&H1B);"@";
PRINT #1, CHR$(&H1B);"a";CHR$(1);
PRINT #1, CHR$(&H1B);"!";CHR$(0);
PRINT #1, CHR$(&H1B);"J";CHR$(4);
PRINT #1, “January 14, 1998 15:00”;
PRINT #1, CHR$(&H1B);"d";CHR$(3);
PRINT #1, CHR$(&H1B);"a";CHR$(0);
PRINT #1, CHR$(&H1B);"!";CHR$(1);
PRINT #1, "TM-U200B $20.00";CHR$(&HA);
PRINT #1, "TM-U200D $21.00";CHR$(&HA);
PRINT #1, "PS-170 $17.00";CHR$(&HA);
PRINT #1, CHR$(&HA);
PRINT #1, CHR$(&H1B);”!”;CHR$(17);
PRINT #1, CHR$(&H1B);”U”;CHR$(1);
PRINT #1, "TOTAL $58.00";CHR$(&HA);
PRINT #1, CHR$(&H1B);"U";CHR$(0);
PRINT #1, CHR$(&H1B);”!”;CHR$(0);
PRINT #1, "------------------------------";CHR$(&HA);
PRINT #1, "PAID $60.00";CHR$(&HA);
PRINT #1, "CHANGE $ 2.00";CHR$(&HA);
PRINT #1, CHR$(&H1D);"V";CHR$(66);CHR$(0);
END

Anyone know how I would convert the above into a NSData format (either in a single NSData object or multiple NSData objects)? Any guidance is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:30:50+00:00Added an answer on May 21, 2026 at 5:30 am

    I would recommend creating a formatter class that keeps an NSMutableData object representing the bytes that are to be sent to the printer. For instance,

    // EpsonFormatter.h
    #import <Foundation/Foundation.h>
    
    @interface EpsonFormatter : NSObject {
        NSMutableData *_data;
    }
    
    @property (readonly) NSMutableData *data;
    
    - (void)initializePrinter;
    - (void)selectCenterJustification;
    - (void)selectStandardPrinterMode;
    - (void)appendString:(NSString *)string;
    @end
    
    // EpsonFormatter.m
    #import "EpsonFormatter.h"
    
    @implementation EpsonFormatter
    
    #define EpsonFormatterESCString "\x1b"
    
    @synthesize data = _data;
    
    - (id)init {
        self = [super init];
        if (self) {
            _data = [[NSMutableData alloc] init];
        }
        return self;
    }
    
    - (void)dealloc {
        [_data release];
        [super dealloc];
    }
    
    - (void)initializePrinter {
        [_data appendBytes:EpsonFormatterESCString "@" length:2];
    }
    
    - (void)selectCenterJustification {
        [_data appendBytes:EpsonFormatterESCString "a" "\x1" length:3];
    }
    
    - (void)selectStandardPrinterMode {
        [_data appendBytes:EpsonFormatterESCString "!" "\x0" length:3];
    }
    
    - (void)appendString:(NSString *)string {
        [_data appendData:[string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]];
    }
    
    @end
    

    You would use this class like this:

    #import "EpsonFormatter.h"
    EpsonFormatter *epsonFormatter = [[[EpsonFormatter alloc] init] autorelease];
    [epsonFormatter initializePrinter];
    [epsonFormatter selectCenterJustification];
    [epsonFormatter selectStandardPrinterMode];
    [epsonFormatter appendString:@"January 14, 1998 15:00"];
    // …
    
    // In order to obtain the underlying NSData object:
    NSData *outputData = epsonFormatter.data;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this database table (some sample code below) that stores the relationship
Below is some sample code. The window does not resize (python3.2, on a Mac,
Below is a some sample code I am trying to update. The client would
This is some sample code copied from The C++ Programming Language chapter 17 as
below is some code I am using to translate a map array into SQL
Below is some code I've written that is effective, but makes too many database
When I use a conditional statement targeting IE6 and below with some PHP code
// .net 2.0 and vs2005 used. I find some code below. I am not
Below I present you some code which has completely been butchered by me. $(.gig).hover(function()
I'm playing with some sample code to try and figure out once and for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.