gpt4 book ai didi

ios - PDFKit 的 PDFDocument init(url : URL) does not work with HTTPS

转载 作者:可可西里 更新时间:2023-11-01 00:00:07 27 4
gpt4 key购买 nike

当我尝试使用 PDFDocument.init(url: ) 时,我注意到它适用于 http 但不适用于 https URL。有谁知道为什么吗?

import PDFKit

let httpURL = URL(string: "http://www.axmag.com/download/pdfurl-guide.pdf")!
let doc1 = PDFDocument(url: httpURL) //makes a PDFDocument

let httpsURL = URL(string: "https://www.gnu.org/s/libmicrohttpd/tutorial.pdf")!
let doc2 = PDFDocument(url: httpsURL) //nil

最佳答案

@IBOutlet var pdfView: PDFView!

var pdfDOC: PDFDocument!

override func viewDidLoad() {
super.viewDidLoad()
downloadPDF()
}

func downloadPDF(){
let urlString = "https://www.tutorialspoint.com/swift/swift_tutorial.pdf"
guard let url = URL(string: urlString) else {return}
do{
let data = try Data(contentsOf: url)
pdfDOC = PDFDocument(data: data)
pdfView.displayMode = .singlePageContinuous
pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
pdfView.displaysAsBook = true
pdfView.displayDirection = .vertical
pdfView.document = pdfDOC
pdfView.autoScales = true
pdfView.maxScaleFactor = 4.0
pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit
}catch let err{
print(err.localizedDescription)
}
}

关于ios - PDFKit 的 PDFDocument init(url : URL) does not work with HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45717813/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com