Friday, December 27, 2019

lp - the Linux printing command
The lpstat -p command displays the status of a printer while lpstat -p -d also lists available printers.
With the -n option, the lp command allows you to specify the number of copies of a printout you  want.
$ lp -n 11 agenda
To cancel a print job, you can use the cancel or lprm command. If you don't act quickly, you might see this:
$ cancel 229
cancel: cancel-job failed: Job #229 is already completed - can't cancel.
To print in landscape mode, you would use the landscape option with the lp command.
$ lp -o landscape penguin.jpg
-o media=size
Sets the page size to size. Most printers support at least the size names "a4", "letter", and "legal".
-o number-up={2|4|6|9|16}
Prints 2, 4, 6, 9, or 16 document (input) pages on each output page.
-o orientation-requested=4
Prints the job in landscape (rotated 90 degrees counter-clockwise).
-o orientation-requested=5
Prints the job in landscape (rotated 90 degrees clockwise).
-o orientation-requested=6
Prints the job in reverse portrait (rotated 180 degrees).
-o print-quality=3
-o print-quality=4
-o print-quality=5
Specifies the output quality - draft (3), normal (4), or best (5).
-o sides=one-sided
Prints on one side of the paper.
-o sides=two-sided-long-edge
Prints on both sides of the paper for portrait output.
-o sides=two-sided-short-edge
Prints on both sides of the paper for landscape output.

-t "name"
Sets the job name.
-H hh:mm
-H hold
-H immediate
-H restart
-H resume
Specifies when the job should be printed. A value of immediate will print the file immediately, a value of hold will hold the job indefinitely, and a UTC time value (HH:MM) will hold the job until the specified UTC (not local) time. Use a value of resume with the -i option to resume a held job. Use a value of restart with the -i option to restart a completed job.

To print from command line we need, first of all, to know which printers are available for our system and how are named. To do that, we use following command:
$ lpstat -a
-a [printer(s)]Shows the accepting state of printer queues. If no printers are specified then all printers are listed.
-lShows a long listing of printers, classes, or jobs.

lp -d <printername> -o ColorModel=CMYK <filename.extension>
Set your printer default to color
sudo lpoptions -p the_printer -o <name=value>

Example: To make banana-color print in color by default on your computer:

sudo lpoptions -p the_printer -o ColorModel=CMYK

To change back to black and white:

sudo lpoptions -p the_printer -o ColorModel=Gray

Note Option commands vary by printer and model. To see available options for a specific printer:

lpoptions -p printername -l
Maybe you are looking for lpoptions ?
Use lpoptions -l in order to know what's the name for your printer.
You can play it like thi (example with an HP Photosmart) :
lp -o scaling=//100// -oColorModel=KGray image.jpg

lpoptions -d the_printer -l | grep -i color
        lp -d P file.pdf  (send file to printer P - e.g. P=5)
        lp -o sides=one-sided file.pdf  (to each page on one side only)
        lp -o ColorModel=color file.pdf    (print in color)
        lp -o sides=two-sided-short-edge  file.pdf  (duplex along short edge instead of long)
        lp -o page-ranges=1  (print just page 1)
        lp -o page-ranges=1-4,7,9-12

You can combine these commands, for example:
        lp -o sides=two-sided-short-edge -o ColorModel=color file.pdf  (useful for printing tri-fold brochures)
Use the lpoptions command to save these options for later use. For example, you might want to do color printing to the printer on another floor, reserving the printer on your own floor for the normal grayscale prints. This command will ensure that anything you send to the 5th floor printer will be printed in color:
        lpoptions -d 5  ColorModel=color
your lpoptions commands are saved in the file ~/.cups/lpoptions. Typing lpoptions by itself will show you what your current printer setup is.
Checking the queue and cancelling jobs
Use the lpstat command to check the status of a queue and cancel to cancel jobs
       lpstat -d5 -t   (checks jobs on queue 5)
       cancel  5-241   (deletes job 5-241 from queue 5)
You can also cancel jobs using the printer icon which will appear in the top right hand corner of your screen when you start your job. To do this, open the printer icon, right click on your job and select cancel (not delete).

lpoptions -d the_printer -o ColorModel=color
- not work
The setting to print color as grey (from the ppd) is valid an is processed.
HPPJLColorAsGray/Print Color as Gray: False HighQuality * BlackInkOnly 
But the settings from the actual printout "overwrite" the default values (what makes sense to me) and in case color is in an document an this is printed with default values -- the colour ink is used. This behaviour can be controlled in the print dialogue generally. E.g. in libreoffice you can use an option "print text in black ink" this would result in real black text (not mixed as black from colors).
In LaTeX you can use \usepackage[monochrome]{xcolor} to force all text to black an so the use of the black ink.
Im my case I wanted to directly print to the print queue even though the default was set in the ppd to use BlackInkOnly it was not the case. After I added this option additionally as parameter to my print command it worked as I want it to be: color is printed in gray and only the black ink is used.
lpr  -P<printqueue> -o HPPJLColorAsGray=BlackInkOnly ...
  1. Set the system's default printer.

    # lpadmin -d [printer-name]
    -d printer-name specifies the name of the printer you are assigning as the system's default printer. If you don't specify printer-name, the system is set up with no default printer.
  2. Check the system's default printer.

    # lpstat -d
# lpadmin -d [printer-name]

-d printer-nameName of the printer you are assigning as the system's default printer. If you don't specify printer-name, the system is set up with no default printer.
This command prints the ".profile" file to the printer named "Sales". The -d option specifies the destination.
lp -dSales file1 file2 file3
This command prints the three files "file1", "file2", and "file3" to the printer named "Sales".
lp -i Sales-101 -H hold
This command places the print request Sales-101 on hold.
lp -i Sales-101 -H resume
This command resumes the print request Sales-101. The print request starts printing from page one unless you instruct it otherwise.
lp -i Sales-101 -H resume -P 4-
This command resumes the print request Sales-101, starting with page 4 of the print job. Note that the final hyphen (following the "4") is required.
The "lp" command can also be used as part of a pipeline. For instance, the following command will print the output of the "ps -ef" command to the default printer:
ps -ef | lp
Save Ink– Use grayscale as the default print setting and only switch to full color on the final version or for client-facing documents.
Fonts Matter– In 2014, a teenager discovered the government could save more than $200 million a year by using Garamond instead of Times New Roman when printing documents. You probably won’t save that much, but using thinner and lighter fonts like Garamond or Evergreen can save on ink.
Start Selectively Printing

Pull, not push
Many enterprise printing systems now offer a 'pull-printing' option. Instead of sitting at your desk and sending documents to a remote printer, pull-printing requires the user to manually enter a security code on the printer itself. This provides greater security, reduces uncollected paper left in the printer - and might even make people think twice before pushing the 'Print' button.


Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

Popular Posts