2011-08-15 136 views
4

有人能指出我正确的方向将网页保存为pdf吗?我已经有一个用于iOS PDF阅读器的库,但我需要以某种方式实现一项功能,以便将用户正在查看的任何网页保存为PDF。我假设我将不得不使用应用内浏览器。有什么想法吗?ios将网页另存为PDF

回答

3

这不是我所做的事情,但似乎你不是第一个想做这样的事情。

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

最后的后在这个环节上提供的代码一个UIWebView保存为图像,你应该能够到的图像转换成PDF。我不邀功,因为我没有把它写的代码,只需连接你俩:)

下面是简单的代码:

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

机会是非常好的,你将不得不调整这但是,希望这可以帮助你朝着正确的方向前进。