在iOS中将PDF转换为数据失败

问题描述

我正在尝试在受密码保护的iOS应用中打开PDF。 为此,我使用PDFKit打开文档,解锁文档,然后尝试将文档转换为Data。然后可以在Webview中加载此Data,这是我要执行的操作。 但是,在将文档转换为Data时,出现Failed to load错误,因此在webView中加载了空白pdf。

 func loadData() -> Data
 {
  let pdfView = PDFView(frame: self.view.bounds)
  let fileURL = Bundle.main.url(forResource: "myDocument",withExtension: "pdf")
  var pdfData:Data?
  if let document = PDFDocument(url: fileURL!) {
    if(document.isLocked){
    document.unlock(withPassword: "0123")
    print("Unlocked successfully!")      //This is printed as expected
  }
   pdfData = document.dataRepresentation() // At this point I am getting -> [Unknown process name] Failed to load /System/Library/PrivateFrameworks/CorePDF.framework/Versions/A/CorePDF

}

func createWebView(withFrame frame: CGRect) -> WKWebView? {
  let webView = WKWebView(frame: frame)
  webView.autoresizingMask = [.flexibleWidth,.flexibleHeight]  
  let pdfdata =  loadData() //Called here.
  webView.load(pdfdata,mimeType: "application/pdf",characterEncodingName:"utf-8",baseURL: URL(fileURLWithPath: ""))
  return webView
  }
  
  return nil
 }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...