views:

2168

answers:

8

What's the best way to print out code (e.g. for a code review)? Eclipse's print option only does portrait (afaict), wich is unreadable for longer lines of code. Opening and printing all files in an editor like gedit is a pain.

Is there some batch code print program available? Or is there some magic command line chain that does it for me?

Of course, I need both line numbers and syntax highlighting.

+4  A: 

Printing out source code on paper is a colossal waste of trees. What other solutions have you considered?

I might suggest a product such as Crucible that lets you do code review collaboratively, online in a web browser.

Greg Hewgill
We'd love to use crucible. It's too expensive tho. Anyway, this is only a handful of classes, so it's not too bad. And the code review was only an example, there's other cases where printing out code is useful.
Sietse
Obviously you make a point Greg but it does not answer the question and I'd like to get a good answer to this question
allesklar
@allesklar: Not all questions, even programming-related ones, ought to be "answered". e.g., ones asking how to defeat popup blockers or SSL security warnings are probably best not answered. :-)
Chris Jester-Young
This is a reasonable question. Printing source code is no less sensible than printing anything else, and printers serve a purpose.
Peter Hilton
-1 for high-horse sitting
jgubby
A: 

You may have a tonne of code and may need to have it all available for your review. Printing the code is not a scalable solution unless it is probably just a few pages.

I would suggest:

  1. Use some online code review tool like Crucible or Google's Rietveld (http://code.google.com/p/rietveld/)
  2. Project your code on a large screen in your conference room. It it even better than seeing it on paper.
Ather
+1  A: 

I've found that gvim gives you syntax coloring, line numbers and the ability to print in landscape mode.

We set up the default print options, associate the files (*.c, *.h, etc) with gvim, then just select all the files and right-click, print.

This is for Windows, I'm not sure how you'd do the same thing for non-Windows platform but you didn't specify which you wanted.

paxdiablo
+3  A: 

a2ps will format code in portrait or landscape mode, with or without line numbers, and has a multitude of other options. It does syntax highlighting for a good number of languages.

http://www.gnu.org/software/a2ps/

Joshua Swink
damn beat me to it...
Omar Kooheji
+4  A: 

I used to use a2ps which resulted in a pretty printed postscript from most languages.

I'm fairly sure you can just tell it to print to a printer.

UPDATE

Here is a link to a page that describes pretty printing using a2ps

Omar Kooheji
+1  A: 

I rarely print code, but when I do, I just use my usual editor, SciTE. It offers a decent control over printing.
It also accepts a command line option to print and exit.

PhiLho
+2  A: 

I use Highlight (German on the top half of the page, English at the bottom half). I can get code and generate HTML, PDF, whatever and give it a color scheme (there are a number of color schemes available, and I think you can make your own, but I never saw the need for that).

Thomas Owens
A: 

As a printer-interface for any of the above solutions for indentation and syntax highlighting, I've found printFile indispensable and unequaled for general-purpose multi-column printing for years. It has just the right set of switches for wrapping, column-width, font-size, orientation, etc.; and trivial overhead. And it has postscript support.

le dorfier