在iOS中将PDF转换为数据失败
我正在尝试在iOS应用程序中打开一个受密码保护的PDF。 为此,我使用在iOS中将PDF转换为数据失败,ios,wkwebview,ios-pdfkit,Ios,Wkwebview,Ios Pdfkit,我正在尝试在iOS应用程序中打开一个受密码保护的PDF。 为此,我使用PDFKit打开文档,解锁文档,然后尝试将文档转换为数据。这个数据然后可以在webview中加载,这就是我想要做的。 但是,在将文档转换为数据时,我发现加载失败错误,因此在webView中加载空白pdf func loadData() -> Data { let pdfView = PDFView(frame: self.view.bounds) let fileURL = Bundle.main.url(f
PDFKit
打开文档,解锁文档,然后尝试将文档转换为数据。这个数据
然后可以在webview中加载,这就是我想要做的。
但是,在将文档转换为数据
时,我发现加载失败
错误,因此在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
}