views:

465

answers:

3

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?

+1  A: 

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
coneybeare
A: 

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.

Marco
A: 

Our tool can take web pages and return PDFs - give it a try at http://fourpdf.com/

If you're after enabling a particular domain, it should do the job nicely. If you're looking to convert pages from multiple sites, that isn't the model we've developed just yet, but we're considering a tool to allow you to view pages from multiple places in a pdf - let me know if that would be of interest - there's a contact form on the site.

Regards, Jake.

Jake Liddell