Americas

  • United States
sandra_henrystocker
Unix Dweeb

Using the Ip command to print from Linux systems

How-To
Mar 25, 20195 mins
Linux

The lp command on Linux systems provides numerous options for printing, such as multiple pages per sheet and page borders, but also just a few quirks to keep you on your toes.

The lp command on Linux systems offers a range of printing options that allow you to print documents using a variety of options. In this post, we take a look at some that offer interesting possibilities.

The recent Printing from the Linux command line post covers printing in double-sided and portrait mode. In this post, we’ll look at printing:

  • Multiple pages per sheet
  • Specific pages or page ranges
  • Pages with borders
  • Multiple copies

How to print multiple pages per sheet

With lp, you can print as many as 16 pages of a document on one side of a single sheet of paper. To specify the number of pages to print on a page, use the  lp -o number-up=# command (e.g.,  lp -o number-up=16 mydoc). If your document doesn’t contain as many pages as you’ve requested in the layout, that’s OK. The page will simply have an empty area.

You also get to choose how those pages are arranged. The default is to print left to right and top to bottom (also referred to as “lrtb”). This is clearly the most common way to order content.

 1  2  3  4
 5  6  7  8
 9 10 11 12
13 14 15 16

If instead you choose “btrl”, your output pages would be organize like this:

16 12  8  4
15 11  7  3
14 10  6  2
13  9  5  1

Of course, that just represents the order of the pages. If the pages themselves contain normal text, those printouts are going to include some very tiny letters, and you might need a good magnifying glass to read them!

A generally more useful choice is to print two pages per sheet. This format can be useful if you want to print a booklet in 8.5″ by 5.5″ (8.5″ by 11″ folded) format.

portrait penguin Sandra Henry-Stocker

Portrait — 2 per page

landscape penguin Sandra Henry-Stocker

Landscape — 2 per page

Depending on whether you’re printing portrait or landscape pages, your overall page orientation will adjust itself. These two page images illustrate how a 2-page-per-sheet printout of a portrait-oriented document and a 2-page-per-sheet printout of a landscape-oriented document compare.

A similar strategy would be used to place 4, 8, or 16 images on a single page. The nice part of this is that the lp command figures out how to arrange the pages, and you don’t have to specify the placement.

How to print specific pages

You can elect to print only some of the pages in a particular document. To specify individual pages or ranges of page, you would use the -P option. For example, you might elect to print the first four pages of a document with a command like this:

$ lp -P 1-4 mydoc.pdf

It’s important to keep in mind that -P refers to the print pages in your print image, NOT the pages in your original document. If you are printing two pages per sheet, for example, you’ll have half as many print pages as in your original document. To print only the first four pages in this case, you would use a command like this:

$ lp -o number-up=2 -P 1-2 mydoc.pdf

To print pages 3-6, you would request -P 2-3.

NOTE: Pages selected for use with the -P option can be individual pages (e.g., -P 3,4), ranges (e.g., -P 3-5) or a combination (e.g., -P 3-4, 7) but must be in page order (smallest to largest) or lp will spit out a “Bad page-ranges” error.

How to print pages with borders

To add a border to your printed pages, use the page-border option (e.g., -o page-border=single). The options for page borders include:

  • Single
  • Double
  • Single-thick
  • Double-thick

How to print multiple copies

To print multiple copies of a document, just add the -n option (e.g., -n 11) to your command. For example:

$ lp Penguin.pdf -n 8

What you can and cannot do with the Ip command

While the lp command is wonderfully flexible, there are print jobs that it’s not set up to handle. A two-page-per-sheet option cannot, for example, provide the most useful format for a booklet. A two-sided, two-page-per-sheet document with eight pages, for example, would ideally be printed with pages 8 and 1 on one side of the sheet and pages 2 and 7 on the other. Folded in the middle along with a second sheet containing pages 6 and 3 on one side and 4 and 5 on the other, it would make a nice eight-page handout. Other tools are needed for this kind of project — or a document with pages reordered to make it work.

Quirks with the Ip command

With all the options available, lp is wonderfully flexible, but can be fairly complicated. Make sure to include the -o specification before each option that doesn’t have its own unique option designation (such as -n) or you’ll confuse it. And keep in mind that for multiple-page-per-sheet documents, the page number that you specify will refer to the print image’s pages — not the pages in your original file.

It’s a good idea to test your more complicated print specifications before you start printing large documents just to be sure that you got them right before you waste a lot of paper. The lp man page explains all the command’s options, but it might take a little practice to be confident that you’ll get what you expect when you put a number of them into use.

sandra_henrystocker
Unix Dweeb

Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she's chasing the bears away from her bird feeders.

The opinions expressed in this blog are those of Sandra Henry-Stocker and do not necessarily represent those of IDG Communications, Inc., its parent, subsidiary or affiliated companies.

More from this author