PDF View Scrolling

I'm having an issue with the displaying a PDF using hte new PDFKit Beta for ios 11 beta. When loading the pdf in PDF view, the PDF displays. However, about the top inch of the page is clipped. I can touch the view and pull down to scroll the pdf so that I can see the top inch of of the PDF. I can't seem to find a way to make PDFView scroll and display the top when the pdf is originaly loaded. Am I missing something? Here is my code, which is based on the PDFAnnotationAnnotationWidgetsAdvanced.


if let documentURL = Bundle.main.url(forResource: "Acupuncture Intake", withExtension: "pdf"),

let document = PDFDocument(url: documentURL),

let pg = document.page(at: 0) {

pdfView?.document = pg.document

pdfView?.autoScales = true

pdfView?.backgroundColor = UIColor.lightGray

pdfView?.displaysPageBreaks = true;

pdfView?.displayMode = .singlePage

}

@mykewithay did you ever figure this out? I'm having the same problem...

This problem still persists in 2022. For an incomplete solution, we can set the document after viewDidAppear.

private var isFirstAppear = true

if isFirstAppear {
    isFirstAppear = false

    if let documentURL = Bundle.main.url(forResource: "Acupuncture Intake", withExtension: "pdf"),
        let document = PDFDocument(url: documentURL),
        let pg = document.page(at: 0) {
            pdfView?.document = pg.document
            pdfView?.autoScales = true
            pdfView?.backgroundColor = UIColor.lightGray
            pdfView?.displaysPageBreaks = true;
            pdfView?.displayMode = .singlePage
    }
}

The downside is that there will be a brief moment when the pdf view is empty until the document is set.

After some digging, I noticed that it's due to the pdf.scaleFactorForSizeToFit changes after viewDidAppear. That gives us two incomplete workarounds. Solution1. Save the pdf.scaleFactor after viewDidAppear and apply it from then on. So the display can be normal for the second time and so forth. Solution2. Disable autoScale and set pdf.scaleFactor = pdf.scaleFactorForSizeToFit manually. The downside is that the scale won't be perfect.

PDF View Scrolling
 
 
Q