Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. -(void)printButtonTapped:(CGRect)rect
  2. {
  3. if ([UIPrintInteractionController isPrintingAvailable] == YES)
  4. {
  5. // NSURL *fileURL = document.fileURL; // Document file URL
  6. NSString* str=[NSString stringWithFormat:@"%@/Documents/mypdf.pdf",NSHomeDirectory()];
  7. NSURL* url=[NSURL URLWithString:str];
  8.  
  9.  
  10.  
  11. if ([UIPrintInteractionController canPrintURL:url] == YES)
  12. {
  13. self.printInteraction = [UIPrintInteractionController sharedPrintController];
  14.  
  15. UIPrintInfo *printInfo = [UIPrintInfo printInfo];
  16. printInfo.duplex = UIPrintInfoDuplexLongEdge;
  17. printInfo.outputType = UIPrintInfoOutputGeneral;
  18. printInfo.jobName = [url lastPathComponent];;
  19.  
  20. self.printInteraction.printInfo = printInfo;
  21. self.printInteraction.printingItem = url;
  22. self.printInteraction.showsPageRange = YES;
  23.  
  24. if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPad) // Large device printing
  25. {
  26. [self.printInteraction presentFromRect:rect inView:self.view animated:YES completionHandler:
  27. ^(UIPrintInteractionController *pic, BOOL completed, NSError *error)
  28. {
  29. #ifdef DEBUG
  30. if ((completed == NO) && (error != nil)) NSLog(@"%s %@", __FUNCTION__, error);
  31. #endif
  32. }
  33. ];
  34. }
  35. else // Handle printing on small device
  36. {
  37. [self.printInteraction presentAnimated:YES completionHandler:
  38. ^(UIPrintInteractionController *pic, BOOL completed, NSError *error)
  39. {
  40. #ifdef DEBUG
  41. if ((completed == NO) && (error != nil)) NSLog(@"%s %@", __FUNCTION__, error);
  42. #endif
  43. }
  44. ];
  45. }
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement