使用Swift打印本地PDF
发布时间:2020-12-14 04:39:23 所属栏目:百科 来源:网络整理
导读:我在Objective-C中有一个打印例程,用于打印本地PDF文件. 我想在Swift中使用相同的例程.有人可以帮忙吗? - (void)printFile:(NSURL *)url { if ([UIPrintInteractionController .canPrintURL(url]) { UIPrintInteractionController * controller = [UIPrintI
|
我在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/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
