2014-09-26 5 views
2

로컬 PDF 파일을 인쇄하는 Objective-C 인쇄 루틴이 있습니다.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]; 

    } 

} 

답변

4

올바른 방향을 지적해야합니다. 링크를 따라 가면 무엇을하는지 알 수 있습니다.

@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) 
    } 
} 

http://nshipster.com/uiprintinteractioncontroller/

에서 촬영