laser sword

22 06 2011

If you ever wanted to print colored text with a monochrome laser printer, you might have encountered the same problem I had: You just can’t read the light blue letters.
The following script can resolve the problem. It converts the pdf to a ps file and (as far as I understand) sets the font color to black (completeley black, not greyscale, halftonig etc.). The output file is a pdf again.
$ pdf_uncolor filename.pdf

#!/bin/bash
# adapted from http://superuser.com/questions/200378/converting-a-pdf-to-black-white-with-ghostscript
tempfile=/tmp/pdf_uncolor_temp.ps
rm $tempfile 
pdf2ps $1 $tempfile
gs -o bw_$1 -sDEVICE=pdfwrite -c "/setrgbcolor{0 mul 3 1 roll 0 mul 3 1 roll 0 mul 3 1 roll 0 mul add add setgray }def" -f $tempfile
rm $tempfile


Thanks to superuser.com for the template. Though I don’t completely understand the ps operations, I was able to adapt them to my needs.