使用Swift打印本地PDF

问题描述:

我在Objective-C中打印了一个打印本地PDF文件的例程。使用Swift打印本地PDF

我想在Swift中得到相同的例程。谁能帮忙?

- (void)printFile:(NSURL *)url { 

    if ([UIPrintInteractionController .canPrintURL(url]) { 

     UIPrintInteractionController * 
      controller = [UIPrintInteractionController 
      sharedPrintController()]; 

     controller.printingItem = url; 

     UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 
     PrintInfo.outputType = UIPrintInfoOutputGeneral; 
     PrintInfo.jobName = [url lastPathComponent]; 
     controller.printInfo = printInfo; 

     controller.showPageRange = YES; 

     [controller presentAnimated:YES completionHandler:Null]; 

    } 

} 

这应该指出你在正确的方向,请点击链接以了解它的作用。从http://nshipster.com/uiprintinteractioncontroller/

采取

@IBAction func print(sender: UIBarButtonItem) { 
    if UIPrintInteractionController.canPrintURL(imageURL) { 
    let printInfo = UIPrintInfo(dictionary: nil) 
    printInfo.jobName = imageURL.lastPathComponent 
    printInfo.outputType = .Photo 

    let printController = UIPrintInteractionController.sharedPrintController()! 
    printController.printInfo = printInfo 
    printController.showsNumberOfCopies = false 

    printController.printingItem = imageURL 

    printController.presentAnimated(true, completionHandler: nil) 
    } 
}