开发者

Is it possible to convert html (uiwebview) on the iphone into pdfs, or pngs?

I'd like to be able to download a web page and then sav开发者_开发问答e 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?


I am afraid the only way is to fully cache the page is to:

  1. Save the HTML to file
  2. Step through the file and save any linked resources (images, stylesheets, javascript)

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:

CGImageRef UIGetScreenImage();
@interface UIImage (ScreenImage)
+ (UIImage *)imageWithScreenContents;
@end

@implementation UIImage (ScreenImage)
+ (UIImage *)imageWithScreenContents
{
    CGImageRef cgScreen = UIGetScreenImage();
    if (cgScreen) {
        UIImage *result = [UIImage imageWithCGImage:cgScreen];
        CGImageRelease(cgScreen);
        return result;
    }
    return nil;
}
@end


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜