更新时间:2023-12-05 15:58:28
不,AFAIK,用命令行工具删除 PDF中的所有图片是不可能的。
No, AFAIK, it's not possible to remove all images in a PDF with a commandline tool.
目的是什么你的要求呢?保存文件大小?删除图片中包含的信息?或者......?
What's the purpose of your request anyway? Save on filesize? Remove information contained in images? Or ...?
无论您的目标是什么,这里都有一个命令会对所有图像进行下采样分辨率为2 ppi( 更新: 1 ppi不起作用)。这一次实现了两个目标:
Whatever you aim at, here is a command that will downsample all images to a resolution of 2 ppi (Update: 1 ppi doesn't work). Which achieves two goals at once:
以下是如何有选择地执行此操作,仅 第33页上的图像original.pdf
:
Here's how to do it selectively, for only the images on page 33 of original.pdf
:
gs \
-o images-uncomprehendable.pdf \
-sDEVICE=pdfwrite \
-dDownsampleColorImages=true \
-dDownsampleGrayImages=true \
-dDownsampleMonoImages=true \
-dColorImageResolution=2 \
-dGrayImageResolution=2 \
-dMonoImageResolution=2 \
-dFirstPage=33 \
-dLastPage=33 \
original.pdf
如果您想在所有所有图像上执行此操作 pages,只需跳过 -dFirstPage
和 -dLastPage
参数。
If you want to do it for all images on all pages, just skip the -dFirstPage
and -dLastPage
parameters.
如果要从图像中删除所有颜色信息,请在同一命令中将它们转换为灰度(在***上搜索其他答案,详细说明)。
If you want to remove all color information from images, convert them to Grayscale in the same command (search other answers on *** where details for this are discussed).
更新:最初,我建议使用1 PPI的分辨率。这似乎不适用于Ghostscript。我现在用2 PPI进行测试。这有效。
Update: Originally, I had proposed to use a resolution of 1 PPI. It seems this doesn't work with Ghostscript. I now tested with 2 PPI. This works.
更新2:另请参阅以下(新)问题及答案:
Update 2: See also the following (new) question with the answer:
它提供了一些示例PostScript代码,它完全删除了所有(光栅)来自PDF的图像,保持页面布局的其余部分不变。
It provides some sample PostScript code which completely removes all (raster) images from the PDF, leaving the rest of the page layout unchanged.
它还反映了Ghostscript的扩展新功能,现在可以有选择地删除所有文本或所有光栅图像,或PDF中的所有矢量对象,或这3种类型的任意组合。
It also reflects the expanded new capabilities of Ghostscript which can now selectively remove either all text, or all raster images, or all vector objects from a PDF, or any combination of these 3 types.