Skip to content

Advanced Linux Printing

Printing Your Program Code

Since most program code is simple ASCII text, you can print it without any further processing using the lpr command. However, using the enscript program, you can get much improved output and page usage when printing your code. First of all, we recommend that you read the manual page for enscript but here are some command lines you can use to get your program code (and other ASCII text files) to print nicely. By default, enscript will send its output directly to your default printer (see above for how to change it). However, you can use a -P option to select a different printer or even make the output go to a Postscript file. Assuming you are trying to print “code.c“, here are some useful command lines:

  • Print multiple columns:  enscript –columns=2 code.cSample Output:

Linux Printing- 2columns

  • Print in landscape mode:  enscript --landscape code.c

    Sample Output:

Linux Printing- landscape

  • Print with syntax highlighting:  enscript --pretty-print --color code.c(Note: You only need the color option when printing to a color-capable printer.)

    Sample Output:

Linux Printing- pretty_print

There are many other options explained in the manual page, for example --fancy-header which gives your text a useful header. You can combine these options to create efficient and attractive output of your code. For example:

enscript --pretty-print --color --landscape --columns=2 --fancy-header code.c

(Read the man page for the equivalent short options, in this case:  enscript -2rGE –color)

This produces very attractive and page-saving output:

Linux Printing- optimal_print

There are many more options to enscript, including ways to change the font, create text borders, create line numbers, etc.  Again, read the manual page for more information.


Printing Multiple Pages Per Sheet

You can easily print multiple pages per sheet of paper. To do this, you must have a Postscript (PS) file of what you want to print or generate Postscript from a command and send it to a pipe. The command to use to print multiple pages per sheet is psnup. There are many options, so you should read the manual page (man psnup) for more information. The psnup command acts as a filter, meaning it takes a PS file as input and sends a new PS file to its output. To print this output file you can send it to a file using something like:

psnup -4 >

and then print the file using an appropriate lpr command. However, if you have no interest in retaining the output PS file, just use a pipe like this:

psnup -4 | lpr

Through the use of pipes you can generate some very useful output in one single command. For example, you want to print code.c with syntax highlighting, fancy header, four pages per sheet, and duplexed (double-sided). You can do this with the following single command:

enscript --fancy-header --pretty-print --landscape --color -p - code.c | psnup -4 -l | lpr -Phydra -Z duplex

(Note: The -l option tells psnup that your input is in landscape format. For more info, check the appropriate manual pages.)

Sample Output:

Linux Printing- 4up

One good use for psnup is to use it to print PDF files two or for pages to a sheet of paper. Just select the “File” button when printing the PDF from Adobe Acrobat and then use psnup -4 | lpr to print that file (of course you can add additional options to psnup or lpr).

The flagship campus of the University of Tennessee System and partner in the Tennessee Transfer Pathway.