I'm searching for a li开发者_运维问答nux 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
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...
- your Ghostscript probably is a newer release from the 9.x version series, and
- 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
(additional forward slash character)-sProcessColorModel=/DeviceGray
- instead of
-sProcessColorModel=DeviceGray
(no forward slash))
精彩评论