I am using a code to get Airprint in my app to print the current view as an image. the Airprint dialog pops up but in the log screen it shows me two warnings :
1) WARNING: Calling -[UIPrintInteractionController presentAnimated:completionHandler:] on iPad failed to find PDF header: `%PDF' not found.
2)[UIPopoverController_commonPresentPopoverFromRect: inView:permittedArrowDirections:animated:]: the rect passed in to this method must have non-zero width and height. This will be an exception in a future release.
I have already searched in the net but found that all solutions provided for regular rect Button
what I am using here is a segmented control, and I don't know how to use this control in this situation
here is the segment control code :
- (IBAction)legalSegment:(id)sender {
switch (((UISegmentedControl *)sender).selectedSegmentIndex) {
case 0:
{
[self printItem];
break;
}
}
and this is the printItem method :
-(void)printItem {
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 *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
}
};
[pic presentAnimated:YES completionHandler:completionHandler];
}
}
any help will be great. Thanks in advance !
On iPad, you should use the popover API provided by the controller. It is mentioned in the documentation.
presentAnimated:completionHandler:
Presents the iPhone printing user interface in a sheet that can be animated to slide up from the bottom of the screen.
presentFromBarButtonItem:animated:completionHandler:
Presents the iPad printing user interface in a popover view that can be animated from a bar-button item.
presentFromRect:inView:animated:completionHandler:
Presents the iPad printing user interface in a popover view that can be animated from any area in a view.
You should use the correct method on the corresponding device type.
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
[pic presentFromRect:self.view.frame inView:self.view animated:YES completionHandler:completionHandler];
}
else {
[pic presentAnimated:YES completionHandler:completionHandler];
}
You should use appropriate parameters for the popover presentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With