我对 iOS 编程非常陌生,遇到了一个问题。我有一个 pdf 我想从互联网上打印出来。我如何在没有第三方应用程序的情况下通过我的应用程序打印这个?另外,我听说过苹果的 AirPrint,它预装在 iOS 设备上。我将如何使用它?谢谢。
问问题
1305 次
1 回答
3
.H 文件代码
#import
@interface xyviewController : UIViewController <...,UIPrintInteractionControllerDelegate> {
UIPrintInteractionControllerDelegate should be delegate
}
-(IBAction)printdoc;
.M 文件代码
-(IBAction)printdoc
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"jpg"];
NSData *myData = [NSData dataWithContentsOfFile: path];
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
if(pic && [UIPrintInteractionController canPrintData: myData] ) {
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [path lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = myData;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
//self.content = nil;
if (!completed && error) {
NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
}
};
[pic presentAnimated:YES completionHandler:completionHandler];
}
}
于 2013-01-24T02:17:40.287 回答