gpt4 book ai didi

ios - PdfKit 高亮注释

转载 作者:搜寻专家 更新时间:2023-10-30 21:59:17 26 4
gpt4 key购买 nike

我正在尝试在 iOS 上使用 PDFKit 向文档添加高亮注释。

let highlight = PDFAnnotation(bounds: selection.bounds(for: page),
forType: PDFAnnotationSubtype.highlight,
withProperties: nil)

highlight.color = color

page.addAnnotation(highlight)
page.displaysAnnotations = true

使用上面的代码添加它们时,它们显示为两个不同形状的图层。将它们保存到 PDF 文件并重新打开时,它们会正确显示。

this screen capture

enter image description here

使用此处提供的代码片段以相同的方式添加了顶部和底部的高亮显示。上面的已经保存到pdf文档中,重新打开时显示正常,下面的刚刚添加。

有谁知道如何在不保存并重新打开文件的情况下正确显示它们(即像最上面的那样)?

最佳答案

所以这是 10.13 中的已知错误。有一个解决方法,就是将页面滚动离开,然后返回到突出显示

您可以使用以下代码创建突出显示:

let page = self.pdfDocument?.page(at: 10)
let bounds = CGRect(x: 85.8660965, y: 786.8891167, width: 298.41, height: 12.1485)
let annotation = PDFAnnotation(bounds: bounds, forType: .highlight, withProperties: nil)
annotation.color = NSColor.blue
page?.addAnnotation(annotation)

然后您需要滚动离开页面并返回到突出显示

func annotationScrollHack(page: PDFPage) {
guard let pdfDocument = self.pdfDocument else { return }

//When adding highlights to macOS 10.13 it seems like 2 highlights are added.
//If you scroll to a different page and back the "extra" highlight is removed
//This function scrolls to the first/last page in the book and then back to the current page
//rdar://34784917
let bookScrollView = self.pdfView.documentView?.enclosingScrollView
let currentVisibleRect = bookScrollView?.contentView.documentVisibleRect
if (0 ... 3).contains(pdfDocument.index(for: page)) {
if self.pdfView.canGoToLastPage {
self.pdfView.goToLastPage(self)
}
} else {
if self.pdfView.canGoToFirstPage {
self.pdfView.goToFirstPage(self)
}
}

if let currentVisibleRect = currentVisibleRect {
bookScrollView?.contentView.scroll(to: CGPoint(x: currentVisibleRect.origin.x, y: currentVisibleRect.origin.y))
}
}

Apple 的回应:

There is no workaround other than the “hack" they described: scrolling away then back is the best option. Changing zoom factor and reverting it might fix it in the same way, but not guaranteed.

关于ios - PdfKit 高亮注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46487471/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com