======Command-Line Printing====== [[https://en.wikipedia.org/wiki/CUPS|CUPS]] is the printing system used in most modern Linux OS's. It provides a variety of facilities for printing and managing the printing functionality. =====Printing Files===== CUPS understands many different types of files directly, including text, PostScript, PDF, and image files. This allows you to print from inside your applications or at the command-line, whichever is most convenient! Type the following command to print a file to the default (or only) printer on the system: lp filename =====Choosing a Printer===== Many systems will have more than one printer available to the user. These printers can be attached to the local system via a parallel, serial, or USB port, or available over the network. Use the **lpstat(1)** command to see a list of available printers: lpstat -p -d # -p specifies that it should list printers # -d specifies to list the current default printer Print to a specific printer using: lp -d printer_name filename =====Setting the Default Printer===== If you normally use a particular printer, you can tell CUPS to use it by default using the lpoptions(1) command: lpoptions -d printer =====Printing the Output of a Program===== **lp** supports printing from standard input. program | lp # prints using the default printer program | lp -d printer # prints to the specified printer If the program does not provide any output, then nothing will be queued for printing. =====Specifying Printer Options===== For many types of files, the default printer options may be sufficient for your needs. However, there may be times when you need to change the options for a particular file you are printing. The **lp** command allows you to pass printer options using the ''-o'' option: lp -o landscape -o scaling=75 -o media=A4 filename.jpg The available printer options vary depending on the printer. The standard options are described in the Standard Printing Options section below. Printer-specific options are also available and can be listed using the lpoptions command: lpoptions -p printer -l =====Creating Saved Options===== Saved options are supported in CUPS through printer instances. Printer instances are, as their name implies, copies of a printer that have certain options associated with them. Use the **lpoptions** command to create a printer instance: lpoptions -p printer/instance -o name=value ... The ''-p printer/instance'' option provides the name of the instance, which is always the printer name, a slash, and the instance name which can contain any printable characters except space and slash. The remaining options are then associated with the instance instead of the main queue. For example, the following command creates a duplex instance of the LaserJet queue: lpoptions -p LaserJet/duplex -o sides=two-sided-long-edge Instances //do not// inherit lpoptions from the main queue. =====Printing Multiple Copies===== You can use **lp** to print multiple copies with the commands: lp -n num-copies filename lp -n num-copies -o Collate=True filename # print collated =====Listing the Print Queue===== You can list the print queue of a printer using **lpstat**. lpstat -o myprinter This will give you a list of job-ID's for each printer that you can use to act on the job. =====Canceling a Print Job===== The **cancel** command cancels a print job. cancel job-ID =====Moving a Print Job===== The **lpmove** command moves a print job to a new printer or class. lpmove job-id destination =====Standard Printing Options===== Here is a list of some standard and useful printing options. ====Selecting the Media Size, Type, and Source==== The ''-o media=XYZ'' option sets the media size, type, and/or source: lp -o media=Letter filename lp -o media=Letter,MultiPurpose filename The available media sizes, types, and sources depend on the printer, but most support the following options (case is not significant): * “Letter” – US Letter (8.5×11 inches, or 216x279mm) * “Legal” – US Legal (8.5×14 inches, or 216x356mm) * “A4” – ISO A4 (8.27×11.69 inches, or 210x297mm) * “COM10” – US #10 Envelope (9.5×4.125 inches, or 241x105mm) * “DL” – ISO DL Envelope (8.66×4.33 inches, or 220x110mm) * “Transparency” – Transparency media type or source * “Upper” – Upper paper tray * “Lower” – Lower paper tray * “MultiPurpose” – Multi-purpose paper tray * “LargeCapacity” – Large capacity paper tray The actual options supported are defined in the printer’s PPD file in the “PageSize”, “InputSlot”, and “MediaType” options. You can list them using the **lpoptions(1)** command: lpoptions -p printer -l When “Custom” is listed for the “PageSize” option, you can specify custom media sizes using one of the following forms: lp -o media=Custom.WIDTHxLENGTH filename lp -o media=Custom.WIDTHxLENGTHin filename lp -o media=Custom.WIDTHxLENGTHcm filename lp -o media=Custom.WIDTHxLENGTHmm filename where “WIDTH” and “LENGTH” are the width and length of the media in points, inches, centimeters, or millimeters, respectively. ====Setting the Orientation==== The ''-o landscape'' option will rotate the page 90 degrees to print in landscape orientation: lp -o landscape filename The ''-o orientation-requested=N'' option rotates the page depending on the value of N: ^ Option ^ Description ^ | ''-o orientation-requested=3'' | portrait orientation (no rotation) | | ''-o orientation-requested=4'' | landscape orientation (90 degrees) | | ''-o orientation-requested=5'' | reverse landscape or seascape orientation (270 degrees) | | ''-o orientation-requested=6'' | reverse portrait or upside-down orientation (180 degrees) | ====Printing on Both Sides==== You can print two-sided using the ''-o sides=two-sided'' option: lp -o sides=two-sided filename ====Selecting Banner Pages==== The ''-o jobsheets=start,end'' option sets the banner page(s) to use for a job: lp -o job-sheets=none filename lp -o job-sheets=standard,classified filename If only one banner file is specified, it will be printed before the files in the job. If a second banner file is specified, it is printed after the files in the job. The available banner pages depend on the local system configuration; CUPS includes the following banner files: * “none” – Do not produce a banner page. * “classified” – A banner page with a “classified” label at the top and bottom. * “confidential” – A banner page with a “confidential” label at the top and bottom. * “secret” – A banner page with a “secret” label at the top and bottom. * “standard” – A banner page with no label at the top and bottom. * “topsecret” – A banner page with a “top secret” label at the top and bottom. * “unclassified” – A banner page with an “unclassified” label at the top and bottom. ====Holding Jobs for Later Printing==== The ''-o job-hold-until=when'' option tells CUPS to delay printing until the ''when'' time, which can be one of the following: ^ Option ^ Description ^ | ''-o job-hold-until=indefinite'' | print only after released by the user or an administrator | | ''-o job-hold-until=day-time'' | print from 6am to 6pm local time | | ''-o job-hold-until=night'' | print from 6pm to 6am local time | | ''-o job-hold-until=second-shift'' | print from 4pm to 12am local time | | ''-o job-hold-until=third-shift'' | print from 12am to 8am local time | | ''-o job-hold-until=weekend'' | print on Saturday or Sunday | | ''-o job-hold-until=HH:MM'' | print at the specified UTC time | ====Releasing Held Jobs==== Aside from the web interface, you can use the **lp** command to release a held job: lp -i job-id -H resume ====Setting Job Priority==== The ''-o job-priority=NNN'' option tells CUPS to assign a priority to your job from 1 (lowest) to 100 (highest), which influences where the job appears in the print queue. Higher priority jobs are printed before lower priority jobs, however submitting a new job with a high priority will not interrupt a job. ====Specifying Output Order==== The ''-o outputorder=normal'' and ''-o outputorder=reverse'' options specify the order of the pages. Normal order prints page 1 first, page 2 second, and so forth. Reverse order prints page 1 last. ====Selecting a Range of Pages==== The ''-o page-ranges=pages'' option selects a range of pages for printing: lp -o page-ranges=1 filename lp -o page-ranges=1-4 filename lp -o page-ranges=1-4,7,9-12 filename As shown above, the “pages” value can be a single page, a range of pages, or a collection of page numbers and ranges separated by commas. The pages will always be printed in ascending order, regardless of the order of the pages in the “page-ranges” option. The default is to print all pages. ====Selecting Even or Odd Pages==== Use the ''-o page-set=set'' option to select the even or odd pages: lp -o page-set=odd filename lp -o page-set=even filename ====N-Up Printing (Multiple Document Pages on a Page)==== The ''-o number-up=value'' option selects N-Up printing. N-Up printing places multiple document pages on a single printed page. CUPS supports 1, 2, 4, 6, 9, and 16-Up formats; the default format is 1-Up: lp -o number-up=1 filename lp -o number-up=2 filename lp -o number-up=4 filename The ''-o page-border=value'' option chooses the border to draw around each page: ^ Option ^ Description ^ | ''-o page-border=double'' | draw two hairline borders around each page | | ''-o page-border=double-thick'' | draw two 1pt borders around each page | | ''-o page-border=none'' | do not draw a border (default) | | ''-o page-border=single'' | draw one hairline border around each page | | ''-o page-border=single-thick'' | draw one 1pt border around each page | The ''-o number-up-layout=value'' option chooses the layout of the pages on each output page: ^ Option ^ Description ^ | ''-o number-up-layout=btlr'' | Bottom to top, left to right | | ''-o number-up-layout=btrl'' | Bottom to top, right to left | | ''-o number-up-layout=lrbt'' | Left to right, bottom to top | | ''-o number-up-layout=lrtb'' | Left to right, top to bottom (default) | | ''-o number-up-layout=rlbt'' | Right to left, bottom to top | | ''-o number-up-layout=rltb'' | Right to left, top to bottom | | ''-o number-up-layout=tblr'' | Top to bottom, left to right | | ''-o number-up-layout=tbrl'' | Top to bottom, right to left | ====Scaling to Fit==== The ''-o fitplot'' option specifies that the document should be scaled to fit on the page: lp -o fitplot filename ====Raw or Unfiltered Output==== The ''-o raw'' option allows you to send files directly to a printer without filtering. This is sometimes required when printing from applications that provide their own “printer drivers” for your printer: lp -o raw filename =====Printing Code===== ====Pretty Printing==== The ''-o prettyprint'' option puts a header at the top of each page with the page number, job title (usually the filename), and the date. Also, C and C++ keywords are highlighted, and comment lines are italicized: lp -o prettyprint filename