In one of my views, I simply want to show a pdf file in a UIWebView.
My code of the header file:
#import <UIKit/UIKit.h>
@interface FCOMViewController : UIViewController
{IBOutlet UIWebView *fcomWebView;}
//flag to denote if this is first time the app is run
@property (nonatomic) BOOL firstRun;
@end
And here the method in the implementation file:
- (void)viewDidLoad {
//Show the procedures PDF
NSString *path = [[NSBundle mainBundle] pathForResource:@"b777normalprocedures" ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[fcomWebView loadRequest:request];
[fcomWebView setScalesPageToFit:YES];
The app starts fine, does not crash or anything. The referencing outlets are set, but it doesn't show the PDF. Console says:
DiskImageCache: Could not resolve the absolute path of the old directory. failed to find PDF header: `%PDF' not found.
The pdf is in the project directory, I have double checked that it is written correctly.
What can I do here? Any help would be appreciated.
Try this if you are targeting iOS 8.0:
NSString *path = [[NSBundle mainBundle] pathForResource:@"b777normalprocedures" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:targetURL];
[_webView loadData:pdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With