7

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.
Jageen
  • 6,345
  • 2
  • 37
  • 56

1 Answers1

11

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];
Jageen
  • 6,345
  • 2
  • 37
  • 56
  • My problem is that the PDF file I store in the app doesn't get to the iPad. I used to be able to just drop the file in the app folder and access it from there. Now I can't see it anymore in the file hierarchy on the device. – Jorgen Sep 22 '14 at 16:12
  • 1
    @joger i think you question is different, ask it as new question or search with similar question is stackoverflow, and also provide information like, OS you are using and is the same problem occur in by sing other XCodes and iOS versions. – Jageen Sep 23 '14 at 03:44