Ios AirPrint:将pdf文件直接打印到打印机
我想直接将pdf文件(iOS 8.1,AirPrint,Swift)打印到打印机上。打印很好,但我在Xcode中收到了以下消息: 2014-11-04 12:34:50.069打印应用[801:266564]-[PK纸质清单 匹配纸张:首选无边框:带双面打印模式:didMatch:] paperToMatch=结果= 匹配类型=0 这是什么意思 这是我的代码:Ios AirPrint:将pdf文件直接打印到打印机,ios,swift,airprint,Ios,Swift,Airprint,我想直接将pdf文件(iOS 8.1,AirPrint,Swift)打印到打印机上。打印很好,但我在Xcode中收到了以下消息: 2014-11-04 12:34:50.069打印应用[801:266564]-[PK纸质清单 匹配纸张:首选无边框:带双面打印模式:didMatch:] paperToMatch=结果= 匹配类型=0 这是什么意思 这是我的代码: let url: NSURL = NSURL(string:"http://www.sirup-shop.de/csv/test-pak
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.")
})
非常感谢您的帮助。我正在分享Objective-C代码,您可以将此作为参考
UIPrintInteractionController *pc = [UIPrintInteractionController
sharedPrintController];
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.orientation = UIPrintInfoOrientationPortrait;
printInfo.jobName =@"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];
这是基于客户答案的Swift版本
你可能需要看看这个答案:@holex:是的,我看到了这个答案。问题是他有一个printFormatter和一个printingItem。通过仅提供printFormatter解决了该问题。但是我只有printingItem。@Michael嗨,我们正在尝试在Flatter中直接打印pdf,这在iOS中允许吗?苹果会因为安全问题拒绝构建吗?@RuchiraMore,对不起,我对Flutter一无所知。
let printController = UIPrintInteractionController.shared
let printInfo = UIPrintInfo(dictionary: [:])
printInfo.outputType = UIPrintInfoOutputType.general
printInfo.orientation = UIPrintInfoOrientation.portrait
printInfo.jobName = "Sample"
printController.printInfo = printInfo
printController.showsPageRange = true
printController.printingItem = NSData(contentsOf: URL(string: "https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf")!)
printController.present(animated: true) { (controller, completed, error) in
if(!completed && error != nil){
NSLog("Print failed - %@", error!.localizedDescription)
}
else if(completed) {
NSLog("Print succeeded")
}
}