Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove / Delete all images from a PDF using Ghostscript or ImageMagick

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.

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

like image 799
codin Avatar asked Dec 19 '13 08:12

codin


2 Answers

You can use the draft option of cpdf:

cpdf -draft in.pdf -o out.pdf

This should work in most situations, but file a bug report if it doesn't do the right thing for you.

Disclosure: I am the author of cpdf.

like image 180
johnwhitington Avatar answered Oct 05 '22 20:10

johnwhitington


Time has passed, and development of Ghostscript has progressed...

The latest releases have the following new command line parameters. These can be added to the command line:

  1. -dFILTERIMAGE: produces an output where all raster drawings are removed.

  2. -dFILTERTEXT: produces an output where all text elements are removed.

  3. -dFILTERVECTOR: produces an output where all vector drawings are removed.

Any two of these options can be combined.

Example command:

gs -o noimage.pdf -sDEVICE=pdfwrite -dFILTERIMAGE input.pdf

More details (including some illustrative screenshots) can be found in my answer to "How can I remove all images from a PDF?".

like image 28
Kurt Pfeifle Avatar answered Oct 05 '22 19:10

Kurt Pfeifle