Linux 命令行实用程序可删除 PDF 文件中的颜色?

发布于 2024-09-26 04:57:33 字数 96 浏览 5 评论 0原文

我正在寻找能够删除 PDF 中颜色的 Linux 命令行实用程序/脚本。该实用程序的输出应该是相同的 PDF,但为灰度。

有谁知道该怎么做?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月染过的梦 2024-10-03 04:57:34

您可以使用 Ghostscript:(

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

示例适用于 Windows;在 Linux 上使用 gs 而不是 gswin32c.exe\ 作为行继续标记而不是<代码>^)。


更新

如果颜色转换无法按预期工作,并且如果您看到类似“无法将颜色空间转换为灰色,将策略恢复为 LeaveColorUnchanged”的消息,那么...

  1. 您的 Ghostscript 可能是来自9.x 版本系列,并且
  2. 您的源 PDF 可能使用嵌入的 ICC 颜色配置文件

在这种情况下添加 -dOverrideICC 到命令行并查看它是否根据需要更改结果。


此外,原始答案包含一个拼写错误:

  • 它使用了-sProcessColorModel=/DeviceGray(额外的正斜杠字符)
  • 而不是-sProcessColorModel=DeviceGray(无正斜杠))

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))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文