tags:

views:

1025

answers:

1

Hi, experts

Can any we open the pdf file from UIWebView ?

if any one has implement this then plz help me...

any code snippet or any weblink help...

thanks in advance...

+8  A: 

Yes, this can be done with the UIWebView.

If you are trying to display a PDF file residing on a server somewhere, you can simple load it to your web view directly:

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];

NSURL *targetURL = [NSURL URLWithString:@"http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWebView_Class/UIWebView_Class.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];

[self.view addSubview:webView];
[webView release];

Or if you have a PDF file bundled with your application (in this example named "document.pdf"):

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];

NSString *path = [[NSBundle mainBundle] pathForResource:@"document" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];

[self.view addSubview:webView];
[webView release];

You can find more information here: Technical QA1630: Using UIWebView to display select document types.

alleus
thanks a lot...alleus. can we save it in local document directory in iPhone ?
yakub_moriss
Yes, it's possible, but you have to use another method of fetching the document other than a WebView. Search for it here on Stack Overflow. For example: http://stackoverflow.com/questions/2102267/downloading-a-file-from-url-and-saving-to-resources-on-iphone
alleus