I have a PDFView that's set to use a pageViewController:
let pdfView = PDFView()
let pdfDoc = PDFDocument(url: Bundle.main.url(forResource: "test", withExtension: "pdf")!)
pdfView.document = pdfDoc
pdfView.autoScales = true
pdfView.displayDirection = .horizontal
pdfView.usePageViewController(true, withViewOptions: [:])
Whenever I swipe to get to the next page, said next page is blurry for half a second before it's rendered sharply. That is quite annoying. Can I somehow preload the pages? I haven't found any attributes/methods in the documentation.
(Interestingly, I have the exact same problem in Preview
on MacOS
when it's in fullscreen mode [since forever, on every mac I own])
It's not reliant on pdf (file) size. The problem occurs with every pdf I tried.
Thanks for any help
I think this is due to the high resolution of your PDF and the way PDFView renders PDF. Do you have more information on your PDF?
Could you try with a PDF with less heavy images? It should render fine. If so, it's not your code which is at fault, but the resources needed to display and render it to the view.
UPDATE
You can try using the PDFView without PageViewController and see you it behaves. You could do this:
pdfView = PDFView(frame: view.frame)
pdfView.backgroundColor = UIColor.white
var documentName: String = "test"
if let documentURL = Bundle.main.url(forResource: documentName, withExtension: "pdf") {
if let document = PDFDocument(url: documentURL) {
pdfView.autoScales = true
pdfView.displayDirection = .horizontal
pdfView.displayMode = .singlePageContinuous
pdfView.document = document
}
}
self.view.addSubview(pdfView)
Does it behave differently? I've notice that the option usePageViewController
loads the document faster for big PDF documents. Something to take into consideration when implementing.
I hope this helps
Please make sure to add values of .maxScaleFactor .minScaleFactor also as per your requirement and see if it makes any difference in the loading time. e.g.
.maxScaleFactor = 4.0;
.minScaleFactor = self.scaleFactorForSizeToFit;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With