Linux 15 - Printing on Linux

By Sheldon L Published at 2020-05-01 Updated at 2020-05-01


CUPS


Configuration Files --> Sheduler
                        |     |
                  Job File   Log File
                        |
                    Filter --> PPD Filter --> Backend --> Printer

Managing CUPS

systemctl status cups
sudo systemctl <enable|disable> cups
sudo systemctl <start|stop|restart> cups

Configuring a Printer from the GUI

Adding Printers from the CUPS Web Interface

Printing Operations

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

Manipulating Postscript and PDF Files

Postscript

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

Converting between PostScript and PDF

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

Viewing and Manipulating PDF

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

Using Additional Tools