2014-11-04 39 views
1

我想直接將PDF文件(iOS 8.1,AirPrint,Swift)打印到打印機。印刷是優良的,但我得到在Xcode這樣一條消息:AirPrint:直接將PDF文件打印到打印機

2014年11月4日12:34:50.069 PrintApp [801:266564] - [PKPaperList matchedPaper:preferBorderless:withDuplexMode:didMatch:] paperToMatch =結果= matchType = 0

這是什麼意思?

這是我的代碼:

let url: NSURL = NSURL(string:"http://www.sirup-shop.de/csv/test-paketlabel.pdf")! 

let printInfo = UIPrintInfo(dictionary: nil) 
printInfo.jobName = "Label" 

let printController = UIPrintInteractionController.sharedPrintController()! 
printController.printingItem = url 
printController.printInfo = printInfo 
printController.delegate = self 
printController.printToPrinter(self.printer!, completionHandler: { 
    (controller:UIPrintInteractionController!, completed:Bool, error:NSError!) -> Void in 
    println("Label finished.") 
}) 

非常感謝您的幫助。

+0

您可能需要採取對答案一看:http://stackoverflow.com/a/24966715/1214122 – holex 2014-11-04 12:03:05

+0

@holex:是的,我看到了這個答案。問題在於他有一個printFormatter _和_一個printingItem。問題只通過提供printFormatter來解決。但我只有printingItem。 – Michael 2014-11-04 12:20:01

回答

0

我在分享Objective-C Code,你可以把它當作參考。

UIPrintInteractionController *pc = [UIPrintInteractionController 
            sharedPrintController]; 
UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 
printInfo.outputType = UIPrintInfoOutputGeneral; 
printInfo.orientation = UIPrintInfoOrientationPortrait; 
printInfo.jobName [email protected]"Report"; 

pc.printInfo = printInfo; 
pc.showsPageRange = YES; 
pc.printingItem = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://test.com/Print_for_Client_Name.pdf"]]; 


UIPrintInteractionCompletionHandler completionHandler = 
^(UIPrintInteractionController *printController, BOOL completed, 
    NSError *error) { 
    if(!completed && error){ 
     NSLog(@"Print failed - domain: %@ error code %ld", error.domain, 
       (long)error.code); 
    } 
}; 


[pc presentFromRect:CGRectMake(0, 0, 300, 300) inView:self.view animated:YES completionHandler:completionHandler];