I don’t remember where I got this. I jotted it down in my notes. (Sorry to whoever was the original author for not giving credit)
gs -o inverted.pdf -sDEVICE=pdfwrite -c "{1 exch sub}{1 exch sub}{1 exch sub}{1 exch sub} setcolortransfer" -f original.pdf
Edit: this might well be the original post I found: https://stackoverflow.com/a/30287097