问题
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
回答1:
I think the setColors
expects a dictionary, check the documentation here
import fitz
doc = fitz.open("test.pdf")
page = doc[0]
text = "result"
text_instances = page.searchFor(text)
for inst in text_instances:
highlight = page.addHighlightAnnot(inst)
highlight.setColors({"stroke":(0, 0, 1), "fill":(0.75, 0.8, 0.95)})
highlight.update()
doc.save("output.pdf")
来源:https://stackoverflow.com/questions/60557977/how-to-change-the-highlight-color-in-pdf-using-fitz-module-in-python