1

我在使用 PDFKit 的 pdfView 中有一个 pdf 文档

    var urldocs = getDocumentsDirectoryURL()

    urldocs.appendPathComponent("test.pdf")


    let pdfDocument = PDFDocument(url: urldocs)

    pdfView.displayMode = .singlePageContinuous
    pdfView.autoScales = true

    pdfView.document = pdfDocument

如何设置 pdfView 以显示嵌入文档的特定区域!?在 ScrollView 中,可以使用 ScrollView.contentOffset = CGPoint ... 我无法弄清楚如何在 pdfView 中执行此操作

谢谢 !

4

2 回答 2

1

这将转到第 2 页上 10、10 处的 100x100 大小的区域。由于它是基于 0 的索引,因此第 2 页表示为索引 1。

pdfView.go(to:CGRect(x: 10, y: 10, width: 100, height: 100), on:pdfView.document.page(at: 1))
于 2019-08-29T11:56:20.527 回答
0

您可以转到通过文档中的文本搜索找到的选择:

let selections = pdfView.document!.findString("have a pdf document", withOptions: [NSString.CompareOptions.literal])
guard let newSelection = selections.first else {
    fatalError("selection not found.")
}

update(pdfView) {
    $0.setCurrentSelection(newSelection, animate: true)
    $0.scrollSelectionToVisible(nil)
}

或者您可以转到页面上的 cgRect:

let pdfPage = pdfView.document!.page(at: 0)!
pdfView.go(to: cgRect, on: pdfPage)
于 2018-09-11T20:44:11.337 回答