4

The goal is to print a set of *.cpp files on a network printer, but... in a way that the (color) printer prints the files like they appear in the c++ editor including the colors and highlighting. And all of this from the command line.

I succeeded in sending all the files to the network printer but they are (of course) all printed in black and white (text) format.

I used : lp -d 'printername' *.cpp

Is there a way to open the files in something like emacs and pass the print command to emacs from the command line?

BTW: I'm on mac OS X.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
tombo
  • 63
  • 2
  • possible duplicate: http://unix.stackexchange.com/questions/43520/how-can-i-print-good-looking-code – ixtmixilix Mar 06 '13 at 22:29
  • Check out an example [here](http://user.it.uu.se/~embe8573/latex/code_tex_example/) of what @Bernhard [speaks](http://unix.stackexchange.com/a/67093/13136) of. While it is SQL and not C++, the principle should be the same. – Emanuel Berg Mar 08 '13 at 01:14

2 Answers2

2

I would be highly surprised if you can do such a thing directly with lp. The following is the easiest solution I could think of.

There is a LaTeX package that can help you a lot: minted. You could write a script, that generates a .tex file (probably by \input{}) and uses this package for syntax-highlighting. Then you compile it, to obtain a .pdf with the colors that you wish. Sending it to printer is than the remaining step.

Bernhard
  • 11,992
  • 4
  • 59
  • 69
1

I think enscript might help you. I don't use it for code-formatting myself, but I do use it to print timestamps on text files I print.

I have a shell script in my ~/bin directory that will save it as a PostScript file that I can then print (directly printing, is of course an option). If that is helpful to you, I have it in a Gist here: https://gist.github.com/ryanaghdam/5103528. It takes a text file as the first argument ($1).

It is not installed on Mac OS X by default, but is available in Homebrew.

Ryan A.
  • 1,201
  • 9
  • 3