7

在我的应用程序中,如何允许用户从 iPhone 或 iPad 打印文档或页面?哪些版本的 iOS 支持打印?

4

2 回答 2

18

这是一个简单的代码。

-(void)printItem {

    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.view.layer renderInContext:context];
    UIImage *imageFromCurrentView = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];
    printController.printingItem = imageFromCurrentView;
    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGrayscale;
    printController.printInfo = printInfo;
    printController.showsPageRange = YES;


        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 presentAnimated:YES completionHandler:completionHandler];

    } 
于 2012-02-17T10:56:28.757 回答
6

您可以在任何运行 iOS 4.2 或更高版本的多任务设备上打印。有关更多信息,请参阅:http: //developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/Printing/Printing.html#//apple_ref/doc/uid/TP40010156-CH12-SW1

于 2011-02-07T07:08:51.833 回答