Strictly Programming

Printing in an Mac App

Posted in Objective-C, OS X by sqllyw on 10/01/2013

a simple way to add printing to your app.

  NSString *t = @"Hello Objective C Printing";
  NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
  [printInfo setTopMargin:3.0];
  // Printing Text
  NSRect textRect = NSMakeRect(0,0,500,648);
  NSTextView *theTextView = [[NSTextView alloc] initWithFrame:textRect];
  [theTextView  setFont:[NSFont fontWithName:@"Courier" size:9]];     
  [theTextView setString: t];
  NSPrintOperation *textPrint = 
                 [NSPrintOperation printOperationWithView:theTextView printInfo:printInfo];
  [textPrint setCanSpawnSeparateThread:YES];
  [textPrint runOperation];

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: