2

Possible Duplicate:
syntax_highlight <source_file> | lpr

I have about 20 Python scripts that I wish to print as PDF. I wish to print them the way GEdit would allow me to, with:

  • Syntax Highlighting
  • Line Numbering
  • Page Headers

Is there any way I can achieve this through the terminal or in any other way which allows for batch printing?

One way is to write a small script to wrap it within alltt or verbatim and compile it with LaTex. But this seems like an overkill.

I have read the question on SuperUser.SE but all the solutions print the code as if it were a story book; no syntax highlighting or any of the above mentioned requirements. Another similar question on SuperUser.SE uses Mac OSX Automator.

1 Answers1

4

You can use a2ps. With the -o OUTPUTFILE.ps option, it produces a postscript file, which then can be converted to pdf using e.g. ps2pdf (from the ghostscript package). Line numbering can be enabled with --line-numbers=1. I do not know if the syntax highlighter of a2ps supports recent python standards.

If you prefer the LaTeX solutions, I would recommend the listings package.

sr_
  • 15,384
jofel
  • 26,758