web content转image

来源:互联网 发布:干支纪日法简便算法 编辑:程序博客网 时间:2024/05/22 03:07

The last post in this link provides code to save a UIWebView as an image, and you should be able to convert that image into a PDF. I don't take credit for the code as I did not write it, just connecting you two :)

Here is the code for simplicity:

CGSize sixzevid=CGSizeMake(1024,1100);UIGraphicsBeginImageContext(sixzevid);[webview.layer renderInContext:UIGraphicsGetCurrentContext()];UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();NSData *imageData = UIImagePNGRepresentation(viewImage);NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *pathFloder = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@",@"new.png"]];NSString *defaultDBPath = [documentsDirectory stringByAppendingPathComponent:pathFloder];[imageData writeToFile:defaultDBPath atomically:YES];
利用原先的连续image转到pdf的代码,即可实现把网页 存为pdf的方式。
原创粉丝点击