Skip to content

Printing

Printing in Linux requires software that:

  1. Converts your document from an application’s format into a language the printer understands
  2. Sends the data to the right device (local USB, network, or remote)

The Linux standard for this is CUPS (Common UNIX Printing System).


CUPS acts as a print server for both local and network printers. It uses a modular architecture to accommodate many different printer models and data formats - different printers may speak completely different page description languages, and CUPS handles the translation.

CUPS architecture

CUPS processes a print job through several components:

ComponentRole
SchedulerManages print jobs, admin commands, printer status, data flow
Configuration filescupsd.conf (system-wide settings), printers.conf (printer-specific)
Job filesQueued documents stored under /var/spool/cups; data files prefixed d, control files prefixed c
Log filesStored in /var/log/cups; include access, error, and page records
FiltersConvert job file formats to the printer’s format
Printer driversStored under /etc/cups/ppd/; describe printer capabilities
BackendLocates and communicates with printer devices

When you print: the scheduler validates the job → creates job files according to config → logs activity → sends data through filter → driver → backend → printer.

  • cupsd.conf - system-wide settings: network access, printer advertisement on LAN, management features. Does not contain printer-specific details.
  • printers.conf - auto-generated when printers are added. Should not be edited by hand.

Both live under /etc/cups/.

Terminal window
systemctl status cups
sudo systemctl start cups
sudo systemctl enable cups # start at boot
sudo systemctl restart cups
sudo systemctl stop cups

CUPS provides two CLI printing interfaces - one from each major UNIX lineage:

ToolOriginUsage
lpSystem VPrimary printing command
lprBSDAlternative syntax

Both support printing text, PostScript, PDF, and images. lp is a front-end to lpr that passes input through.

Terminal window
lp filename # print to default printer
lp -d HP-LaserJet filename # print to a specific printer
lp -n 3 filename # print 3 copies
program | lp # print output of a program
echo "test page" | lp # print a string
lpoptions -d printer-name # set the default printer
lpoptions help # list supported options
Terminal window
lpq -a # show queue status across all printers
lpstat -p -d # list available printers + their status
lpstat -a # check all connected printers + job numbers
cancel job-id # cancel a specific print job
lpmove job-id newprinter # move job to a different printer

PostScript is a standard page description language from Adobe. It:

  • Is a pure text format interpreted by a PostScript-compatible printer
  • Describes page appearance in terms of vectors and fonts - resolution-independent
  • Embeds information about page layout, fonts, and graphics within the page data
  • Can be used on any PostScript-compatible printer (all modern printers support it)

PDF (Portable Document Format) has largely superseded PostScript. PDFs are much smaller due to compression, and PDF support is built into most modern applications. However, PostScript is still encountered as an intermediate format in printing pipelines.

These converters come from two packages: ghostscript (ps2pdf, pdf2ps) and poppler (pstopdf, pdftops).

CommandAction
pdf2ps file.pdfConvert PDF to PostScript (→ file.ps)
ps2pdf file.psConvert PostScript to PDF (→ file.pdf)
pstopdf input.ps output.pdfAlternative (poppler)
pdftops input.pdf output.psAlternative (poppler)
convert input.ps output.pdfImageMagick converter
convert input.pdf output.psImageMagick converter

enscript converts plain text files to PostScript:

Terminal window
enscript textfile.txt # print directly to default printer
enscript -p psfile.ps textfile.txt # convert to PostScript file
enscript -2 -r -p psfile.ps textfile.txt # 2-column landscape layout
enscript -n -p psfile.ps textfile.txt # n-column (1-9) output
  • -2 - two columns
  • -r - rotate to landscape (width > height), reducing total pages
  • -p - output to file (not printer)

Common PDF manipulation tasks:

  • Merge or split PDF files
  • Rotate pages
  • Extract specific page ranges
  • Encrypt or decrypt PDFs
  • Add/update metadata
  • Fill out PDF forms
ToolStatusNotes
qpdf✅ RecommendedWidely available, full-featured
ghostscript (gs)✅ RecommendedWidely available, excellent for scripting
pdftk⚠️ AvoidDepends on unmaintained libgcj; many distros dropped it
pdfmodGUISimple graphical editor
pdfinfoCLIExtract metadata from PDFs
flpsedGUIAdd data/fill fields in PostScript docs
Terminal window
qpdf --empty --pages 1.pdf 2.pdf -- merged.pdf # merge two PDFs
qpdf --empty --pages 1.pdf 1-2 -- pages.pdf # extract pages 1-2
qpdf --rotate=+90:1 1.pdf rotated.pdf # rotate page 1 clockwise 90°
qpdf --rotate=+90:1-z 1.pdf all-rotated.pdf # rotate all pages
qpdf --encrypt mypw mypw 128 -- public.pdf private.pdf # 128-bit encryption
qpdf --decrypt --password=mypw private.pdf decrypted.pdf # decrypt
Terminal window
# Merge multiple PDFs into one
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite \
-sOutputFile=all.pdf file1.pdf file2.pdf file3.pdf
# Split: extract pages 10–20
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH \
-dFirstPage=10 -dLastPage=20 \
-sOutputFile=split.pdf file.pdf
ToolUse
pdfinfo file.pdfShow PDF metadata (title, pages, creator, etc.)
pdfmodGUI: reorder, rotate, remove pages; edit title/author/keywords
flpsedGUI: fill forms or add annotations to PostScript documents

![Print manipulation tools](/images/linux/Untitled 3 24.png)