Note that there are some explanatory texts on larger screens.

plurals
  1. POtake & print a screenshot from IOS
    primarykey
    data
    text
    <p>I'm trying to take a screenshot and print it right away. For some reason it doesn't response right... I'm saving the screenshot into documents directory. Here is the code:</p> <pre><code>-(IBAction)printdoc { if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale); else UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); //UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); NSData * imageData = UIImageJPEGRepresentation(viewImage, 1.0); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"Screenshot.jpg"]; [imageData writeToFile:documentsDirectory atomically:YES]; NSString *myFilePath = [documentsDirectory stringByAppendingPathComponent:@"Screenshot.jpg"]; NSData *myData = [NSData dataWithContentsOfFile:myFilePath]; UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController]; if (pic &amp;&amp; [UIPrintInteractionController canPrintData:myData] ) { pic.delegate = self; NSLog(@"CAN PRINT !!!!!!!!!!!!"); UIPrintInfo *printInfo = [UIPrintInfo printInfo]; printInfo.outputType = UIPrintInfoOutputGeneral; printInfo.jobName = [myFilePath lastPathComponent]; printInfo.duplex = UIPrintInfoDuplexLongEdge; pic.printInfo = printInfo; pic.showsPageRange = YES; pic.printingItem = myData; void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) { if (!completed &amp;&amp; error) NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code); }; // iPad only printing [pic presentAnimated:YES completionHandler:completionHandler]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload