Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Swift打印本地PDF_Swift_Pdf_Ios8 - Fatal编程技术网

使用Swift打印本地PDF

使用Swift打印本地PDF,swift,pdf,ios8,Swift,Pdf,Ios8,我在Objective-C中有一个打印例程,用于打印本地PDF文件 我希望在Swift中使用相同的程序。有人能帮忙吗 - (void)printFile:(NSURL *)url { if ([UIPrintInteractionController .canPrintURL(url]) { UIPrintInteractionController * controller = [UIPrintInteractionController

我在Objective-C中有一个打印例程,用于打印本地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];

    }

}

这将为您指明正确的方向,按照链接了解它的作用

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

摘自swift 4.2的更新

@IBAction func printAction(_ sender: UIButton) {
        if let guide_url = Bundle.main.url(forResource: "RandomPDF", withExtension: "pdf"){
            if UIPrintInteractionController.canPrint(guide_url) {
                let printInfo = UIPrintInfo(dictionary: nil)
                printInfo.jobName = guide_url.lastPathComponent
                printInfo.outputType = .photo

                let printController = UIPrintInteractionController.shared
                printController.printInfo = printInfo
                printController.showsNumberOfCopies = false

                printController.printingItem = guide_url

                printController.present(animated: true, completionHandler: nil)
            }
        }
    }