I am using swift, i need to take print of a sheet which is opened in UIWebView.
let url = webView.request?.url
let stringurl = url?.absoluteString
let pic = UIPrintInteractionController.shared
let printInfo : UIPrintInfo = UIPrintInfo(dictionary: nil)
printInfo.outputType = UIPrintInfoOutputType.general
printInfo.jobName = stringurl!
pic.printInfo = printInfo
pic.printFormatter = webView.viewPrintFormatter()
pic.showsPageRange = false
pic.present(animated: true, completionHandler: nil)
Here is my solution:
in
UIWebViewDelegate
in functionwebViewDidFinishLoad
we need to "redirect"window.print
function to our native function that will take care of print:next step:
and final step inmplement
printContent()
function:And now when we will press
print
in webView (1st screenshot) we will see iOS native dialog (2nd screenshot):