Question

I'm searching for a linux command-line utility/script capable of removing colors in a PDF. The output of the utility should be the same PDF, but in grayscale.

Does anyone know how to do this?

Thanks

Was it helpful?

Solution

You can use Ghostscript:

gswin32c ^
  -o grayscale.pdf ^
  -sDEVICE=pdfwrite ^
  -sColorConversionStrategy=Gray ^
  -sProcessColorModel=DeviceGray ^
  -dCompatibilityLevel=1.4 ^
   c:/path/to/input.pdf 

(example is for Windows; on Linux use gs instead of gswin32c.exe and \ as a line continuation mark instead of ^).


Update

If color conversion does not work as desired and if you see a message like "Unable to convert color space to Gray, reverting strategy to LeaveColorUnchanged" then...

  1. your Ghostscript probably is a newer release from the 9.x version series, and
  2. your source PDF likely uses an embedded ICC color profile

In this case add -dOverrideICC to the command line and see if it changes the result as desired.


Also, the original answer contained a typo:

  • it used -sProcessColorModel=/DeviceGray (additional forward slash character)
  • instead of -sProcessColorModel=DeviceGray (no forward slash))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top