Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDFview scrolls to bottom of the page in single page document

I am creating a PDFViewer application. I have set the autoScale Property of the PDFViewer to true, so that it the view expands to the width of the screen. Works fine with large PDF documents. But when the document is a single page document, the page automatically scrolls down to the end of the page, instead of starting with the beginning. I just cant understand the root cause of it. What am I missing here?

like image 543
Adwait Avatar asked Nov 26 '14 11:11

Adwait


3 Answers

I think this is a bug in PDFView.

As workaround I suggest to manually scroll top the top:

self.pdfView.document = pdfDocument;

NSPoint pt = NSMakePoint(0.0, [self.pdfView.documentView bounds].size.height);
[self.pdfView.documentView scrollPoint:pt];

Bug Reporter

rdar://37942090: PDFview scrolls to bottom of the page in single page document.

like image 168
catlan Avatar answered Nov 09 '22 19:11

catlan


I propose this solution for scrolling to top of first page (it works on iOS 11.3):

if let document = pdfView.document,
   let firstPage = document.page(at: 0)
{
    let firstPageBounds = firstPage.bounds(for: pdfView.displayBox)
    pdfView.go(to: CGRect(x: 0, y: firstPageBounds.height, width: 1.0, height: 1.0), on: firstPage)
}
like image 41
Petro Novosad Avatar answered Nov 09 '22 18:11

Petro Novosad


This is what I did, it's a bit hacky

if let scrollView = pdfView.subviews.first as? UIScrollView {
    scrollView.contentOffset.y = 0.0
}
like image 8
Aaron Halvorsen Avatar answered Nov 09 '22 17:11

Aaron Halvorsen