All formats

PostScript (PS)

Full namePostScript
Extensions.ps
MIME typeapplication/postscript
Typepage description language (a program that draws pages), usually plain text
Starts with25 21 50 53 (%!PS), usually %!PS-Adobe-3.0
SpecificationPostScript Language Reference, Third Edition (PDF)
Maintained byAdobe (no longer developed)
Licenseopen specification; the name is an Adobe trademark

A PostScript file is a program in the PostScript language. A printer or an interpreter such as Ghostscript runs the program, and the program draws text, vector graphics and images onto pages. Pages are described in points (1/72 inch) and print at the full resolution of the device.

PostScript is still used as a printer language and as the output of older Unix and TeX tools (dvips, groff, a2ps). For documents you want to view or share, PDF has replaced it: a PDF has the same imaging model but is a data structure, not a program, so a viewer can open any page directly.

When to use PostScript#

File structure#

A PostScript file is plain text (sometimes with binary image or font data) made of PostScript operators in postfix order: operands first, then the operator. Only the interpreter knows what the file draws. To let other programs process a file without running it, well-formed files follow the Document Structuring Conventions (DSC): special comments that start with %% and mark the header, the prolog and each page.

%!PS-Adobe-3.0
%%Creator: my program
%%Title: hello.ps
%%Pages: 1
%%BoundingBox: 0 0 612 792
%%DocumentMedia: Letter 612 792 0 () ()
%%LanguageLevel: 2
%%EndComments
%%BeginProlog
/F { findfont exch scalefont setfont } bind def
%%EndProlog
%%BeginSetup
%%EndSetup
%%Page: 1 1
24 /Helvetica F
72 720 moveto (Hello, PostScript) show
newpath 72 600 moveto 300 0 rlineto stroke
showpage
%%Trailer
%%EOF

The coordinate origin is the bottom-left corner of the page and the y axis goes up. 72 720 moveto is 1 inch from the left edge, 10 inches from the bottom. showpage outputs the current page.

DSC comments#

Comment Meaning
%!PS-Adobe-3.0 first line: the file follows DSC version 3.0. %!PS alone means no DSC promise
%%Pages: n number of pages; (atend) means the value is in the trailer
%%BoundingBox: llx lly urx ury area that contains all marks, in integer points
%%HiResBoundingBox: the same with decimals
%%DocumentMedia:, %%PageMedia: paper size and type
%%LanguageLevel: n PostScript level needed: 1, 2 or 3
%%Creator:, %%Title:, %%CreationDate:, %%For: metadata
%%EndComments end of the header
%%BeginProlog / %%EndProlog procedure definitions used by all pages
%%BeginSetup / %%EndSetup device setup: paper size, duplex, resolution
%%Page: label ordinal start of a page
%%BeginFont, %%BeginResource embedded fonts and other resources
%%Trailer, %%EOF end of the document

With DSC a tool can count pages, extract a page range or reorder pages (psselect, psnup from psutils) by copying text between %%Page: comments. A file that breaks the conventions (for example, a page that depends on state set by an earlier page) prints fine but breaks such tools.

Language levels#

Level Adds
1 the base language: paths, Type 1 and Type 3 fonts, grayscale images
2 color spaces (CMYK, CIE), compression filters (LZW, DCT/JPEG, RunLength), forms, patterns, setpagedevice
3 Flate (zlib) compression, smooth shading, more color spaces (DeviceN), masked images, CID fonts

Binary data such as images is usually written as ASCII85 or hex so the file stays 7-bit text.

Other things at the start of a file#

Converting PostScript#

Ghostscript does almost every conversion:

Shell
# PostScript to PDF
ps2pdf in.ps out.pdf
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf in.ps

# PostScript to PNG, one file per page, 150 dpi, anti-aliased
gs -dNOPAUSE -dBATCH -sDEVICE=png16m -r150 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 \
   -sOutputFile=page-%03d.png in.ps

# extract text
gs -dNOPAUSE -dBATCH -sDEVICE=txtwrite -sOutputFile=out.txt in.ps

# PDF to PostScript
pdf2ps in.pdf out.ps

Since Ghostscript 9.50 -dSAFER is the default: the PostScript program can’t read or write arbitrary files. Keep it on for files you didn’t create.

Specifications and documentation#

Software that opens PostScript files#

SoftwareWindowsmacOSLinuxWebCanNotes
SumatraPDF✓viewfree, open source; opens .ps when Ghostscript is installed
Ghostscript✓✓✓view, convertthe reference interpreter; gs, ps2pdf; AGPL or commercial license
Okular✓viewfree, open source KDE viewer; uses Ghostscript through libspectre
Evince✓viewGNOME document viewer, uses libspectre
Zathura✓viewkeyboard-driven viewer with the zathura-ps plugin
Inkscape✓✓✓view, edit, convertimports PS/EPS through Ghostscript, exports PS and EPS
GIMP✓✓✓view, convertrasterizes PostScript pages through Ghostscript
Adobe Acrobat Pro✓✓convertcommercial; Acrobat Distiller converts PS to PDF
Adobe Illustrator✓✓view, editcommercial
CorelDRAW✓✓view, editcommercial; imports PS and EPS
ImageMagick✓✓✓convertcommand line; reads PostScript through Ghostscript
IrfanView✓view, convertfree for non-commercial use; needs Ghostscript and the PostScript plugin

macOS Preview opened PostScript up to macOS 12. macOS 13 removed it from Preview and macOS 14 removed the built-in PostScript-to-PDF converter (pstopdf). On a current Mac, install Ghostscript (brew install ghostscript) and run ps2pdf.

Libraries#

Open-source libraries that interpret, render or write PostScript. See all PostScript libraries for a comparison.

C/C++cairo, Ghostscript, libspectre
C#Ghostscript.NET, Magick.NET
Javaxmlgraphics-commons
Gocanvas
PythonPillow, pycairo, python-ghostscript
RubyMiniMagick
Rustcairo-rs
PHPImagick