PDFKit - PDFView using pageViewController - page rendering slow when swiping to next page

情到浓时终转凉″ 提交于 2019-12-05 03:28:05

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;

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

Did you try to change the interpolationQuality option ?

The interpolation quality for images drawn into the PDFView context.

Possible values are

  • none
  • low
  • high

Maybe you could try something like

pdfView.interpolationQuality = .low

or

pdfView.interpolationQuality = .none
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!