converting a grayscale multipage PDF file to BW

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.farnell

converting a grayscale multipage PDF file to BW

Post by mark.farnell »

I have a grayscale PDF file of music score, but this file does not have images, so it is really meant to be black and white. How can I convert this file to black and white to save space? Also how can I specify the filter cutoff point between white and black? I tried in ghostscript, but results is unsatisfactory. ghostscript seems to congretate a few neighbouring gray pixels to one black pixel - so light gray areas become spotted with black dots, whereas I want these light gray background areas completely *removed*

gs -sDEVICE=tiffg4 -sOutputFile=output.tiff input.pdf

Thanks!

Mark
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting a grayscale multipage PDF file to BW

Post by fmw42 »

try supersampling and thresholding

convert -density 288 image.pdf -resize 25% -threshold 50% -type bilevel image.tiff

You can vary the threshold and see what value gives you the best results.

using -density 288=72*4 is 4 times higher resolution than nominal 72 dpi, so afterwards one resizes by 1/4=25%

You can resize by a larger percent if you want to have higher resolution, but the image will be bigger.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: converting a grayscale multipage PDF file to BW

Post by magick »

To generate monochrome PDF's, try this command:

convert -monochrome page.pdf page.tiff
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting a grayscale multipage PDF file to BW

Post by fmw42 »

see http://www.imagemagick.org/Usage/quantize/#monochrome about monochrome, but according to Anthony's page +dither has no effect on -monochrome, so that your results will be dithered. That was why I did not suggest it earlier. However, it is the simplest way to get b/w images and may suffice for you.
mark.farnell

Re: converting a grayscale multipage PDF file to BW

Post by mark.farnell »

I tried:

convert -monochrome page.pdf page.tiff

but like the gs command I used, it just pools surrounding light pixels (in light background) into a black pixel in monochrome, which wastes both disk space and toner.

What I really want is use threshold to distinguish between background and text, that's all.

Then I also tried:

convert -density 288 image.pdf -resize 25% -threshold 50% -type bilevel image.tiff
tiff2pdf image.tiff > output.pdf

However the pages of the resultant output.pdf become really small!
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: converting a grayscale multipage PDF file to BW

Post by Drarakel »

Replace '-resize 25%' with '-resample 72' (a quarter of 288). Then the printing size (if that's what you meant) should be preserved.
Post Reply