开发者

ios save web page as pdf

Can someone point me in the right direction for saving a webpage as a pdf? I already have a library for an iOS pdf reader, but I need to somehow imple开发者_开发技巧ment a feature for saving whatever webpage the user is viewing as pdf. I am assuming I would have to use an in-app browser. Any thoughts?


This is not something that I have done, but it seems you are not the first to want to do something like this.

http://www.iphonedevsdk.com/forum/iphone-sdk-development/21451-save-contents-uiwebview-pdf-file.html

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];

Chances are pretty good that you will have to tweak this but, hopefully this helps you move in the right direction.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜