微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Swift打印本地PDF

我在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)
  }
}

取自http://nshipster.com/uiprintinteractioncontroller/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐