Convert a PDF to greyscale on the command line in FLOSS?
Solution 1
ImageMagick can do this.
convert -colorspace GRAY color.pdf gray.pdf
via this email
Solution 2
Better:
gs \
-sOutputFile=output.pdf \
-sDEVICE=pdfwrite \
-sColorConversionStrategy=Gray \
-dProcessColorModel=/DeviceGray \
-dCompatibilityLevel=1.4 \
-dNOPAUSE \
-dBATCH \
input.pdf
Solution 3
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.
Related videos on Youtube
Comments
-
Amandasaurus over 1 year
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.
-
tdc almost 12 yearsAgreed, this gives much better results than convert, but sometimes it rotates the pdf which is a bit annoying!
-
tdc almost 12 yearsJust realised you can disable that with
-dAutoRotatePages=/None
-
Archie over 11 yearsI 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!
-
Johannes Weiss about 11 yearsThat significantly reduces quality. @goyinux' solution is better.
-
ixe013 over 9 yearsWorks well on Windows, too! Just remove the `\` and put everything on the same line.
-
m000 over 9 yearsConvert 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.
-
burtek over 8 yearsUnless you use
-density 400 -quality 100
parameters - that works well -
jjmerelo over 8 yearsIn fact, this fails with this error
GPL Ghostscript 9.10: Unable to convert color space to Gray, reverting strategy to LeaveColorUnchanged.
-
saeedgnu almost 7 yearsWorks great. But output image size is almost 3x for my file. I have a complicated vector-drawing colorful file with 3.5 MB size that became 10 MB!
-
Joshua Grosso Reinstate CMs over 6 yearsReally, is there anything ImageMagick can't do? :)
-
user1338062 almost 6 yearsFWIW, pdftk can concatenate PDFs, too.
-
Stanimir Stoyanov almost 6 years
-density 400 -quality 100
creates HUGE files. +1 for @goyinux's solution. -
rew over 5 yearsThe big files print great (only using black toner) while the original and gs-converted file use all toners and create a vague mess on my printer.
-
Mpunkt Moeniac about 5 yearsWhat's the reason for
convert
to reduce the quality of rasterized images? I tried using the optionsconvert -density 300 -quality 100
, in order to prevent this behaviour ofconvert
. But the quality of the output image is still much worse than the quality of the input image... so are there options forconvert
, that prevent the encapsulated images from quality loss, when convertingpdf
'-files encapsulating rasterized images? -
xaratustra about 4 yearsThis is really fantastic. Perfect for scanned documents for subsequent print.
-
loved.by.Jesus over 3 yearsAnother problem with
convert
is that OCRed pdf files lose the text layer. That is, one loses the OCR. While the method withgs
keeps OCR. -
loved.by.Jesus over 3 yearsSome people complains that the size of the grayscale image is not lower than the original. If, besides turning the image grayscale, you want to compress it, add the following option
-dPDFSETTINGS=/ebook
. Instead of/ebook
you can also use/screen
for a more radical compression (i.e. lower quality). Enjoy it! -
Jean Carlo Machado about 3 years
convert -density 200 -colorspace GRAY
worked like a charm for me