Replies: 1 comment
-
|
@dinchu I've been trying to make this work as well. If you know exact coordinates of the text you could create a text highlight with the annotation plugin. However, in my case I don't, I just have the exact text. There does not seem an official way to do it based on pure text match, however, you could combine search and annotation plugins to achieve this, not in a clean way... but possible. const { provides: search, state: searchState } = useSearch(documentId)
const { provides: annotation, state: annotationState } = useAnnotation(documentId)
....
// I did not find a way to scope search to just one page, however, search results can be filtered later.
const matches = await search
.searchAllPages('Text to match')
.toPromise()
const matchesPerPage = matches.filter(match => match.pageIndex === highlightPageIndex)
for (const match of matchesPerPage) {
annotation.createAnnotation(highlightPageIndex, {
type: PdfAnnotationSubtype.HIGHLIGHT,
segmentRects: match.rects,
//...other properties
})
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
is possible to highlight text passed programatically when the pdf is loaded?
Beta Was this translation helpful? Give feedback.
All reactions