我试图从iOS中的网址打印PDF。我可以显示打印对话框,但是作业失败并显示错误代码3.我尝试了什么,或者我是否必须先下载PDF?
printUrl
-(void) printUrl:(NSString *)url
{
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.delegate = self;
NSLog(@"Printing from URL: %@", url);
if ([UIPrintInteractionController canPrintURL:[[NSURL alloc] initWithString:url]]) {
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [url lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = url;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
//self.content = nil;
NSLog(@"Print job %@", (completed ? @"completed" : @"didn't complete"));
if (error) {
NSLog(@"FAILED! due to error in domain %@ with error code %ld", error.domain, (long)error.code);
}
};
[pic presentAnimated:YES completionHandler:completionHandler];
} else {
NSLog(@"Can't print specified URL");
}
}
记录输出
<Warning>: Printing from url: http://www.energy.umich.edu/sites/default/files/pdf-sample.pdf
<Warning>: Can print: Yes
<Warning>: -[PKPaperList matchedPaper:preferBorderless:withDuplexMode:didMatch:] paperToMatch=<PKPaper: 0x187e4320> result=<PKPaper: 0x187d9ba0> matchType=0
<Warning>: Print job completed
<Warning>: FAILED! due to error in domain UIPrintErrorDomain with error code 3
答案 0 :(得分:0)
我在这个问题上犯了一个非常愚蠢的错误。我将URL作为NSString传递而不是所需的NSURL。