开发者

Displaying a PDF file into UIWebView

开发者 https://www.devze.com 2023-04-12 12:08 出处:网络
I want to display a pdf file in a UIWebView. My PDF is coming from a web service and I am able to store it in a documents directory successfully. But when I try to load the PDF url into my UIWebView,

I want to display a pdf file in a UIWebView. My PDF is coming from a web service and I am able to store it in a documents directory successfully. But when I try to load the PDF url into my UIWebView, it displays a blank webview. No errors are reported.

Does anyone have an idea as to what might be going wrong here开发者_如何学C or how I can better debug this problem?


NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//Considering your pdf is stored in documents directory with name as "pdfFileName"

NSString *pdfPath = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"mynewDocument.pdf"];
NSURL *url = [NSURL fileURLWithPath:pdfPath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];

Use debugger to check the contents of url. It should point to the exact pdf location. Also, You can use UIWebView's delegate methods:-

-(void)webViewDidFinishLoad:(UIWebView *)webView;
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
0

精彩评论

暂无评论...
验证码 换一张
取 消