简体   繁体   English

如何在 swift 3 中使用 UIPrintInteractionController.print 设置要打印的页数?

[英]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.我正在使用UIPrintInteractionController将 html 从UIWebView直接打印到 AirPrint 打印机。 I would like to tell the UIPrinter that only the first page should be printed.我想告诉UIPrinter应该只打印第一页。 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.该代码应与 iOS 9.0 兼容。

There is numberOfPages property in UIPrintPageRenderer that you can override.您可以覆盖UIPrintPageRenderer中的numberOfPages属性。 Or you may just set the UIPrintInteractionController property showsPageRange to true .或者您可以将UIPrintInteractionController属性showsPageRange设置为true

For more reference please use see this link - https://developer.apple.com/documentation/uikit/uiprintpagerenderer/1621631-numberofpages如需更多参考,请使用此链接 - https://developer.apple.com/documentation/uikit/uiprintpagerenderer/1621631-numberofpages

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们如何设置打印尺寸UIPrintInteractionController - How can we set print size UIPrintInteractionController 如何使用uiprintinteractioncontroller类打印Word文档 - How to Print Word Documents Using uiprintinteractioncontroller class 使用UIPrintInteractionController打印图像和文本 - Print image and text using UIPrintInteractionController 使用AirPrint打印锁定的pdf时如何将密码传递给UIPrintInteractionController? - How to pass a password to UIPrintInteractionController when using AirPrint to print a locked pdf? UIPrintInteractionController - 限制打印副本/获取打印副本数量 - UIPrintInteractionController - Limit print copies / Get number of printed copies iOS打印不允许出现UIPrintInteractionController - iOS print without allowing UIPrintInteractionController to appear 如何使用 Swift 打印 DynamoDB 查询结果 - How Print DynamoDB Query Results Using Swift 使用UIPrintInteractionController打印完整的A4纸需要什么图像尺寸? - What image size need to print a full A4 paper with UIPrintInteractionController? Swift中的CocoaLumberjack,如何打印行号和filne名称 - CocoaLumberjack in Swift, how to print line number and filne name 如何打印轨道数据(swift) - how to print track data (swift)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM