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

  • Home
  • SEARCH
  • 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

Note The question below was asked in 2008 about some code from 2003. As
See code below, for some reason it only works when I put a breakpoint
In the code below I'm trying to load some images and put them in
I've been using the idiom below for some time now. And it seems to
For some reason I'm not getting this. (Example model below) If I write: var
I have an xslt sheet with some text similar to below: <xsl:text>I am some
Some batch files on Windows use an IF syntax with multiple lines, as below:
I've just started with opengl but I ran into some strange behaviour. Below I
WinForms C#.. am getting some JSON in the format below (bottom of message) and
i found the below plugin for showing messages ... http://bassistance.de/jquery-plugins/jquery-plugin-message/ we can change the

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.