Print UITableView that has content off screen?
- by Daniel
Hi I have an iOS app that has the ability to print a UITableView. However, only th part of the tableview that is shown is printed. Is there a way to print the whole tableview, even if it has not been drawn yet?
Here is the code I am using to print:
UIGraphicsBeginImageContext(self.mainTableView.contentSize);
[self.mainTableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIPrintInteractionController *printer = [UIPrintInteractionController sharedPrintController];
printer.printingItem = viewImage;
UIPrintInfo *info = [UIPrintInfo printInfo];
printer.printInfo = info;
UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
if (!completed && error)
NSLog(@"FAILED! due to error in domain %@ with error code %u: %@",
error.domain, error.code, [error localizedDescription]);
};
UIButton * printButton = (UIButton *)sender;
if(UIUserInterfaceIdiomPad == [[UIDevice currentDevice] userInterfaceIdiom]){
[printer presentFromRect:printButton.frame inView:self.view animated:YES completionHandler:completionHandler];
} else {
[printer presentAnimated:YES completionHandler:completionHandler];
}