在特定页面上打开 PDF 文件 iOS

Rov*_*val 1 pdf ios

是否可以PDF在特定页面上打开文件UIDocumentInteractionController

我试图在文件地址字符串的末尾附加#page=3但当我尝试这样做时它不起作用:

NSString* pdf = [fileName stringByAppendingString:@"#page=3"];

NSURL *URL = [[NSURL alloc] initFileURLWithPath:pdf];
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
Run Code Online (Sandbox Code Playgroud)

也许有另一种方法可以做到这一点?

Rov*_*val 5

现在,使用 Swift 4 和 PDFKit,我们可以执行以下操作:

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)
    }

}
Run Code Online (Sandbox Code Playgroud)