简体   繁体   English

uiwebview的高分辨率屏幕截图/或pdf

[英]high resolution screenshot / or pdf from uiwebview

I want to save a screenshot or generate a pdf from UIWebView text content. 我想保存屏幕截图或从UIWebView文本内容生成pdf。 I know about how to make screenshots like described in: 我知道如何制作如下所述的屏幕截图:

http://developer.apple.com/library/ios/#qa/qa2010/qa1703.html http://developer.apple.com/library/ios/#qa/qa2010/qa1703.html

The thing is I'd like to have the screenshot in 300dpi. 事情是我想要300dpi的屏幕截图。 It is a fixed requirement to generate the content in a UIWebView. 在UIWebView中生成内容是固定的要求。

I thought about generating touches for zooming into the UIWebView, make several screenshots at a high zoom and stitch them together. 我考虑过要生成用于放大UIWebView的触摸,以高缩放比例制作几个屏幕截图并将它们拼接在一起。

Does anyone have a more elegant solution? 有谁有一个更优雅的解决方案?

Thanks b00tsy 谢谢b00tsy

The thing is I'd like to have the screenshot in 300dpi. 事情是我想要300dpi的屏幕截图。 It is a fixed requirement to generate the content in a UIWebView. 在UIWebView中生成内容是固定的要求。

I'm not sure this can easily be done. 我不确定这是否可以轻松完成。

UIWebView uses WebKit. UIWebView使用WebKit。 It appears to render to tiles in the background and seems to do some pre-rendering, but if you scroll quickly you can sometimes see tiles which weren't rendered soon enough. 它似乎在背景中渲染为图块,并且似乎进行了一些预渲染,但是如果快速滚动,有时会看到未足够快渲染的图块。 There's no easy way to know when WebKit has finished rendering the page. 没有简单的方法知道WebKit何时完成页面渲染。

The least ugly way might be to generate a larger-than-fullscreen UIWebView and render its layer. 最丑陋的方法可能是生成大于全屏的UIWebView并渲染其图层。 Setting scalesPageToFit = YES might help. 设置scalesPageToFit = YES可能会有所帮助。

Also note that UIWebView takes the screen resolution into account while rendering (ie it does high-res rendering on iPhone 4). 还要注意,UIWebView在渲染时会考虑屏幕分辨率(即,在iPhone 4上进行高分辨率渲染)。 This means that you'll get better results on iPhone 4/iPod Touch 4g. 这意味着您可以在iPhone 4 / iPod Touch 4g上获得更好的效果。 This also means that you might be able to "trick" UIWebView into thinking that the screen is higher-res than it really is (you might have success with setting webView.layer.contentsScale on OS 4.0+). 这也意味着您可能可以“欺骗” UIWebView以使其认为屏幕的分辨率高于实际分辨率(在OS 4.0+上设置webView.layer.contentsScale可能会成功)。

(And FWIW, "300 dpi" is a vague requirement — the "retina display" exceeds 300 ppi.) (而FWIW,“ 300 dpi”是一个模糊的要求-“视网膜显示”超过300 ppi。)

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

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