 
 extension PDFSinglePageViewer: UICollectionViewDelegateFlowLayout {
     public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
-        
-        let flowLayout = collectionViewLayout as! UICollectionViewFlowLayout
-        switch flowLayout.scrollDirection {
+        switch scrollDirection {
         case .horizontal:
             var size = bounds.size
             let contentInsetHeight = contentInset.bottom + contentInset.top + 1

    }
    
    private func didDisplayPage(_ scrollView: UIScrollView) {
        let flowLayout = collectionViewLayout as! UICollectionViewFlowLayout
        let page: Int
        switch flowLayout.scrollDirection {
        case .horizontal:
            page = Int((scrollView.contentOffset.x + scrollView.frame.width) / scrollView.frame.width)
        case .vertical:

    }
    
    open func indexForPage(_ page: Int) -> Int {
        let currentPage = page - 1
        if currentPage <= 0 {
            return 0
        } else if let pageCount = document?.pageCount, currentPage > pageCount {
            return pageCount - 1
        } else {
            return currentPage
        }
    }
    
    open func displayPage(_ page: Int, animated: Bool) {
