Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    
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

2 Answers 2

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, ...)

share|improve this answer

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.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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