2015-01-03 3 views
0

Я пытаюсь распечатать PDF с URL-адреса в iOS. Я могу получить диалоговое окно печати, чтобы показать его, но работа завершилась неудачей с кодом ошибки 3. Является ли то, что я пытаюсь сделать возможным, или мне нужно сначала загрузить PDF?Как распечатать PDF в iOS?

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

Я сделал довольно тупую ошибку на этом. Я передавал URL как NSString вместо требуемого NSURL.

Смежные вопросы