0

In my app users can save web pages as PDF files on a TableView. Now how to open PDF file after clicking on a cell? The following codes is just I started with if let. You can advise your way to do it if it is different. Thanks.

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    if let pdfToOpen = NSUserDefaults.standardUserDefaults().objectForKey("pdfSaved") as? NSData {

}
Rajan Maheshwari
  • 14,465
  • 6
  • 64
  • 98
Mike
  • 37
  • 1
  • 9

1 Answers1

0

you can use webview to show pdf data like,

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

pass your data which you get from nsuserdefault in place of pdfContent.

it's objective c code convert this line in swift.

In swift something like,

func loadData(_ data: NSData,
    MIMEType MIMEType: String,
   textEncodingName textEncodingName: String,
     baseURL baseURL: NSURL)

if you want to open from url then,

let url : NSURL! = NSURL(string: "http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWebView_Class/UIWebView_Class.pdf")
webView.loadRequest(NSURLRequest(URL: url))

hope this will help :)

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75