Check if a word or words are already highilighted #1665
-
Is there a way to know if a word is highlighted?
Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 10 replies
-
The only way to know whether some area on the page (be it text or something else), is to walk through the page's highlight annots and then check whether your area is covered by one of the annotation rectangles. Maybe a slightly different approach can help:
|
Beta Was this translation helpful? Give feedback.
-
An item of word = item[4]
lword = len(word)
bbox = fitz.Rect(item[:4])
if word == "v" * lword: # all "v"
# ok to process
elif lword > 2 and word[:-1] == "v" * (lword - 1):
# ok to process: word ends with punctuation probably
else:
# not my case
``` |
Beta Was this translation helpful? Give feedback.
-
As a special service 😉, here is an example snippet: |
Beta Was this translation helpful? Give feedback.
-
More complications can arise from "words" like import string
check_set = set(string.punctuation)
check_set.add("v")
# check if word contains at least one "v" and else only punctuations:
if check_set.issuperset(set(word)) and "v" in word:
# ok to process |
Beta Was this translation helpful? Give feedback.
-
Here are other versions that make use of that idea with Python sets - mucho más fácil! |
Beta Was this translation helpful? Give feedback.
Here are other versions that make use of that idea with Python sets - mucho más fácil!
Also added a version without annotations ...
test-annot2.zip