Is it possible to invert text and background colors in a PDF when printing?
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.
Solution 1:
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.
Solution 2:
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 some sort of online PDF inverter which will probably just do this for you. (Edit: There used to be no such websites. After seeing this thread, I made one and ran it for a while, but then after a few other websites popped up offering the same service I closed mine.)
Solution 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.
Solution 4:
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.