Thursday, May 1, 2008

PDF conversion to grayscale

I had some trouble finding out how to convert a color PDF to a grayscale one. I found a post on an Ubuntu forum giving the following recipe:

pdf2ps -sDEVICE=psgray original.odf
ps2pdf original.ps new.pdf

This works, but this has the unpleasant side effect to increase the size of the PDF and to lower the quality (for a reason which escapes me). So I looked again in the magic pdfwrite parameters, and I came up with the following solution, which works on my box (though the above page suggests it shouldn't):

gs -sOutputFile=biniou.pdf -sDEVICE=pdfwrite \
  -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray \
  -dCompatibilityLevel=1.4 Plot.pdf < /dev/null

This works fine, does not lower the quality of the produced PDF and in the case I tried even made it smaller...

12 comments:

Zack Weinberg said...

The quality deteriorates in the first example because pdf2ps uses Ghostscript's "pswrite" driver, which is really really dumb. It does things like convert text to paths. The "pdfwrite" driver is much more sensible.

dvase said...
This comment has been removed by the author.
dvase said...

Thank you! Thank you! Thank you!

I was beginning to despair that such a seemingly easy task was so difficult. Judging by the number of other posts I've seen by people also looking to solve this problem, your solution is a God send.

Unknown said...

thanks!

Unknown said...

big thanks!

hiusy said...

is ghostscript able to perform conversion also from RGB to CMYK for pdf?

Ethan Anderson said...

I cannot begin to express how much trouble you just saved me.

Next time, I'm NOT going to forget to switch xsane to greyscale before I scan.....

Paul d'Aoust said...

Your blog title is incredibly inaccurate; it's far from useless. I'm very grateful you shared this tip, as I'm trying to do the very same thing myself.

pw said...

wow. impressive. didn't think i'd find such a nice solution that quickly

Jaichu said...

Thanks a lot :)

Unknown said...
This comment has been removed by the author.
Anonymous said...

There are some of the more basic parts and objects which are almost transcribing everything what has been asked to do so, hopefully it will create something good to it. convert java to c