我正在尝试从WKWebView打印.网页和图片工作正常.
这是我用来创建printController的代码:
let printController = UIPrintInteractionController.sharedPrintController() let printInfo = uiprintinfo(dictionary:nil) printInfo.outputType = uiprintinfoOutputType.General printInfo.jobName = urlField.text! printInfo.duplex = uiprintinfoDuplex.LongEdge let formatter: UIViewPrintFormatter = webView.viewPrintFormatter() formatter.contentInsets = UIEdgeInsets(top: 10,left: 10,bottom: 10,right: 10) printController.printFormatter = formatter printController.printInfo = printInfo printController.showsPageRange = true printController.showsNumberOfcopies = true printController.presentFromBarButtonItem(printButton,animated: true,completionHandler: nil)
有人能帮助我走向正确的方向吗?
有这个问题的解决方案吗?
解决方法
根据
documentation,您可以使用printingItem.
重要说明:在iPhone模拟器上有点滞后,看起来需要时间将pdf直接加载到Controller.
let printController = UIPrintInteractionController.sharedPrintController() let printInfo = uiprintinfo(dictionary:nil) printInfo.outputType = uiprintinfoOutputType.General printInfo.jobName = (webView.URL?.absoluteString)! printInfo.duplex = uiprintinfoDuplex.None printInfo.orientation = uiprintinfoOrientation.Portrait //New stuff printController.printPageRenderer = nil printController.printingItems = nil printController.printingItem = webView.URL! //New stuff printController.printInfo = printInfo printController.showsPageRange = true printController.showsNumberOfcopies = true printController.presentFromBarButtonItem(printButton,completionHandler: nil)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。