Print UITableView that has content off screen?

Posted by Daniel on Stack Overflow See other posts from Stack Overflow or by Daniel
Published on 2012-03-21T17:25:28Z Indexed on 2012/03/21 17:30 UTC
Read the original article Hit count: 195

Filed under:
|
|
|

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];
}

© Stack Overflow or respective owner

Related posts about ios

Related posts about uitableview