Page 1 of 1
Grayscale matters
Posted: 2013-02-02T19:06:51-07:00
by visionhappens
Hi all
I have a variety of scanned PDFs that are black and white like the following
Many thanks from a massive newbie
Re: Colorizing scanned grayscale PDF
Posted: 2013-02-02T19:16:48-07:00
by fmw42
You do not say what resulting image format you want? If you process to pdf, IM will rasterize and then convert that to PDF.
because you want to keep the antialiasing of the text, you should try
convert test.pdf +level-colors red,white result.png (or gif or jpg)
see
http://www.imagemagick.org/Usage/color_ ... vel-colors
http://www.imagemagick.org/Usage/formats/#vector
Re: Colorizing scanned grayscale PDF
Posted: 2013-02-02T19:20:19-07:00
by visionhappens
Thanks very much sir.
Indeed ideally output would be pdf again. Just tried your suggestion and the resulting document is awfully small so text can't be read. Any suggestions how to recoup a clear readable document very welcome.
Re: Colorizing scanned grayscale PDF
Posted: 2013-02-02T19:37:08-07:00
by snibgo
For example, green text on a white background:
Code: Select all
convert -density 150 test.pdf lecture2.png
convert lecture2.png -alpha Copy -fuzz 100% -fill White -opaque Gray -background Green -alpha Remove lecture3.png
convert lecture3.png lecture3.pdf
I've shown it as three stages, but you could combine them into one.
Re: Colorizing scanned grayscale PDF
Posted: 2013-02-02T19:42:47-07:00
by visionhappens
snibgo wrote:For example, green text on a white background:
Code: Select all
convert -density 150 test.pdf lecture2.png
convert lecture2.png -alpha Copy -fuzz 100% -fill White -opaque Gray -background Green -alpha Remove lecture3.png
convert lecture3.png lecture3.pdf
I've shown it as three stages, but you could combine them into one.
This is splendid thank you so much!
Re: Colorizing scanned grayscale PDF
Posted: 2013-02-02T19:48:13-07:00
by snibgo
I cross-posted with fmw42. His "+level colors" is far more elegant, and probably quicker, than my version that messes around with alpha. My "-density 150" is what you need for readable text.
Re: Colorizing scanned grayscale PDF
Posted: 2013-02-02T19:51:04-07:00
by fmw42
Since you are starting with PDF which is vector, it has no size. You have to specify the density you want in dpi. You probably need to use supersampling to increase the quality and then resize to the same input size (assuming it is 72 dpi nominally). What I usually do is
convert -density 288 test.pdf +level-colors red,white -resize 25% result
where 72*4=288 and 1/4=25%
But note that your output will be a raster image imbedded in a vector wrapper.
If you want a larger output size change the -resize argument to a larger value or just remove the -resize and adjust the -density to a value that gives you the size output in pixels that you want.
Re: Grayscale matters
Posted: 2013-02-02T20:24:47-07:00
by snibgo
For PDFs that are a single raster image in a vector wrapper, as this one is, I open it in Adobe Reader and control-C the image, which copies it to the clipboard. Then ...
... tells me how many pixels it has.
Then I try a simple convert (at 72 ppi)...
... and arithmetic tells me the most obvious density to use (usually rounded to the nearest multiple of 150).
(This is in Windows7.)