Open PDF file using swift

前端 未结 11 1984
萌比男神i
萌比男神i 2020-11-28 04:50

How can I add a PDF file for an app , where you click on a button to view the file & when you\'re done you get back to screen you were at?

11条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 05:20

    Check out PDFKit from IOS11

    Here is an example of a view controller which implements PDFView from PDFKit.

    import UIKit
    import PDFKit
    
    class ViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            // Add PDFView to view controller.
            let pdfView = PDFView(frame: self.view.bounds)
            self.view.addSubview(pdfView)
    
            // Fit content in PDFView.
            pdfView.autoScales = true
    
            // Load Sample.pdf file.
            let fileURL = Bundle.main.url(forResource: "Sample", withExtension: "pdf")
            pdfView.document = PDFDocument(url: fileURL!)
        }
    
    }
    

提交回复
热议问题