11

How to create pdf with inverted colours of original one?

(Just like inverting whole screen with xcalib -i -a)

Preferably : not loosing hyperlinks. But it's not requirement. It would be nice if images also get inverted.

1
  • Maybe ImageMagick is a starting point -- I've just tried convert orig.pdf -negate negative.pdf but the result is not that good....maybe there're caveats I'm not aware of.
    – sr_
    Feb 29 '12 at 18:35
7

A while ago, I was able to find a way to invert postscript files (although it failed for some files, I guess the ones which somehow override the change).

Adding {1 exch sub} settransfer as the first command in the file would invert the colors of the document (bitmap pictures included).

For the PDF → postscript conversion, you can use pdftops from libpoppler (AFAIK, the ghostscript pdf2ps generates suboptimal results). Unfortunately, this will not be kept when generating a PDF from the now negated postscript file.

Note that some pdf viewers have the ability to invert colors, such as xpdf (which does not invert bitmaps) and evince (which inverts everything, apparently no matter the format (PDF, postscript, djvu, ...)

2
  • 4
    Invert color in evince, View -> Inverted Colors OR Ctrl-i if you prefer keyboard shortcut.
    – Glass
    Apr 4 '16 at 2:04
  • For xpdf, use xpdf -rv <filename> to open the document in reverse video mode. Some more info from the man page: "This reverses the colors of everything except images. It may not always produce great results for PDF files which do weird things with color. This also causes the paper color to default to black."
    – GDP2
    Sep 6 '17 at 7:20
0

I rigged together a Ruby script (using Inkscape and ImageMagick as subroutines) pdfinvert. It proceeds as follows:

  1. Split PDF into individual pages.
  2. Convert each page to SVG.
  3. Invert colors¹ in the SVG; embedded PNG images are taken care of².
  4. Reconvert each page to PNG.
  5. Join pages together for the final result.

It was designed for drawings but it may work in many more cases (it seems to need some extensions to work with uncolored backgrounds).


  1. You can also specify a color replacement table.
  2. The approach probably extends to JPG or any other format ImageMagick's convert can deal with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.