I’m using iOS 5.0.1 to develop an app.
I’m using the following code to print the screen shot of the view in my ipad app:
CGRect rect = CGRectMake(0, 0, 768, 1004);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIPrintInteractionController* pic = [UIPrintInteractionController sharedPrintController];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(img)];
if (pic && [UIPrintInteractionController canPrintData:imageData])
{
pic.delegate = self;
UIPrintInfo* printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputPhoto;
printInfo.jobName = @"PrintingImage";
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = imageData;
void (^completionHandler) (UIPrintInteractionController *, BOOL, NSError*) = ^(UIPrintInteractionController *pic, BOOL completed, NSError* error) {
if (!completed && error) {
NSLog(@"Error: %@", error.localizedDescription);
}
};
[pic presentAnimated:YES completionHandler:completionHandler];
}
Its not showing the printing view and throwing following error:
WARNING: Calling -[UIPrintInteractionController presentAnimated:completionHandler:] on iPad
failed to find PDF header: `%PDF' not found.
failed to find PDF header: `%PDF' not found.
failed to find PDF header: `%PDF' not found.
failed to find PDF header: `%PDF' not found.
I solved the issue by using following methods related to ipad