pdf to grayscale looks awful

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mark

pdf to grayscale looks awful

Post by mark »

Hello, I possess a ~200MB/350pages pdf file. It is a result from a scan, so every page is an image.
Unfortunately the guy who created this file saved every page in RGB though only 10 pages should be RGB, the rest is fine with grayscale.
I extracted every page from the original pdf into single pdf files to be able to convert all pages into grayscale and create a new pdf from that afterwards.

My first try was the following command (using bash):

Code: Select all

for FILE in *pdf
  convert -type Grayscale $FILE `echo $FILE|cut -f1 -d'.'`_gray.pdf
done
This works, but the resulting pages are practically unreadable, it looks like many information gets lost this way.

So for comparison I opened one page with gimp, converted it to grayscale and saved it. The resulting page looks really nice, exactly like the RGB file (but in grayscale of course) and it is about 1MB smaller.
What gimp produces is exactly what I want (though I can only save as png which forces me to convert the file later again), but of course I cannot do this manually for every page, so imagemagick is the only choice I have...
How can I do that with imagemagick?
mark

Re: pdf to grayscale looks awful

Post by mark »

ok, I was able to write a small python-fu for gimp which did the trick, but nevertheless I want to know how to do this with imagemagick :-)

Code: Select all

import os
for root, dirs, files in os.walk('/home/mark/tmp'):
  for file in files:
    image = pdb.file_pdf_load(root+'/'+file, root+'/'+file)
    pdb.gimp_image_convert_grayscale(image)
    pdb.file_png_save_defaults(image, image.active_layer, root+'/'+file, root+'/'+file)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: pdf to grayscale looks awful

Post by magick »

Try this command:
  • convert -density 400 $FILE -resize 25% -type Grayscale `echo $FILE|cut -f1 -d'.'`_gray.pdf
You can try adding -monochome before the first filename. For smaller file sizes add -monochrome just before the final filename. Or add -compress Zip.
Post Reply