从swift uiwebview打印

时间:2014-12-18 10:56:51

标签: ios swift printing uiwebview

我可以打印我的UIWebview内容,但是它打印在两个页面上,如何缩小它以适合一个页面?

我的代码:

@IBAction func printWebPage(sender: UIBarButtonItem) 
{
  let url = MainWebView.request?.URL
  let stringurl = url?.absoluteString

  let pic = UIPrintInteractionController.sharedPrintController()
  let printInfo : UIPrintInfo = UIPrintInfo(dictionary: nil)

  printInfo.outputType = UIPrintInfoOutputType.General
  printInfo.jobName = url  

  pic!.printInfo = printInfo
  pic!.printFormatter = MainWebView.viewPrintFormatter()
  pic!.showsPageRange = false

  pic!.presentAnimated(true, completionHandler: nil)
}

1 个答案:

答案 0 :(得分:3)

来自您的评论:

var webView = UIWebView()
let pic = UIPrintInteractionController.sharedPrintController()
let printInfo : UIPrintInfo = UIPrintInfo(dictionary: nil)

// General: Text, Graphics and images.
// Photo: Black and white or color images.
// PhotoGrayscale: Black and white and grayscale images
// Grayscale: Gray scale general. (Black and white)
printInfo.outputType = UIPrintInfoOutputType.General

pic!.printInfo = printInfo

pic!.printFormatter = webView.viewPrintFormatter()
pic!.showsPageRange = true

唯一缺少的是关闭,你必须自己开发(对不起!)