Air Print images objective c

1k Views Asked by At

I am a beginner to xcode and I wanted to print using Air Print for my objective C app. Here is the code I have currently.

-(IBAction)Print {

  UIImage *image  = [UIImage imageNamed:@"picTwizzlerfw.png"];

     NSMutableString *printBody = [NSMutableString stringWithFormat:@"%@",_TextField.text];

  UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    //pic.delegate = self;


  UIPrintInfo *printInfo = [UIPrintInfo printInfo];
  printInfo.outputType = UIPrintInfoOutputGeneral;
  printInfo.jobName = @"PrintJob";
  pic.printInfo = printInfo;


      UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc] initWithText:printBody];
  textFormatter.startPage = 0;
  textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0);
  textFormatter.maximumContentWidth = 6 * 72.0;
  pic.printFormatter = textFormatter;
  pic.showsPageRange = YES;


  void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
    if (!completed && error) {
      NSLog(@"Printing could not complete because of error: %@", error);
    }
  };


  [pic presentAnimated:YES completionHandler:completionHandler];

}

Right now it is printing the TextField but I want it to print the image. If any one could help that would be great!

1

There are 1 best solutions below

0
On

Add:

pic.printingItem = image;

and remove the text formatter:

pic.printFormatter = textFormatter;