By Sheldon L | Published at 2020-05-01 | Updated at 2020-05-01 |
Printing itself requires software that converts information from the application you are using to a language your printer can understand. The Linux standard for printing software is the Common UNIX Printing System (CUPS)
.
CUPS
is the underlying software almost all Linux systems use to print from applications like a web browser or LibreOffice. It converts page descriptions produced by your application (put a paragraph here, draw a line there, and so forth) and then sends the information to the printer. It acts as a print server for both local and network printers.
Printers manufactured by different companies may use their own particular print languages and formats. CUPS
uses a modular printing system which accommodates a wide variety of printers and also processes various data formats. This makes the printing process simpler; you can concentrate more on printing and less on how to print.
CUPS
carries out the printing process with the help of its various components:
Configuration Files --> Sheduler
| |
Job File Log File
|
Filter --> PPD Filter --> Backend --> Printer
Scheduler: manages print jobs, handles administrative commands, allows users to query the printer status, and manages the flow of data through all CUPS components.
Configuration Files: The print scheduler reads server settings from several configuration files, two most important art cupsd.conf
and printers.conf
. These and all other CUPS related configuration files are stored under the /etc/cups/
directory.
cupsd.conf
is where most system-wide settings are located; it does not contain any printer-specific details. Most of the settings available in this file relate to network security, i.e. which systems can access CUPS network capabilities, how printers are advertised on the local network, what management features are offered, and so on.
printers.conf
is where you will find the printer-specific settings. For every printer connected to the system, a corresponding section describes the printer’s status and capabilities. This file is generated or modified only after adding a printer to the system, and should not be modified by hand.
Job Files: CUPS stores print requests as files under the /var/spool/cups
directory. Data files (Print queues) are prefixed with the letter d
while control files are prefixed with the letter c
.
Log Files: Log files are placed in /var/log/cups
and are used by the scheduler to record activities that have taken place. These files include: access, error, and page records.
Filters, Printer Drivers, and Backends: CUPS
uses filters to convert job file formats to printable formats. Printer drivers contain descriptions for currently connected and configured printers, and are usually stored under /etc/cups/ppd/
. The print data is then sent to the printer through a filter, and via a backend that helps to locate devices connected to the system.
systemctl status cups
sudo systemctl <enable|disable> cups
sudo systemctl <start|stop|restart> cups
Settings
- Printers
);lsusb
utility will show a line for the printer. Extra software is rarely required.A fact that few people know is that CUPS also comes with its own web server, which makes a configuration interface available via a set of CGI scripts.
This web interface allows you to:
The CUPS web interface is available on your browser at: http://localhost:631.
Some pages require a username and password to perform certain actions, for example to add a printer. For most Linux distributions, you must use the root password to add, modify, or delete printers or classes.
Ctrl-P
lpstat -p -d # get a list of available printers, along with their status
lpstat -a # check the status of all connected printers, including job numbers
lp -d [printer] <filename>
lp -d HP-Officejet-4500-k710 $HOME/.txt
lpq -a # show the queue status
lpadmin # configure printer queues
lpoptions -d printer # set the default printer
# if default printer is set:
lp <filename>
lp -n number <filename> # print multiple copies
# print the output of a program
program | lp
echo string | lp
cancel job-id # cancel a print job
# OR
lprm job-id
lpmove job-id newprinter # move job to new printer
PostScript is a standard page description language. It effectively manages scaling of fonts and vector graphics to provide quality printouts. It is purely a text format that contains the data fed to a PostScript interpreter. The format itself is a language that was developed by Adobe in the early 1980s to enable the transfer of data to printers.
Postscript has been for the most part superseded by the PDF format (Portable Document Format) which produces far smaller files in a compressed format for which support has been integrated into many applications. However, one still has to deal with postscript documents, often as an intermediate format on the way to producing final documents.
enscript
is a tool that is used to convert a text file to PostScript and other formats. It also supports Rich Text Format (RTF) and HyperText Markup Language (HTML)enscript -p psfile.ps textfile.txt # Convert a text file to PostScript
enscript -[n] -p psfile.ps textfile.txt # Convert a text file to [n] columns where n=1-9
enscript textfile.txt # Print a text file directly to the default printer
ps2pdf
and pdf2ps
are part of the ghostscript
package installed on or available on all Linux distributions. As an alternative, there are pstopdf
and pdftops
which are usually part of the poppler
package, which may need to be added through your package manager. Unless you are doing a lot of conversions or need some of the fancier options (which you can read about in the man pages for these utilities), it really does not matter which ones you use.
Another possibility is to use the very powerful convert
program, which is part of the ImageMagick
package. (Some newer distributions have replaced this with Graphics Magick
, and the command to use is gm convert
).
pdf2ps file.pdf
ps2pdf file.ps
pstopdf input.ps output.pdf
pdftops input.pdf output.ps
convert input.ps output.pdf
convert input.pdf output.ps
enscript -p - /var/log/dmesg | ps2pdf - dmesg_direct.pdf
The most common Linux PDF readers are:
evince
is available on virtually all distributions and the most widely used program, evince [file]
.okular
is based on the older kpdf and available on any distribution that provides the KDE environment.ghostView
is one of the first open source PDF readers and is universally available.xpdf
is one of the oldest open source PDF readers and still has a good user base.All of these open source PDF readers support and can read files following the PostScript standard unlike the proprietary Adobe Acrobat Reader, which was once widely used on Linux systems, but, with the growth of these excellent programs, very few Linux users use it today.
At times, you may want to merge, split, or rotate PDF files; not all of these operations can be achieved while using a PDF viewer. Some of these operations include:
In order to accomplish these tasks there are several programs available:
qpdf
: widely available on Linux distributions and is very full-featuredpdftk
: once very popular but depends on an obsolete unmaintained package (libgcj) and a number of distributions have dropped it; thus we recommend avoiding it.ghostscript
: (often invoked using gs
) is widely available and well-maintained. However, its usage is a little complex.qpdf --empty --pages 1.pdf 2.pdf -- 12.pdf # Merge the 1.pdf and 2.pdf, saved to 12.pdf.
qpdf --empty --pages 1.pdf 1-2 -- new.pdf # Write pages 1 and 2 of 1.pdf, saved to new.pdf.
qpdf --rotate=+90:1 1.pdf 1r.pdf # Rotate page 1 of 1.pdf 90 degrees clockwise and save to 1r.pdf
qpdf --rotate=+90:1-z 1.pdf 1r-all.pdf # Rotate all pages of 1.pdf 90 degrees clockwise and save to 1r-all.pdf
qpdf --encrypt mypw mypw 128 -- public.pdf private.pdf # Encrypt with 128 bits
qpdf --decrypt --pasword=mypw private.pdf file-decrypted.pdf # Decrypt
# Combine three PDF files into one:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=all.pdf file1.pdf file2.pdf file3.pdf
# Split pages 10 to 20 out of a PDF file:
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dDOPDFMARKS=false -dFirstPage=10 -dLastPage=20 -sOutputFile=split.pdf file.pdf
You can use other tools to work with PDF files, such as:
pdfinfo
in poppler-utils
utility, it extract information about PDF files, especially when the files are very large or when a graphical interface is not available.flpsed
can add data to a PostScript document. This tool is specifically useful for filling in forms or adding short comments into the document.pdfmod
is a simple application that provides a graphical interface for modifying PDF documents. Using this tool, you can reorder, rotate, and remove pages; export images from a document; edit the title, subject, and author; add keywords; and combine documents using drag-and-drop action.