lpr: How to specify the page range "3 to end"?

lpr ranges

I'm not sure about the "end" bit but you can try this method if you know the last page number in the series:

$ lpr -P myprinter -o page-ranges=3-10

lpoptions

You can try querying the printer to see what options it has to offer.

$ lpoptions -p <printer name> -l

Example

$ lpoptions -p mfc-8480dn -l
OptionTrays/Number of Input Trays: 1Trays *2Trays
PageSize/Media Size: *Letter Legal Executive A4 A5 A6 Env10 EnvMonarch EnvDL EnvC5 EnvISOB5 EnvISOB6
BrMediaType/BrMediaType: *PLAIN THIN THICK THICKERPAPER2 BOND TRANSPARENCIES ENV ENVTHICK ENVTHIN
InputSlot/InputSlot: MPTRAY TRAY1 TRAY2 *AUTO
Duplex/Duplex: DuplexTumble DuplexNoTumble *None
Resolution/Resolution: 300dpi *600dpi 2400x600dpi 1200dpi
TonerSaveMode/Toner Save: *Off On
Sleep/Sleep Time [Min.]: *PrinterDefault 2minutes 10minutes 30minutes

psselect

If you have a postscript (PS) stream that you're attempting to send to the lpr command you can use the command psselect to select ranges of pages from the postscript stream.

Sample data

  • PDF: A Sample PDF file is available here, titled: example.pdf
  • text: We can make a example .txt file like so:

    $ seq 1000 > example.txt
    

Examples

text

using enscript

$ enscript sample.txt -o - | psselect -p3- | ps2pdf - textfile.pdf
[ 16 pages * 1 copy ] left in -
[3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] 
Wrote 14 pages, 30417 bytes

$ enscript sample.txt -o - | psselect -p3-5 | ps2pdf - textfile.pdf
[ 16 pages * 1 copy ] left in -
[3] [4] [5] Wrote 3 pages, 16329 bytes

using paps

$ paps sample.txt - | psselect -p3- | ps2pdf - textfile.pdf
[3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] 
Wrote 17 pages, 44159 bytes
[saml@grinchy bin]$ paps sample.txt - | psselect -p3-5 | ps2pdf - textfile.pdf
[3] [4] [5] Wrote 3 pages, 15851 bytes

PDF

$ pdftops example.pdf - | psselect -p3- | ps2pdf - pdffile.pdf
[3] [4] [5] [6] [7] [8] [9] [10] Wrote 8 pages, 687796 bytes

$ pdftops example.pdf - | psselect -p3-5 | ps2pdf - pdffile.pdf
[3] [4] [5] Wrote 3 pages, 372422 bytes

Sending to lpr

You can change the above commands so that instead of piping the output to ps2pdf, send it to lpr, like so:

$ pdftops example.pdf - | psselect -p3-5 | lpr -P myprinter

What else?

You can control the number of columns using either lpr or enscript or paps. You can also control the duplex (double sided style) using lpr too.

Examples

2 columns

$ paps --columns=2 sample.txt - | psselect -p3-5 | ps2pdf - textfile.pdf
[3] [4] [5] Wrote 3 pages, 22244 bytes

$ enscript -2 sample.txt -o - | psselect -p3-5 | ps2pdf - textfile.pdf
[ 8 pages * 1 copy ] left in -
[3] [4] [5] Wrote 3 pages, 19700 bytes

$ pdftops example.pdf - | psselect -p3-5 | lpr -o number-up=2

duplex

$ pdftops example.pdf - | psselect -p3-5 | lpr -o number-up=2 -o sides=two-sided-short-edge

References

  • Using the Printing System
  • Printing from DICE project

If you specify a number that's more than the actual number of pages, Cups ignores the request for pages beyond the end.

lpr -o page-ranges=3-999999999 …

(Don't use more than nine 9s as Cups will silently wrap numbers around beyond 231.)


Back when this question was asked, Cups could do it on its own. If you left out one of the sides of the range, it meant the end. page-ranges=-42 was a (rather useless) shortcut for page-ranges=1-42. To specify a range that goes till the end of the file, you could leave the end part blank: page-ranges=3-. Sadly this feature seems to have disappeared.

Tags:

Printing

Cups