Search code examples
objective-cfilepdfwebviewnsdata

Objective C Load PDF file in UIWebView


EDIT: There was something wrong with my Base64 decoding. I searched for a external Base64 decoder and it working just like this:

This is the case: I have a Base64 encoded byte array I get from a webservice and convert it to NSData:

NSData *data = [Base64 decodeBase64WithString:response];

And in my Webview Controller I declared:

[webview loadData:fileData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];

fileData is the decoded data.

When I run this I get a gray screen. So I assume I'm not giving it a correct NSData object.


Solution

  • I already answered my own question when I was typing it.

    So I assume I'm not giving it a correct NSData object.

    My Base64 decoding was wrong.

    Using this statement works like a charm:

    [webview loadData:fileData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
    

    I'm just posting so other people can look at it of they have the same problem.