Hi I am trying to change the highlight color in a pdf but not able to do so. The default highlight color is yellow but i want to change it Following is my code:
import fitz
doc = fitz.open(r"path\input.pdf")
page=doc[0]
text="some text"
text_instances = page.searchFor(text)
for inst in text_instances:
highlight = page.addHighlightAnnot(inst)
highlight.setColors(colors='Red')
highlight.update()
doc.save(r"path\output.pdf")
Also how do i search for the entire pdf together and not just one page
and how can i highlight text on an image given in a pdf
text_instances = page.searchFor(text)
withtext_instances = page.search_for(text)
, as the instance name has been updated in later versions of fitz/PyMuPDF. – Works