How to print a single page from PDF file using Linux command line interface (CLI)
30th October 2008
There are several ways to do that, I’ll describe the one which worked for me. Please note, that printing from CLI has an advantage of being able to print out something at work from the comfort of your home and ssh (provided that the printer is on and is loaded with paper).
To extract a single page (or a range of pages), I used pdftops:
pdftops -f 187 -l 187 -paper A4 abstract_book.pdf page_187.ps
Here, -f is the first page, -l is the last, and -paper is paper size.
Alternatives include using pdf2ps (which relies on GhostScript and accepts the same options) and acroread -toPostScript (which uses non-free Adobe Reader in CLI mode to convert PDF to PS).
Now that I have a single-page PS file, I can print it:
cupsdoprint -P S200 -o Resolution=720dpi,Copies=2,PageSize=A4 page_187.ps
Printing options will vary depending on your printer model (use lpoptions -l -P PrinterName to find out possible options and their default values). In the sample line above, S200 is the printer to use for printing, Resolution/Copies/PageSize are all self-explanatory printing options.
Alternative (and, actually, more standard) way to print is by using lpr, but if you run CUPS and KDE then cupsdoprint isn’t any worse.
For more details this FAQ might be helpful. Also, keep in mind that simple shell scripts can automate routine sequential tasks, and that piping helps.
November 3rd, 2008 at 8:09
[snip]
acroread -toPostScript (which uses non-free Adobe Acrobat Reader in CLI mode to convert PDF to PS).
[/snip]
Well, that’s not entirely true. Adobe Reader is free for Windows, Mac and Unix.
One doesn’t need Adobe Acrobat for -toPostScript (which, incidentally, is not even available for Linux).
November 3rd, 2008 at 9:39
Well, if it were free, one could have the source code of it – which is not the case; thus, it is *not* free – instead, it is provided “free of charge”, which doesn’t count as “FREE” in GNU/GPL/Debian sense of word.