Search code examples
python-3.xpdfcolorshighlight

change text color or highlight text with multiple colors using python


I am trying to read the pdf and highlight some sub-strings in pdf, and i am able to achieve it using python libraries PYPDF2 and fitz

but i wanted to make to highlight/ change text with different colors and retain the layout of the original pdf,

please advice on this, thank you


Solution

  • We can't change the textcolor of words inside the pdf but we can use the

    highlight annot

    with default color("yellow"),

    if need more colors we need to make the

    square annot

    using pymupdf lib, this worked for me in python