Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot open PDF file using UIWebView in iOS8beta5

I have working project in which i display pdf file in UIWebView
While testing my application in iOS8beta5 with XCode5, it did not work
In log it display failed to find PDF header : '%PDF' not found


I create sample application with below code which also have same problem
CODE :
self.myWebView.delegate = self;
NSString *path = [[NSBundle mainBundle] pathForResource:@"201" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[self.myWebView loadRequest:request];


I read release note, Apple wrote that Quicklook framework may did not display PDF file in some application but they did not mention any thing about UIWebView, enter image description here

Reference


NOTE :
This problem was not came in iOS8beta4.
Same problem is also occur in XCode6 + iOS8beta5.
I also check with different PDF files but have same problem.
QUESTION :
1] Is there any one had done fix for the above problem ?
If yes, please provide me some sample code.
like image 851
Jageen Avatar asked Aug 12 '14 05:08

Jageen


1 Answers

I found a workaround for viewing the PDF in WebView

// Create pdf path & url
NSString *path = [[NSBundle mainBundle] pathForResource:@"201" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];

// Load pdf in WebView
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:targetURL];
[self.webView loadData:pdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
like image 197
Jageen Avatar answered Oct 20 '22 19:10

Jageen