Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

failed to find PDF header: `%PDF' not found

I get this log when i try to load a pdf and don't know why.

failed to find PDF header: `%PDF' not found.

hers my code:

- (void)viewDidLoad
{


    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://webdesign-schoenefeld.de/es-app/heute.pdf"]]];
    NSLog(@"---------------pdfloading....,------------------------");
    [webview addSubview:activityind];
    timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0)
                                             target:self
                                           selector:@selector(loading)
                                           userInfo:nil
                                            repeats:YES];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

}

I use Xcode 6 Beta 5 and iOS 8 beta 5.

Thanks for your help.

like image 855
Marius Schönefeld Avatar asked Aug 06 '14 10:08

Marius Schönefeld


2 Answers

I agree, there seems to be a bug (or change of behaviour) in iOS 8 beta 5 which means that your code does not work anymore (and it was valid. I have the same and it worked fine up to iOS 8 beta 4).

I think there is a problem with type detection because if I do the following, it works:

NSLog(@"About to request PDF document loading...");
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:urlStr]];
[self.webView loadData:pdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];

Now that bit of code should not be used "as is" as it is synchronous.

I feel Nithin's answer was valid but it does not answer the problem specifically seen with iOS 8 beta 5. The main code is the same and will hit the same iOS bug.

like image 110
Gilles Avatar answered Sep 16 '22 19:09

Gilles


This worked for me 👊👍

NSURL *targetURL = [NSURL fileURLWithPath:pdfFilePath]; // <pdfFilePath> if full path of your pdf file
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:targetURL];
[self.webview loadData:pdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
like image 24
Vaibhav Saran Avatar answered Sep 18 '22 19:09

Vaibhav Saran