syntax_highlight <source_file> | lpr

You can use vim.

vim -c hardcopy -c quit /path/to/file

This will print the file and quit immediately. By default, vim prints with syntax highlighting.

If you need to print from stdout of some command, you can do this:

cat some_file.c | vim -c hardcopy -c 'quit!' -

If you want to save the .ps for later, you can do that by adding redirection to the hardcopy command, like so:

vim -c 'hardcopy > /path/to/saved.ps' -c 'quit' /path/to/file

Vim lets you set lots of printing-related options, so you might want to see the documentation if you want to tweak it. Of course, there are lots of syntax highlighting options as well.


There are several programs that pretty-print various programming languages to Postscript, which don't require any third-party software to run:

  • a2ps
  • enscript
  • trueprint

If you are willing to go via LaTeX, you have more options. Going via LaTeX is mostly useful if you want to include code and something else in the same document; otherwise it's overkill.

  • highlight
  • The listings package (runs on any LaTeX installation, no preprocessing required)
  • lgrind
  • source-highlight

In Gedit, the standard editor for gnome, you can print to file, choose Postscript (default PDF) and mark on the third tab, to use highlightening, which is off as default, which produces a nice ps-file for me.

And Gedit has a lot of syntax files, to serve many programming languages, HTML, SQL, XML, rc-files, you name it.