1

按照这篇文章的问题: 无法使用 AirPrint 显示打印机选项

我有几个问题:

1)答案之一是将 Controller.printItem 设置为 URL。同样,我可以设置多个 URL 吗?基本上,我有一组需要一次性打印的 URL。是否可以将 controller.printitems 设置为 URL 数组?另外,我知道 controller.printItem 采用“数据”类型,那么如何将基于 Web 的图像 URL 转换为“数据”类型?

2)由于某种奇怪的原因,默认情况下,每次我到达打印对话框时,双面都设置为打开。我需要设置什么变量?如果我不能向用户显示该选项,那就太好了。

4

2 回答 2

0

试试这个代码可能对你有帮助

- (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;
}
于 2012-04-11T11:14:26.107 回答
0

我知道它很晚,但如果有人需要这个可能会有所帮助:创建 URL 数组并将其分配给“UIPrintInteractionController”类的“printingItems”属性。

于 2017-07-18T09:23:32.783 回答