Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display NSData with PDF content in iOS UIWebView?

I am trying to show a PDF in my iPad application through UIWebView as shown below.

NSData * responseData = [NSURLConnection sendSynchronousRequest:mutableUrlRequest returningResponse:nil error:nil];
[pdfWebView loadData:responseData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil]; 

But this doesn't work. Is it a right way to display? If not could anyone guide me in showing the PDF in UIWebView or any other useful method.

Thanks !

like image 584
Easwaramoorthy K Avatar asked Jun 06 '13 16:06

Easwaramoorthy K


People also ask

What is UIWebView used for in iOS?

For information about basic view behaviors, see View Programming Guide for iOS. In addition to HTML content, UIWebView objects can be used to display other content types, such as Keynote, PDF, and Pages documents. For the best rendering of plain and rich text in your app, however, you should use UITextView instead.

Can I debug a UIWebView with Web Inspector?

If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled. You can debug the HTML, CSS, and JavaScript contained inside a UIWebView with Web Inspector. Read Debugging Web Content on iOS to learn how to configure Web Inspector for iOS.

How do I track the loading of web content in UIScrollView?

Set the delegate property to an object conforming to the UIWebViewDelegate protocol if you want to track the loading of web content. You shouldn’t embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.

Can I embed UITableView in UIScrollView?

You shouldn’t embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled. You can debug the HTML, CSS, and JavaScript contained inside a UIWebView with Web Inspector.


1 Answers

Got the answer for my question. The below line will do the magic.

 [webview loadData:PdfContent MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
like image 142
Easwaramoorthy K Avatar answered Sep 24 '22 05:09

Easwaramoorthy K