1
votes

Following the question from this post: Unable to display printer options with AirPrint

There were few questions I had:

1) One of the answers were to set Controller.printItem to a URL. Similarly, Can I set multiple URLs? Basically, I have a set of URLs I need to print at one shot. Is it possible to set controller.printitems to an array of URLs? Also, I know controller.printItem takes a type 'data', so how do I convert a web based image URL to a type 'data'?

2) For some weird reason, by default, doubled sided is set to on every time I reach the print dialog. What is the variable I need to set that off? It would be great if I could just not show the option to the user.

2
please try the reference link sugartin.info/2012/02/02/… - Nimit Parekh

2 Answers

0
votes

Try this code may help to you

- (IBAction)btnPrintTapped:(id)sender {
    NSData *imageData = UIImagePNGRepresentation(self.imgV.image);
    [self printItem:imageData];
}

#pragma mark - Printing 

-(void)printItem :(NSData*)data {
    printController = [UIPrintInteractionController sharedPrintController];
    if(printController && [UIPrintInteractionController canPrintData:data]) {
        printController.delegate = self;
        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        printInfo.outputType = UIPrintInfoOutputGeneral;
        printInfo.jobName = [NSString stringWithFormat:@""];
        printInfo.duplex = UIPrintInfoDuplexLongEdge;
        printController.printInfo = printInfo;
        printController.showsPageRange = YES;
        printController.printingItem = data;
        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);
            }
        };
        [printController presentFromBarButtonItem:self.item animated:YES completionHandler:completionHandler];
    }
}

- (BOOL)presentFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated completionHandler:(UIPrintInteractionCompletionHandler)completion {
    return YES;
}

- (BOOL)presentFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated completionHandler:(UIPrintInteractionCompletionHandler)completion {
    return YES;
}
0
votes

I know its late but might help if someone needs this: Create array of URLs and assign it to "printingItems" property of "UIPrintInteractionController" class.