Is it possible to invert text and background colors in a PDF when printing?

18

6

I have an existing PDF with a totally black background and all text is white.

Is there a way to get the text to print black and the black background to not print at all?

I have Bluebeam and Adobe PDF.

Ron

Posted 2012-07-16T20:39:09.927

Reputation: 181

Answers

12

Funnily enough there are "legitimate" use cases for this, notably people with low vision. Acrobat and other readers can override colors for display (eg Ctrl-I in Evince and via the Accessibility menu in Acrobat Reader X) but strangely not for printing. What you can do, though, is use GhostScript's pdf2ps converter (or a fake PS printer driver that just writes the file) to get a postscript file, then edit the file by putting

{1 exch sub} settransfer 

as the first line in the file and then printing that PostScript file. That way you get a more faithful rendering of the doc than you would if you converted the PDF to an image and inverted that.

AlwaysLearning

Posted 2012-07-16T20:39:09.927

Reputation: 1 169

Using a combination of pdf2ps and ps2pdf I can be able to export the original pdf into an inverted pdf file. I'm just curious on what the proposed line do and if it is possible to "revert" back to the original colors. – tigerjack89 – 2017-06-13T09:57:01.833

1I've done something like this (on Windows) by installing a PostScript printer driver and then telling it to print to file to capture the output. The same concept should work on other OSs. It should be noted that PostScript files are just text files that can be edited with most text editors. – martineau – 2012-07-16T22:38:00.670

3

There is an easy way, and a technical way.

The technical way is that if you have Ghostscript installed and have its .../bin folder added to your PATH, you should just be able to invert the colours of your PDF by calling something resembling the following from the command-line:

gswin64 -o C:/outputfile.pdf -sDEVICE=pdfwrite -c "{1 exch sub}{1 exch sub}{1 exch sub}{1 exch sub} setcolortransfer" -f C:/inputfile.pdf

Note that gswin64 (located in the .../bin folder) might be called gswin32 if you downloaded the 32-bit version, or something else entirely if you're on a *nix system instead of Windows, and that you should obviously replace C:/outputfile.pdf and C:/inputfile.pdf with the actual paths of your input file and intended output file location. Also take care that in my experience there can sometimes be a bit of trouble if you have spaces in your path directories, even if you put quotation marks around them.

It's also worth noting that iirc some versions of Ghostscript might fail on this unless you put the {1 exch sub}{1 exch sub}{1 exch sub}{1 exch sub} setcolortransfer line in a separate .ps file and just add the .ps file to your command.

(This is really just a more fleshed-out version of Mateen Ulhaq's answer above)

The easy way is that if you can't be bothered doing any of the above, you can use the website InvertPDF.com that will do all of this (plus a little more) for you. This is my own website, and I stumbled upon this thread while I was trying to build it. I sure hope this answer makes it easier for the next person trying to achieve a similar thing, or making their own offline script.

Jack Crawford

Posted 2012-07-16T20:39:09.927

Reputation: 31

3

According to this page, you may be able to accomplish it with ImageMagick. However, the PDF will be converted to images before it is inverted. If the quality isn't sufficient because of this, you should be able to adjust the DPI number.

convert -density 300 -negate "input.pdf[1-999]" output.pdf

Replace 300 with your desired DPI and 1-999 with your desired page range.

NOTE: This command is for an older version of ImageMagick and you will need to ensure that legacy utilities are installed.

Legacy Utilities

bdr9

Posted 2012-07-16T20:39:09.927

Reputation: 2 508

@fixer1234 Thanks for bringing this to my attention. I have added a link to that page on the Internet Archive. – bdr9 – 2015-11-17T19:55:47.150

1

None of the previously posted solutions worked for me so I wrote this simple bash script. It depends on pdftk and awk. Just copy the code into a file and make it executable. Then run it like:

$ /path/to/this_script.sh /path/to/mypdf.pdf

The script:

#!/bin/bash                                                                      
pdftk "$1" output - uncompress | \                                               
awk '                                                                            
  /^1 1 1 / {                                                                    
    sub(/1 1 1 /,"0 0 0 ",$0);                                                   
    print;                                                                       
    next;                                                                        
  }                                                                              

  /^0 0 0 / {                                                                    
    sub(/0 0 0 /,"1 1 1 ",$0);                                                   
    print;                                                                       
    next;                                                                        
  }                                                                              

  { print }' | \                                                                 
pdftk - output "${1/%.pdf/_inverted.pdf}" compress

This script works for me but your mileage may vary. In particular sometimes the colors are listed in the form 1.000 1.000 1.000 instead of 1 1 1. The script can easily be modified as needed. If desired, additional color conversions could be added as well.

John Cole

Posted 2012-07-16T20:39:09.927

Reputation: 11

1

In Acrobat Reader X

Edit->Preferences->accessibility Select: Replace document colors Select: Custom color

Set remaining options according to personal preference.

Note: This does not change the document, just your view and they way it is printed.

Bas

Posted 2012-07-16T20:39:09.927

Reputation: 27

Does not print differently than the original AFAICT – mike65535 – 2018-06-25T19:27:04.173

0

If you want a more pleasing greyscale, and are OK with converting your document to images, throw this into a .bat file and then simply drag your PDF onto the .bat file.

"C:\Program Files\gs\gs9.20\bin\gswin64c" -o inverted.pdf -sDEVICE=pdfwrite -c "{1 exch sub}{1 exch sub}{1 exch sub}{1 exch sub} setcolortransfer" -f %1
convert -brightness-contrast 3,-18 -compress lzw  -density 300 -colorspace Gray inverted.pdf output.pdf

Requires Ghostscript to be installed for the first command (please specify correct path). Requires ImageMagick with legacy utilities to be installed for the second command.

Mateen Ulhaq

Posted 2012-07-16T20:39:09.927

Reputation: 3 207

0

Many had suggested using the Edit->Preference->Accessibility method but sadly it did not work for me. After testing and playing around PDF setting, I managed to get what I wanted!

  • Go to Print (Ctrl + P)
  • Click Advanced Settings
  • Check Settings: Custom
  • Click on Output from left panel
  • Under Color: select Composite Gray
  • Check the Negate box
  • Click OK

This should do the trick!

Important Note!
I would suggest printing this file to a PDF than directly. Especially if you intend to print multiple pages in one page as it will result in the whitespace turning black too!

Lastly, if you are going to print the document as another PDF, under Page Sizing & Handling , click on Fit and check both the boxes - "Choose paper size when needed" and Use custom paper size when needed. (To avoid unwanted whitespace)

Hope this help!

Xin Yi

Posted 2012-07-16T20:39:09.927

Reputation: 11

This is specific to your printer driver – Mark Jeronimus – 2018-06-18T14:06:05.310

-1

Using ImageMagick worked for me, although the outputfile is about 50 times larger than the input one.

convert -density 300 -negate input_file.pdf output_file.pdf

Catchaca

Posted 2012-07-16T20:39:09.927

Reputation: 11

The command line (in luinux) was : convert -density 300 -negate input_file.pdf output_file.pdf – Catchaca – 2016-01-19T22:06:26.803