johnDoe
johnDoe

Reputation: 795

PDFKit - PDFThumbnailView skips a page instead of showing continuous pages - swift

I am able to present the PDFThumnailView of my pdf document. The problem is it is skipping pages. It shows pages 1,3,5 etc...and not displaying the pages in between. My code is below.

@IBOutlet weak var pdfView: PDFView!
@IBOutlet weak var pdfThumbnailView: PDFThumbnailView!

 func setupThumbnailView() {
    pdfThumbnailView.pdfView = pdfView
    pdfThumbnailView.thumbnailSize = CGSize.init(width: thumbnailDimension, height: thumbnailDimension)
    pdfThumbnailView.backgroundColor = sidebarBackgroundColor

}

Upvotes: 5

Views: 1704

Answers (2)

S.Basnagoda
S.Basnagoda

Reputation: 711

You have to make pdfThumbnailView bigger. However then it can be too big to fit on the screen, so let’s put it in a scroll view.

First make change the constraints on the pdfThumbnailView to make it wide enough to accomodate all the pages.

NSLayoutConstraint.activate([
    pdfThumbnailView.heightAnchor.constraint(equalToConstant: CGFloat(thumbnailSize)),
    pdfThumbnailView.widthAnchor.constraint(equalToConstant: CGFloat(pdfDocument.pageCount*thumbnailSize))
])

Next create the scroll view and add the thumbnail view as its only subview.

var pdfThumbnailScrollView = UIScrollView()
pdfThumbnailScrollView.translatesAutoresizingMaskIntoConstraints = false
pdfThumbnailScrollView.addSubview(pdfThumbnailView)

Finally add some constraints so the scroll view and the thumbnail view know how to lay themselves out. The scroll view only has one subview, so let's constrain it to fit.

NSLayoutConstraint.activate([
    pdfThumbnailView.leadingAnchor.constraint(equalTo: pdfThumbnailScrollView.leadingAnchor),
    pdfThumbnailView.trailingAnchor.constraint(equalTo: pdfThumbnailScrollView.trailingAnchor),
    pdfThumbnailView.topAnchor.constraint(equalTo: pdfThumbnailScrollView.topAnchor),
    pdfThumbnailView.bottomAnchor.constraint(equalTo: pdfThumbnailScrollView.bottomAnchor)
])

You may follow this tutorial more details.

Upvotes: 2

user3425784
user3425784

Reputation: 66

I might be wrong but I think this is the way that PDFThumbnailView works. It fits as many thumbnails as it can within the View width by not displaying some intermediate thumbnails. It does show them if you touch over the thumbnails. Make the width bigger or the thumbnails smaller and it shows more.

Upvotes: 2

Related Questions