Reputation: 597
Is it possible to open PDF
file on certain page with UIDocumentInteractionController
?
I'm trying to append #page=3 at the end of the file address string but it is not working when I try to do:
NSString* pdf = [fileName stringByAppendingString:@"#page=3"];
NSURL *URL = [[NSURL alloc] initFileURLWithPath:pdf];
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
Maybe there is another way to do this?
Upvotes: 2
Views: 2283
Reputation: 597
Now, with Swift 4 and PDFKit we can do the following:
var pdfView: PDFView!
override func viewDidLoad() {
super.viewDidLoad()
pdfView = PDFView()
// You might want to constraint pdfView here
// Load pdf from bundle or url
let url = Bundle.main.url(forResource: "test", withExtension: "pdf")!
let document = PDFDocument(url: url)
pdfView.document = document
// Grab 10th page, returns optional if out of bounds
if let page10 = document?.page(at: 10) {
pdfView.go(to: page10)
}
}
Upvotes: 7
Reputation: 362
It doesn't look possible to do this. Don't see any hooks into the document interaction controller's scrollview, so you can't change the offset programmatically. You probably need to:
Basically make your own preview.
Upvotes: 0