如何在iOS中使用swift 5将pdf文件保存到本地?

红色独轮车

我正在使用 Swift 5 开发一个 iOS 应用程序,它将纯文本转换为 pdf 格式。我想与 Whatsapp 应用程序共享 pdf 文件,但我找不到之前如何保存 pdf 文件,然后找不到我用 Whatsapp 保存的文件的 url。我怎样才能做到这一点?

编辑:我正在将纯文本转换为 pdf 格式我手上有 pdf 数据,我想将其保存到本地并获取它的 url

菲利波·赞菲尼

您必须使用一个UIDocumentInteractionController.

var interactionController: UIDocumentInteractionController!

然后通过按钮(例如)您可以打开控制器。

@IBAction func savePDF(_ sender: Any) {      
     self.interactionController = UIDocumentInteractionController(url: "http://website.com/title.pdf")
     self.interactionController.delegate = self
     self.interactionController.presentOpenInMenu(from: button.frame, in: view, animated: true)
 }

更新:

    let title = "PDF Title"

    guard let outputURL = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent(title).appendingPathExtension("pdf")
            else { fatalError("URL not created") } // PDF url

    pdfData.write(to: outputURL, atomically: true) // pdfData is your PDF file

    self.interactionController = UIDocumentInteractionController(url: outputURL)
    self.interactionController.delegate = self
    self.interactionController.presentOpenInMenu(from: button.frame, in: view, animated: true)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何提示用户将pdf文件保存到Django的本地计算机中?

如何使用CURL将文件下载并保存到本地路径

将本地生成的PDF保存到iOS8中的应用程序的documents文件夹中

如何将svg canvas保存到本地文件系统

如何将Spark RDD保存到本地文件系统

如何将文件从postgreSQL保存到本地?

使用Java将Spark RDD保存到本地文件系统

如何通过浏览文件将PDF图像保存到XLSX?

如何将StringIO(pdf)数据保存到文件中

MarkLogic-如何将pdf保存到文件系统

如何将pdf文件保存到Google云端硬盘?

Swift 5:将复杂对象保存到文件存储

如何在 iOS 上的 Swift 3 中使用本地文件路径实例化 AVPlayer?

使用Powershell将md5哈希保存到文件

如何将在 Flutter 上查看的 pdf 文件保存到设备的本地存储?

在Swift中使用AVAssetWriter将AVCaptureVideoDataOutput保存到电影文件

如何将文件另存为 zip 而不将其保存到本地文件夹

如何使用java将Int8Array保存到本地文件

无法在ios swift中将文件保存到本地存储

如何将pdf保存到android文件系统然后查看PDF-react-native

如何在 Swift IOS 中使用 NSKeyedArchiver 保存带有子类的对象

如何将JSON保存到本地文本文件

我如何将日志/数据持久保存到Docker中的本地文件系统

我如何将数据从 android 游戏保存到本地 json 文件

如何在Swift 5和iOS 13中使用CIFilter sunbeamsGenerator?

如何在 ios Swift 5 Like ["£179.95", "£199.95", "£89.95"] 中使用多个欧元值总数组

如何在swift-ios文件中使用asl.h

iOS Swift如何在我的项目中使用Gif文件

使用Python和BeautifulSoup(将网页源代码保存到本地文件中)