【问题标题】:How do I view a PDF file saved in my document directory using Swift? [closed]如何使用 Swift 查看保存在我的文档目录中的 PDF 文件? [关闭]
【发布时间】:2020-08-30 12:33:37
【问题描述】:

我已经构建了一个订购应用程序并将订单表编码为保存到文档目录的 PDF。

我希望有一种方法可以在将 PDF 作为电子邮件发送之前预览它,并希望有人可以就如何加载/预览 PDF 以及如何使用UIViewController 发送它给我一些建议。

【问题讨论】:

    标签: swift pdf uiviewcontroller


    【解决方案1】:

    您可以使用 PDFKit.amazing 工具查看 PDF https://developer.apple.com/documentation/pdfkit

    import PDFKit
    
    class TextPreviewController: BaseController {
        
        @IBOutlet weak private var pdfView: PDFView!
        
        override func viewDidLoad() {
            super.viewDidLoad()
            setupView()
        }
        
        private func setupView() {
            let fm = FileManager.default
        let docsurl = try! fm.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
        let myurl = docsurl.appendingPathComponent("Owl.jpg")
        guard let path = myurl,
            let pdfDocument = PDFDocument(url: URL(fileURLWithPath: path))else { return }
        pdfView.displayMode = .singlePageContinuous
        pdfView.autoScales = true
        pdfView.displayDirection = .vertical
        pdfView.document = pdfDocument
        }
                
    }
    

    您只需将链接放在 PDF 上,它就会打开。

    【讨论】:

    • 非常感谢。愚蠢的问题我如何在pdf上放置链接?抱歉,我是新手,感谢您的帮助
    • 你知道手机上保存的文件夹和文件名吗? (您可以在尝试将文件保存在手机内存中的代码中找到它)
    • 我编辑了代码。你需要在你的喜欢(“Hello.pdf”)上放一个文件名(而不是“Owl.jpg”)
    • 太好了,我确实有设备的地址。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    • 2016-06-24
    • 2010-09-10
    • 2014-09-10
    • 1970-01-01
    • 2018-07-24
    • 1970-01-01
    相关资源
    最近更新 更多