Satyam
Satyam

Reputation: 15894

iOS - Getting warning and not able to print

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.

Upvotes: 2

Views: 2679

Answers (1)

Satyam
Satyam

Reputation: 15894

I solved the issue by using following methods related to ipad

- (BOOL)presentFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated completionHandler:(UIPrintInteractionCompletionHandler)completion;    // iPad
- (BOOL)presentFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated completionHandler:(UIPrintInteractionCompletionHandler)completion;      // iPad

Upvotes: 8

Related Questions