Okay, let's break this down.
Yes, it is possible to achieve a color inversion effect in Ghostscript, similar to the invert(100%)
part of your CSS filter. Replicating the hue-rotate(180deg)
part exactly is significantly more complex within Ghostscript's standard processing model, but the simple inversion often gets you 90% of the way to a usable "dark mode".
The core idea is to use PostScript's transfer functions. These functions modify color component values just before they are rendered. To invert a color component c
(where c
is between 0 and 1), the function is simply 1 - c
.
We need to apply this function to all relevant color spaces commonly found in PDFs: DeviceGray, DeviceRGB, and DeviceCMYK.
Here is the Ghostscript command you can use in a Bash shell script: