0

Couldn't create horizontal scrolling PDF view in ios 10. Is this possible in iOS 11 ? Using PDFKit - PDFView ?

Mohamed Raffi
  • 1,165
  • 1
  • 7
  • 15

2 Answers2

6

You can do something like this:

//configure the pdfView or use it from an outlet in Storyboard
let pdfView = PDFView(frame: self.view.bounds)
let url = Bundle.main.url(forResource: "pdfFile", withExtension: "pdf")
pdfView.document = PDFDocument(url: url!)
//the important setting
pdfView.displayDirection = .horizontal
pdfView.usePageViewController(true, withViewOptions: nil)
//add to subview if you don't use an outlet
self.view.addSubview(pdfView)
Hw.Master
  • 4,412
  • 3
  • 18
  • 19
1

This works for me:

        if let path = Bundle.main.path(forResource: "myfile", ofType: "pdf") {
            let url = URL(fileURLWithPath: path)
            if let pdfDocument = PDFDocument(url: url) {
                pdfView.autoScales = true
                pdfView.displayMode = .singlePage
                pdfView.displayDirection = .horizontal
                pdfView.usePageViewController(true, withViewOptions: [UIPageViewControllerOptionInterPageSpacingKey: 5])
                pdfView.document = pdfDocument    
            }
        }
Mario Burga
  • 1,107
  • 1
  • 13
  • 19