Paresh Karnawat
Paresh Karnawat

Reputation: 312

Displaying a PDF file into UIWebView

I want to display a pdf file in a UIWebView. My PDF is coming from a web service and I am able to store it in a documents directory successfully. But when I try to load the PDF url into my UIWebView, it displays a blank webview. No errors are reported.

Does anyone have an idea as to what might be going wrong here or how I can better debug this problem?

Upvotes: 0

Views: 4251

Answers (1)

Shri
Shri

Reputation: 2139

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//Considering your pdf is stored in documents directory with name as "pdfFileName"

NSString *pdfPath = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"mynewDocument.pdf"];
NSURL *url = [NSURL fileURLWithPath:pdfPath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];

Use debugger to check the contents of url. It should point to the exact pdf location. Also, You can use UIWebView's delegate methods:-

-(void)webViewDidFinishLoad:(UIWebView *)webView;
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;

Upvotes: 1

Related Questions