【问题标题】:How to set number of pages to print using UIPrintInteractionController.print in swift 3?如何在 swift 3 中使用 UIPrintInteractionController.print 设置要打印的页数?
【发布时间】:2017-10-19 10:31:43
【问题描述】:

我正在使用UIPrintInteractionControllerUIWebView 中的html 直接打印到AirPrint 打印机。我想告诉UIPrinter,只打印第一页。我该怎么做?

这是我打印所有页面的代码:

let printer = UIPrinter(url: myURL)
let printerController = UIPrintInteractionController.shared

let printInfo = UIPrintInfo(dictionary: nil)
printInfo.jobName = "My print job name"
printInfo.outputType = .general
printerController.printInfo = printInfo

let printPageRenderer = MyCustomPageRenderer()
printPageRenderer.addPrintFormatter(myWebView.viewPrintFormatter(), startingAtPageAt: 0)

printerController.printPageRenderer = printPageRenderer
printerController.print(to: printer!) { (printerController, success, error) in
 
}

代码应兼容 iOS 9.0。

【问题讨论】:

    标签: ios swift swift3


    【解决方案1】:

    您可以覆盖 UIPrintPageRenderer 中的 numberOfPages 属性。或者您可以将 UIPrintInteractionController 属性 showsPageRange 设置为 true

    如需更多参考,请使用此链接 - https://developer.apple.com/documentation/uikit/uiprintpagerenderer/1621631-numberofpages

    【讨论】:

    • 是的,但是使用打印方法我避免了对话框,所以在这种情况下该属性是无用的,对吧?
    猜你喜欢
    • 2017-02-07
    • 1970-01-01
    • 2013-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    相关资源
    最近更新 更多