How to print only even or odd pages (HP LaserJet 1018)
Solution 1
If you're trying to print from libreoffice, there is an option to print left or right pages only.
Open the print dialog, then choose tle layout tab and choose the appropriate option under the page sides dropdown.
If you're printing a pdf, Document viewer has a similar option under the page setup tab of the print dialog box.
Solution 2
you could also do this from the command-line using the lp
command:
$ PDF_NAME='my_document.pdf'
$ NUMBER_PAGES=15
# print odd pages
$ lp "${PDF_NAME}" -P $(seq -s ',' 1 2 "${NUMBER_PAGES}")
# print even pages:
$ lp "${PDF_NAME}" -P $(seq -s ',' 2 2 "${NUMBER_PAGES}") -o outputorder=reverse
# may have to add '-o orientation-requested=6' to rotate by 180°
the seq
commands just output the comma-separated list of pages as needed for the lp
command:
$ NUMBER_PAGES=15
$ seq -s ',' 1 2 "${NUMBER_PAGES}" # -> 1,3,5,7,9,11,13,15
$ seq -s ',' 2 2 "${NUMBER_PAGES}" # -> 2,4,6,8,10,12,14
the commands above will print to the default printer if you have one defined. otherwise you will need to find the printer name and specify it on the command line:
# find the available printers and the default printer:
$ lpstat -p -d
# printer my_printer is idle. enabled since ...
# direct lp to use the desired printer
$ lp -d my_printer ...
if you need to get the number of pages automatically (there may be a nicer way to do this) you could use pdfinfo
from the poppler-utils
package:
$ NUMBER_PAGES=$(pdfinfo "${PDF_BOOK}" | grep 'Pages:' | cut -d ':' -f 2 | xargs)
Solution 3
Based on hiro protagonist
answer, I am trying to save everyone working out the details to make a function out of it.
Run lpstat -p -d
to find your printer's name and replace printer_name
with the name of your printer in the below scripts.
Once the below functions are saved in ~/.bashrc
or ~/.zshrc
or similar, they can be invoked as a command from the shell like:
printOdd <file>
printEven <file>
function printOdd() {
NUMBER_PAGES=$(pdfinfo $1 | grep 'Pages:' | cut -d ':' -f 2 | xargs)
lp "$1" -P $(seq -s ',' 1 2 "${NUMBER_PAGES}") -d printer_name
}
function printEven() {
NUMBER_PAGES=$(pdfinfo $1 | grep 'Pages:' | cut -d ':' -f 2 | xargs)
lp "$1" -P $(seq -s ',' 2 2 "${NUMBER_PAGES}") -d printer_name
}
PS: You need to have pdfinfo
installed in your system
Related videos on Youtube
mehdix
Updated on September 18, 2022Comments
-
mehdix almost 2 years
Sometimes I print two sided documents. Therefore I first print odd pages then I use the same papers in reverse order to print even pages(I just check reverse while printing).
I do this operation manually, it means that I enter page numbers my self, like: 1,3,5,7,9 for odd pages then 2,4,6,8,10 for even pages.
The problem is when I want to print a large number of pages this is hard to do. Imagine 100 pages. Moreover I may make some mistakes in between.
Is there any way to define odd pages in general print dialog of ubuntu?
I am using Ubuntu 12.10 with default hplib for printing.
-
Rinzwind about 11 yearsThis might depend on the printer... so make/model/brand might be useful. And it might also be depending on the software you use.
-
mehdix about 11 yearsMy printer is HP LaserJet 1018. I use the hplib for printing. The one which is shipped with Ubuntu 12.10.
-
-
mehdix about 11 yearsNo, I'm trying to pring pdf files. I view pdf files using Document-Viwer.
-
mehdix over 10 yearsI gained voting privilege today.
-
Walter Tross about 10 yearsFor printing pdf files with Document Viewer, the option in the Print dialog box is (as you said) in the Page Setup tab, and is called Only print, with values All sheets, Even sheets and Odd sheets