In my app, I have the user make a coupon, preview it, and they have the option to print that coupon. Right now it simply crops down the screen to include the coupon part only and prints, but it is printing to a full-size 8.5 x 11 and uses lots of ink in doing so as the coupon is black in background. How can this be altered to only print say to a 2.5 x 3.5 " section of the paper?
-(void)printer {
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
if(!controller){
NSLog(@"Couldn't get shared UIPrintInteractionController!");
return;
}
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if(!completed && error){
NSLog(@"FAILED! due to error in domain %@ with error code %u",
error.domain, error.code);
}
};
CGRect rect;
rect=CGRectMake(0, 0, 320, 480);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context=UIGraphicsGetCurrentContext();
[self.tabBarController.view.layer renderInContext:context];
UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage *img = [self cropImage:image rect:CGRectMake(20,70,279,359)];
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputPhoto;
printInfo.jobName = @"Your Coupon";
controller.printInfo = printInfo;
controller.showsPageRange = YES;
controller.printingItem = img;
[controller presentAnimated:YES completionHandler:completionHandler];
}
Sounds like it scales the image you print to the full size of the output media. You could try putting your coupon image into a larger image and printing that composite image. I didn't test this code but it is an adaptation of something I do to crop images.