ios将网页保存为pdf [英] ios save web page as pdf

查看:196
本文介绍了ios将网页保存为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能指出我将网页另存为pdf的正确方向吗?我已经有一个iOS pdf阅读器库,但我需要以某种方式实现一个功能,以保存用户正在查看的任何网页为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 implement 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

此链接的最后一篇文章提供了将UIWebView保存为图像的代码,您应该能够将该图像转换为PDF。我没有把它归功于代码,因为我没有写它,只是连接你两个:)

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 :)

这是简单的代码:

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.

这篇关于ios将网页保存为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆