The result is worth it, though. Black is real black, and since it produces vector graphics the edges are not pixelated, even if you zoom in.
|Original scan, grey and pixelated.|
|After the vectorizing, black and white, and no visible pixelation (you may distinguish pixels here, since I converted the image from pdf to png).|
Here comes a way to do it in one command from a terminal.
Install the toolsInkscape uses potrace to trace bitmaps. Luckily, potrace is available as a standalone program. You need to install it. I used the package manager fink to do that:
You need also pdfimages to extract images from the original pdf. It is included in xpdf, which I also installed with fink:
I did not need to install mkbitmap or ghostscript (
gs), but I might have installed them earlier with other programs. If you get complaints about either of them, you'll need to install them as well.
Create a scriptThe process of conversion is as follows:
- Extract images from the original pdf
- Threshold the images to get black and white pixels only
- Trace the bitmap images to vectors and generate pdf files
- Merge the pdf files into one single pdf
Here is the script that does all of that:
# Create ppm images, one per pdf page.
pdfimages $1.pdf $1_conv_temp
# Create pbm images (no grey levels) from the ppm.
mkbitmap $1_conv_temp*.ppm -t 0.48
# Create pdf files from the pbm images, one per original page.
potrace -b pdf -r 150 $1_conv_temp*.pbm
# Combine the several pdf files into one.
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
# Clean up
Copy this to a new file, which you can call vectorize.sh, for example.
Then you need to make this script executable with:
Make it accessible from anywhere by adding the scripts location to your path.
Run!When you are setup, run this script in a terminal:
and your file
original.pdfwill be copied and vectorized to