Is their a way, with imagemagick, pdftk or other stuff, to remove a specific color from a whole pdf document?

I mean, I give an html hex color code to a tool, and it remove all occurences of this color from a pdf file.

How to do it?

1 Answer 1


You can use imagemagick to convert one color to another, including an rgba value; if the page background is predicable, white say, you can replace the color in question with that. Suppose you want to replace red #ff0000 with (transparent) white, then you can use something like this:

convert input.pdf -fuzz 10% -fill 'rgba(255,255,255,0)' -opaque '#ff0000' output.pdf

(The fuzz value sets how closely to the color in question it needs to match.)

  • I got the following error message convert-im6.q16: attempt to perform an operation not allowed by the security policy PDF' @ error/constitute.c/IsCoderAuthorized/421. convert-im6.q16: no images defined output.pdf' @ error/convert.c/ConvertImageCommand/3229.. It seems I should allow imagemagick to perform this kind of operation.
    – fauve
    May 6, 2022 at 2:35
  • Well, I solve the previous problem with this solution but the command you give didn’t delete the targeted color and in addition, it transform the pdf into a bitmap witch is not desirable.
    – fauve
    May 6, 2022 at 2:40
  • Imagemagick pretty much only works on rasterized images, so that is definitely a downside. Converting to svg with inkscape and just changing colors with sed then converting back might be a possibility, but it would be a lot easier to test with the actual file rather than speculate blindly.
    – frabjous
    May 6, 2022 at 3:24
  • I planed to do the convertion into svg with inkscape and come back to pdf. But the inkscape convertion break the fonts (and so other vectorial effects) :/ That’s why I whant to avoid inkscape solution, also manualy.
    – fauve
    May 6, 2022 at 4:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .