Search code examples
iphonehtmlobjective-ciosipad

converting html to image in ios


I am using multiple .html files in my app and opens it in a webview , i need to show the html pages as a thumb view as well , is it possible to convert the html pages into images or any other methods to show the html files as a preview. Please help me if any one know


Solution

  • -(void) webViewDidFinishLoad:(UIWebView *)webView { 
    
    UIGraphicsBeginImageContext(CGSizeMake(webView.layer.frame.size.width, webView.layer.frame.size.height));
    [webView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    
    UIGraphicsBeginImageContext(CGSizeMake(70,100));
    [image drawInRect:CGRectMake(0, 0, 70,100)];
    image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    //image is now a 70x100 thumbnail. make sure you include CoreGraphics
    }