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.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityFunnily 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.
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.
Jun 13, 2017 at 9:57
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.
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.)
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.
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.
I've tried many of the answers here, and none have been adequate for me. The top answer simply didn't work, and most other solutions converted each page of the PDF into a raster image, inflating the size and decreasing the quality.
For these reasons, I decided to create a solution of my own, which can be downloaded from github here. It's a relatively simple Java program built upon a fork of pdfbox. (The fork exists simply to allow access to two otherwise private fields/methods.) It's licensed under the highly nonrestrictive MIT license.
Using the program is very simple. Simply enter the following command in the same directory as PDFInverter.jar
:
java -jar PDFInverter.jar input_file.jar output_file.jar
This will invert all objects, including raster images, in the PDF, while maintaining the lossless nature of text and vector elements in the file. Additionally, you can supply a custom background color by specifying a CSS color string as a 3rd parameter like so:
java -jar PDFInverter.jar input_file.jar output_file.jar #7f7f7f
If you would like to leave raster images contained in the file untouched, you can enter "false" as the 4th parameter to disable the feature:
java -jar PDFInverter.jar input_file.jar output_file.jar #7f7f7f false
Caveats:
Pattern
color space. (See the PDF specification §8.2.2.6 and §8.7)DeviceRGB
color space (§8.6.4.3), meaning there might be a loss of gamut if the corresponding color was defined in a different color space.Disclaimer: This is a project which I have personally developed. While I have nothing to gain from your use of the program, I still feel it is important to make it clear that I am the one who developed the program, and might be biased towards its use or otherwise.
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.
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!
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!
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