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 [OPTIONS] [FILE...]

PARAMETERS

-b, --header=TEXT
    Sets the header text for pages. Supports special escape sequences for dynamic content like file name, date, or page number.

-f, --font=NAME
    Specifies the font to use for the body text, e.g., Courier10. Can include font size.

-l, --lines=NUM
    Sets the maximum number of lines to print on each page.

-M, --media=NAME
    Specifies the page media size (e.g., A4, Letter).

-p, --output=FILE
    Directs the PostScript output to the specified FILE.

-2, --columns=NUM
    Arranges the output in NUM columns per page.

-E, --highlight
    Enables syntax highlighting for various programming languages based on file extension.

-G, --fancy-header
    Uses a more elaborate header format with file name, date, and page numbers.

-r, --rotate-pages
    Rotates the pages by 90 degrees, suitable for landscape printing.

-X, --encoding=NAME
    Specifies the input character encoding (e.g., UTF-8, latin1).

-#, --copies=NUM
    Generates NUM copies of the output. Often handled by the printer spooler.

-o
    Sends the output to standard output (stdout).

-P, --printer=NAME
    Sends the output directly to the specified printer NAME.

-q, --quiet
    Suppresses informational messages and warnings.

DESCRIPTION

The enscript command converts plain text files into PostScript (PS) format, primarily for high-quality printing. It offers extensive formatting capabilities, allowing users to control almost every aspect of the output, such as fonts, font sizes, line numbering, headers, footers, page layout (e.g., multiple columns), and syntax highlighting.

It's widely used by programmers to print source code, by system administrators to print log or configuration files, and by anyone needing a well-formatted printed version of a text document. enscript can output the generated PostScript to a file, to standard output, or directly to a printer via the system's printing spooler, making it a versatile tool for document preparation.

CAVEATS

enscript generates PostScript, which requires a PostScript-compatible printer or a PostScript viewer/converter (like Ghostscript) to render. In modern printing workflows, direct PostScript generation is sometimes bypassed for more universal formats like PDF, which can reduce enscript's direct-to-printer usage. Its extensive options, while powerful, can make it complex to master, and subtle configuration issues might lead to unexpected formatting.

CONFIGURATION FILES

enscript can be extensively configured using system-wide (e.g., /etc/enscript.cfg) and user-specific (e.g., ~/.enscriptrc) configuration files. These files allow setting default options, defining custom highlight rules, and managing print queues, making it easier to achieve consistent formatting without specifying all options on the command line each time.

ENVIRONMENT VARIABLES

Several environment variables can influence enscript's behavior, such as ENSC_DEBUG for debugging, PRINTER to specify the default printer, or ENscript which can contain default options to be prepended to the command line arguments, providing another layer of customization.

HISTORY

enscript originated in the Unix environment, developed primarily by Markku Savolainen in Finland. It quickly became a staple utility for converting plain text to PostScript for printing, especially in environments where robust formatting and direct printer communication were essential. It has been a fundamental part of many GNU/Linux distributions for decades, maintaining its relevance for specific text processing and printing tasks despite the evolution of document formats and printing technologies.

SEE ALSO

lpr(1), lp(1), a2ps(1), pr(1), ps2pdf(1) (from Ghostscript)

Copied to clipboard