简体   繁体   中英

How to set number of pages to print using UIPrintInteractionController.print in swift 3?

I'm using the UIPrintInteractionController to print a html from a UIWebView directly to an AirPrint printer. I would like to tell the UIPrinter that only the first page should be printed. How can I do this?

Here is my code which prints all pages:

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
 
}

The code should be compatible with iOS 9.0.

There is numberOfPages property in UIPrintPageRenderer that you can override. Or you may just set the UIPrintInteractionController property showsPageRange to true .

For more reference please use see this link - https://developer.apple.com/documentation/uikit/uiprintpagerenderer/1621631-numberofpages

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM