0

Looking for an example to capture the contents of a UIWebView to a image file, all in the background. Most likely the UIWebView will be hidden or framed off the main window so the user never sees this happening.

Thanks in advance!

Rob

paulrehkugler
  • 3,241
  • 24
  • 45
Rob Bonner
  • 9,276
  • 8
  • 35
  • 55
  • This SO answer is exactly what you're looking for. http://stackoverflow.com/a/2454622/953105 – paulrehkugler May 01 '13 at 14:43
  • possible duplicate of [Get a PDF/PNG as output from a UIWebView or UIView](http://stackoverflow.com/questions/2454309/get-a-pdf-png-as-output-from-a-uiwebview-or-uiview) – rob mayoff May 01 '13 at 14:44

1 Answers1

0

The following code will capture the content of the webview and that will be saved as a .png file

    UIGraphicsBeginImageContext(webview.bounds.size);
    [webview.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    // Write image to PNG
    NSString  *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
    [UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
Thilina Chamath Hewagama
  • 9,039
  • 3
  • 32
  • 45