105

I have a colour PDF file, and I'm going to print it out and then photocopy it in black and white. I'd like to know what it's like in B&W before photocopying it. Is it possible to 'greyscale' a PDF on the command line using free software? I'm using Ubuntu 9.10.

4 Answers 4

40

ImageMagick can do this.

convert -colorspace GRAY color.pdf gray.pdf

via this email

10
  • 38
    That significantly reduces quality. @goyinux' solution is better. Feb 12, 2013 at 16:41
  • 8
    Convert will actually rasterize the contents of the pdf. So unless the pdf already encapsulates only raster images (e.g. a scanned document), this approach is a big no-no.
    – m000
    Sep 19, 2014 at 12:24
  • 4
    Unless you use -density 400 -quality 100 parameters - that works well
    – burtek
    Dec 13, 2015 at 20:51
  • 2
    Really, is there anything ImageMagick can't do? :) Aug 18, 2017 at 3:02
  • 1
    -density 400 -quality 100 creates HUGE files. +1 for @goyinux's solution. Jun 27, 2018 at 10:45
216

Better:

gs \
 -sOutputFile=output.pdf \
 -sDEVICE=pdfwrite \
 -sColorConversionStrategy=Gray \
 -dProcessColorModel=/DeviceGray \
 -dCompatibilityLevel=1.4 \
 -dNOPAUSE \
 -dBATCH \
 input.pdf
9
  • 2
    Agreed, this gives much better results than convert, but sometimes it rotates the pdf which is a bit annoying!
    – tdc
    Aug 7, 2012 at 18:08
  • 24
    Just realised you can disable that with -dAutoRotatePages=/None
    – tdc
    Aug 7, 2012 at 18:15
  • 2
    I just ran this command on a 58MB PDF that was already greyscale (came from a scanner) and the resulting output was 10MB and looked exactly the same. Nice!
    – Archie
    Dec 19, 2012 at 2:33
  • 1
    Works well on Windows, too! Just remove the `\` and put everything on the same line.
    – ixe013
    Aug 19, 2014 at 4:23
  • 1
    In fact, this fails with this error GPL Ghostscript 9.10: Unable to convert color space to Gray, reverting strategy to LeaveColorUnchanged.
    – jjmerelo
    Dec 15, 2015 at 17:56
16

Here’s a little script which in addition to the grayscale conversion can concatenate multiple input files. To use the script, put the following lines in a file, e.g. "convert2gray.sh"

#!/bin/bash
gs -sOutputFile=converted.pdf -sDEVICE=pdfwrite -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -dCompatibiltyLevel=1.4 -dNOPAUSE -dBATCH $@

and make it executable

chmod +x convert2gray.sh

Then

./convert2gray.sh input1.pdf input2.pdf … lastinput.pdf

will produce a single PDF "converted.pdf", which contains all pages from the input files converted to grayscale.

I had to print out mutliple files all in grayscale and found this the easiest way, since you can print out everything after inpection with one command.

1
  • FWIW, pdftk can concatenate PDFs, too. Jun 14, 2018 at 7:07
0

In my case I am keeping signed document scans in color, but need reprint it without gray noice. For this case works well

convert -density 300 -threshold 75% input.pdf output.pdf

(based on the answer)

Range between 50%-75% works fine in circumstances when you have color scan PDF (text as image) with original resolution 300dpi.

In case of text saved as PDF (not image) you will get huge increasing of output file size.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .