我们正在使用以下代码以横向模式打印网页
func print(webView: WKWebView, useRenderer: Bool) {
let pic = UIPrintInteractionController.shared
if useRenderer {
let renderer = UIPrintPageRenderer()
renderer.addPrintFormatter(webView.viewPrintFormatter(), startingAtPageAt: 0)
pic.printPageRenderer = renderer
} else {
pic.printFormatter = webView.viewPrintFormatter()
}
let printInfo = UIPrintInfo.printInfo()
printInfo.orientation = .landscape
pic.printInfo = printInfo
pic.present(animated: true) { (controller, success, error) in
}
}
使用上述代码,有时我们会在UIPrintInteractionController
中获得空白的打印预览,
据我了解,我们可以通过两种方式使用UIPrintInteractionController, 1.使用渲染器 2.使用打印格式程序
两种方法都提供相同的空白预览
示例代码:https://github.com/vinu-vanjari/landscape-air-print-bug
PS:尝试打印-如果您第一次看不到空白预览,请取消多次