是否可以将iPhone上的html(uiwebview)转换为pdf或png?
我希望能够下载一个网页,然后将其保存为 pdf 或 png(或将其与所有 html、图像和 css 等文件一起保存在本地)。这样就可以在没有互联网连接的情况下查看该页面。有没有标准的方法来做到这一点?
I'd like to be able to download a web page and then save it as a pdf, or png (or save it locally with all the html, image and css etc files). This is so the page can be viewed without an internet connection. Is there a standard way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
恐怕完全缓存页面的唯一方法是:
即使如此,某些页面可能不会完全缓存,因为 javascript 可能需要其他地方的连接以提取数据。
如果你想截屏,可以使用一个私有API来截屏:
I am afraid the only way is to fully cache the page is to:
Even so, some pages may not be fully cached as javascript may require a connection elsewhere to pull data.
If you want to take a screenshot, there is a private API you can use to take a screenshot:
只要 UIWebView 位于活动窗口的视图层次结构中,它就会在屏幕外渲染。然后您可以将其渲染到 PNG 缓冲区。
缺点是它的尺寸不会比屏幕大,因此您只能以屏幕尺寸的增量拍摄页面。
更好的方法是按照 coneybeare 的建议进行操作并保存页面的代码和资源。
A UIWebView will render offscreen as long as it's in the view hierarchy of the active window. You can then render it to a PNG buffer.
The downside is that it won't size itself any larger than the screen, so you're limited to photographing the page in screen-sized increments.
The much better way is to do what coneybeare suggested and save the page's code and assets.
因此可以将文档导出到 Google 文档,然后将其以 PDF 格式下载回来。我想这里的重点是在不连接到网络的情况下执行此操作。
So can exporting a document to Google doc and then downloading it back as a PDF. I guess the point here is to do it without being connected to the network.