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
converting a grayscale multipage PDF file to BW
- 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
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.
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.
- 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
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.
Re: converting a grayscale multipage PDF file to BW
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!
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!
Re: converting a grayscale multipage PDF file to BW
Replace '-resize 25%' with '-resample 72' (a quarter of 288). Then the printing size (if that's what you meant) should be preserved.