Below is a piece of my code, where I'm searching for a particular word & extracting their coordinates.
As per the documentation page.searchFor(), page.searchFor(needle, hit_max=16, quads=False, flags=None).
Searches for needle on a page. Upper/lower case is ignored. The string may contain spaces.
First, I want the coordinates for an exact match. Secondly, if the selected word is "inter", it will also extract the coordinate of "inter" from the word internalization present in the document which conflicts with my task.
Is there any way I can achieve the same?
doc = fitz.open(document_name)
words = ["Midpoint", "CORPORATE", "internalization"]
for page in doc:
page._wrapContents()
for word in words:
text_instances = page.searchFor(word)
for rect_coordinates in text_instances:
page.addRedactAnnot(rect_coordinates, text_color = (0,0,0), fill = (0,0,0))
page.apply_redactions()