Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux command-line utility to remove colors in a PDF file?

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

like image 949
plang Avatar asked Dec 06 '25 20:12

plang


1 Answers

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))
like image 64
Kurt Pfeifle Avatar answered Dec 09 '25 19:12

Kurt Pfeifle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!