Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. if ([UIPrintInteractionController isPrintingAvailable]) {
  2. UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
  3. pic.delegate = self;
  4. UIPrintInfo *printInfo = [UIPrintInfo printInfo];
  5. printInfo.outputType = UIPrintInfoOutputGeneral;
  6. printInfo.jobName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
  7. pic.printInfo = printInfo;
  8.  
  9. UIViewPrintFormatter* printFormatter = articleWebView.viewPrintFormatter;
  10. pic.printFormatter = printFormatter;
  11.  
  12. pic.showsPageRange = NO;
  13. if([pic respondsToSelector:@selector(showsNumberOfCopies)]) {
  14. pic.showsNumberOfCopies = NO;
  15. }
  16.  
  17. void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
  18. if (!completed && error) {
  19. NSLog(@"Printing could not complete because of error: %@", error);
  20. }
  21. };
  22.  
  23. CGRect senderFrame = ((UIButton*)sender).frame;
  24. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  25. [pic presentFromRect:senderFrame inView:self.view animated:YES completionHandler:completionHandler];
  26. } else {
  27. [pic presentAnimated:YES completionHandler:completionHandler];
  28. }
  29.  
  30. } else {
  31. NSLog(@"WARN: printing is not available");
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement