LinuxCommandLibrary

enscript

Convert text files for printing

TLDR

Generate a PostScript file from a text file

$ enscript [path/to/input_file] [[-o|--output]] [path/to/output_file]
copy

Generate a file in a different language than PostScript
$ enscript [path/to/input_file] [[-w|--language]] [html|rtf|...] [[-o|--output]] [path/to/output_file]
copy

Generate a PostScript file with a landscape layout, splitting the page into columns (maximum 9)
$ enscript [path/to/input_file] --columns [num] [[-r|--landscape]] [[-o|--output]] [path/to/output_file]
copy

Display available syntax highlighting languages and file formats
$ enscript --help-highlight
copy

Generate a PostScript file with syntax highlighting and color for a specified language
$ enscript [path/to/input_file] --color 1 [[-E|--highlight]] [language] [[-o|--output]] [path/to/output_file]
copy

SYNOPSIS

enscript [OPTION...] [FILE...]

PARAMETERS

-b LABEL, --label=LABEL
    Set document label on first page header

-B, --no-header
    Suppress headers and footers

-C[NUM], --line-numbers[=NUM]
    Print line numbers; NUM sets lines per header

-c
    Print each input file on one page (no page breaking)

-d PRINTER
    Send output to named printer

-D VAR[=VAL], --define VAR[=VAL]
    Define PostScript variable VAR to VAL

-E[LANG], --highlight=[LANG]
    Highlight syntax for programming language LANG

-e NUM, --every=NUM
    Like -C but number every NUM lines

-f FONT, --font=FONT
    Select body font; format NAME[:ENCODING[:POINTSIZE]]

-F FONT, --header-font=FONT
    Select header/footer font

-G, --print-anyway
    Print file even if it produces no pages

-g, --fancy-header
    Print fancy headers

-h, --no-splitleader
    Suppress split titles on multi-page documents

-i INDENT, --indent=INDENT
    Set left margin indent in characters

-j, --linewrap
    Wrap lines

-J TITLE, --job=TITLE
    Set job title

-k, --page-prefeed
    Enable page prefeeding

-L NUM, --lines-per-page=NUM
    Lines per page

-l NUM, --line-numbers=NUM
    Like -C but only NUM lines

-M NAME, --media=NAME
    Media type (A4, Letter, etc.)

-m
    Don't send control-D to printer

-N, --no-job
    Suppress job headers/trailers

-n NUM
    Copy NUM pages per input file

-o FILE, --output=FILE
    Save output to FILE

-p FILE, --print-file=FILE
    Save spool file to FILE

-P PRINTER
    Like -d but check printer status

-r, --landscape
    Landscape orientation

-R, --portrait
    Portrait orientation

-s NUM, --size=NUM
    Page width in characters

-S VAR[=VAL], --setpagedevice VAR[=VAL]
    Set PostScript page device variable

-t TITLE, --title=TITLE
    Set title printed on headers

-T MODE, --tab=MODE
    Tabulator mode (0=spaces, 1=no tabs, 2=8 spaces)

-u[NUM], --underlay[=NUM]
    Print underline; NUM sets thickness

-U, --overstrike
    Print overstrike

-v, --verbose
    Verbose mode

-W LANG, --word-wrap[=LANG]
    Word wrap; LANG selects highlighting

-X ENCODING, --encoding=ENCODING
    Input code encoding

-Z, --no-zap
    Don't remove trailing empty pages

--help
    Display usage summary

--version
    Print version information

DESCRIPTION

Enscript is a powerful command-line utility that converts plain ASCII text files into PostScript (or SPL) format, optimized for high-quality printing. Originally designed for printing source code with syntax highlighting, it supports dozens of programming languages like C, C++, Java, Python, Perl, and more via built-in or custom highlight definitions.

Key capabilities include multi-column layouts (up to 4 columns), landscape/portrait orientation, customizable headers/footers with page numbers, dates, filenames, and titles, line numbering, font selection for body and headers, paper/media size adjustments (A4, letter, legal), word wrapping, underlining/overstriking, and input encoding support for international text.

Usage is straightforward: pipe input, specify files, or send directly to printers. Output can be saved as .ps files or converted to PDF using Ghostscript. Syntax highlighting is activated with -E lang, e.g., enscript -Ec++ code.cc. Custom styles, margins, and variables allow fine-tuning.

Ideal for developers, sysadmins, and anyone needing professional printouts from terminals or scripts, enscript excels in environments without GUI tools, remaining relevant on modern Unix-like systems.

CAVEATS

Requires PostScript printer or Ghostscript for non-PS devices.
Highlighting files must be installed separately for some languages.
Large files may consume significant memory during processing.

EXAMPLES

enscript file.txt - Convert to default.ps
enscript -2r -Ec++ code.cc - 2-column landscape C++ highlighting
enscript -p output.ps *.c | lp - Print all C files

HIGHLIGHTING

Use -E for languages like c,c++,java,perl,python,sh. Custom defs in /usr/share/enscript/hl/.

HISTORY

Developed by Markku Rossi starting in 1992; first public release around 1993. Adopted into GNU project in 1995. Maintained as GNU enscript, with versions up to 1.6.7 (2020). Widely packaged in Linux distros for decades.

SEE ALSO

a2ps(1), lp(1), lpr(1), gs(1)

Copied to clipboard