Couldn't create horizontal scrolling PDF view in ios 10. Is this possible in iOS 11 ? Using PDFKit - PDFView ?
Asked
Active
Viewed 1,766 times
0
-
1This Q is out of scope of SO. Report the attempts you have made so far and ask a specific Q, if necessary. – Amin Negm-Awad Sep 27 '17 at 18:22
2 Answers
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
-
HI! Adding displayDirection after setting document is not working! However i have tried to set pdfDocument just before addSubview and is working! I Hope you have tested the above code before pasting here! – Saurabh Prajapati Nov 07 '17 at 05:14
-
@SaurabhPrajapati yes i've tested before post to stackoverflow as usual. – Hw.Master Nov 09 '17 at 07:27
-
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