开发者

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

开发者 https://www.devze.com 2023-01-19 11:20 出处:网络
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.

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...

  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))
0

精彩评论

暂无评论...
验证码 换一张
取 消