I'd like to mark several keywords in a pdf document using Python and pymupdf.
The code looks as follows (source: original code):
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(colors='Red')
highlight.update()
doc.save("output.pdf")
However, the text gets only marked on one page. I tried changing the code as described in the documentation for pymupdf (documentation) so it slices over all pages.
import fitz
doc = fitz.open("test.pdf")
for page in doc.pages(1, 3, 1):
pass
text = "result"
text_instances = page.searchFor(text)
for inst in text_instances:
highlight = page.addHighlightAnnot(inst)
highlight.setColors(colors='Red')
highlight.update()
doc.save("output.pdf")
Unfortunately, it still only marks the keywords on one page. What do I need to change, so the keywords get marked on all pages?