If you are on Linux and want to print some code and also make it look pretty then check out a2ps (Any to postscript filter). Of course if you can avoid printing in the first place and saving paper and trees and make it greener that is ideal - however there are times that is not possible. I tried printing from CDT, but the printing options from CDT just looks plain ugly and big fonts and can spread over 10 pages for a simple code file (spanning 293 lines). Sure I can tweak the font in CDT, but that is the only option available - enter a2ps . It seems to have more options, but I have not had a chance to play with those.

For example if I wanted a C++ code file called MOOSSniffer.cpp and “print it” out as PDF then use the command shown below. Here “-E” is the option to make the code look pretty and the “-P pdf” is the option for printing to PDF. Next comes the source file (you can also provide multiple files such as *.cpp) and finally the -o option is for the output filename. Of course you will need to install a2ps, which you can do via System -> Admin -> Synaptic Package Manager

a2ps -E -P pdf MOOSSniffer.cpp -o MOOSSniffer.pdf

Now, for some reason the resulting PDF could not be opened in Acrobat Reader, but on my Ubuntu machine, I could open it using the “Document Viewer” and print it using that. And in case you were curious, the pretty page option came to 3 pages instead of the original 10.

Also no trees were harmed in the making of this post - my printouts were all to PDF and not real paper - but in the end I did print out the 3 page version. :)