使用Ghostscript或ImageMagick删除/删除PDF中的所有图像 [英] Remove / Delete all images from a PDF using Ghostscript or ImageMagick

查看:298
本文介绍了使用Ghostscript或ImageMagick删除/删除PDF中的所有图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除/删除PDF中的所有图像,只留下PDF中的文本/字体,无论使用什么命令行工具。

I want to delete / remove all the images in a PDF leaving only the text / font in the PDF with whatever command Line tool possible.

我尝试使用< Ghostscript命令中的code> -dGraphicsAlphaBits = 1 但是图像存在但是像一个大像素。

I tried using -dGraphicsAlphaBits=1 in a Ghostscript command but the images are present but like a big pixel.

推荐答案

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

如果要从图像中删除所有颜色信息,请在同一命令中将它们转换为灰度(在Stackoverflow上搜索其他答案,详细说明)。

If you want to remove all color information from images, convert them to Grayscale in the same command (search other answers on Stackoverflow 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.

这篇关于使用Ghostscript或ImageMagick删除/删除PDF中的所有图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆