PS File Documentation


Summary

A file with the .ps extension is a PostScript document: a page-description program, written in Adobe’s PostScript language, that an interpreter executes to draw one or more pages of text, vector graphics and images. It is the print-ready ancestor of PDF. A .ps file is plain ASCII text that begins with %! (hex 25 21), normally the line %!PS-Adobe-3.0. Its MIME type is application/postscript. PostScript is largely legacy now — PDF has replaced it for everyday use — but it survives in printing and LaTeX workflows.

Technical details

FeatureValue
Full namePostScript (page-description program)
File extension.ps
MIME typeapplication/postscript
Format typePostScript page-description language — a text program interpreted to render pages
DeveloperAdobe Systems
Introduced1984 (Level 1); Level 2 in 1991; Level 3 in 1997
Standard / specPostScript Language Reference Manual (PLRM); DSC 3.0
Open standardPartial (Adobe-published specification)
EncodingASCII text (with optional binary image data)
Magic number25 21 (“%!”); DSC header line %!PS-Adobe-3.0
Execution modelStack-based; interpreted by Ghostscript or a PostScript printer
ResolutionDevice-independent (vector); rasterised at output time
FontsType 1 / TrueType, embeddable in the file
Relationship to PDFPDF is a fixed, non-programmatic descendant of the same imaging model
Relationship to EPSEPS is a single-figure encapsulated subset with a BoundingBox
CategoryVector Image / Page-Description Document
Related extensions.eps, .pdf, .ai, .prn, .svg
File signature (magic bytes)
25 21 50 53 2D 41 64 6F 62 65

Offset 0. A PostScript file is plain text that starts with %! (hex 25 21). A DSC-conforming file spells out the full header line, e.g. %!PS-Adobe-3.0 (the hex above is %!PS-Adobe), which also declares the Document Structuring Conventions version. In PostScript the % character begins a comment, so the interpreter ignores this line as code — but the leading %! is the recognised signature that marks the file as a PostScript program rather than data. An EPS figure uses the same start followed by %!PS-Adobe-3.0 EPSF-3.0.

What is a .ps file?

PostScript (PS) is the page-description language Adobe introduced in 1984, the technology that launched desktop publishing. A .ps file is not a static image but a small program written in the PostScript language: it contains drawing commands that a PostScript interpreter — built into a laser printer, or software such as Ghostscript — executes to render one or more pages of text, vector graphics and embedded raster images. Because the output is resolution-independent and was understood directly by printers, PostScript became the standard for professional printing and typesetting for two decades. Its MIME type is application/postscript.

The consequence of PostScript being a programming language, rather than a fixed document, runs through everything below: a .ps file is executed, not merely parsed, and two files that draw the same page can contain completely different code. Adobe later built PDF on the same imaging model but stripped out the programmability, which is why PDF has almost entirely replaced .ps for everyday use while PostScript survives in printing pipelines and academic toolchains.

The PostScript language: stack-based and PostFix

PostScript is a stack-based, postfix (Reverse Polish) language. Operands are pushed onto an operand stack and an operator consumes them, so drawing a line looks like a sequence of pushes followed by commands:

%!PS-Adobe-3.0
/Times-Roman findfont    % push the font dictionary
20 scalefont             % scale it to 20 units, leaving a font on the stack
setfont                  % install it as the current font
72 700 moveto            % move the current point to (72, 700)
(Hello, world) show      % paint the string at the current point
100 100 moveto
300 400 lineto           % add a line to the current path
2 setlinewidth
stroke                   % draw the path
showpage                 % emit the page and start a new one

Coordinates are in the default user space of 72 units per inch, with the origin at the bottom-left of the page. The language has variables, procedures (/name { ... } def), control flow, arithmetic and dictionaries, which is what makes it Turing-complete and, later, a security concern. The showpage operator is what actually renders and ejects the current page, so a multi-page document calls it once per page.

Document Structuring Conventions: %! and the %% comments

Raw PostScript can do anything in any order, which makes it hard for tools to, say, extract page 5 or print pages in reverse. Adobe’s Document Structuring Conventions (DSC) solve this with a layer of structured comments. In PostScript the % character starts a comment the interpreter ignores, so DSC hides machine-readable metadata in lines beginning with %% (or %! for the header). These comments do not affect the rendered output; they let spoolers and viewers understand the document without executing it.

%!PS-Adobe-3.0                 <- header + DSC version (magic signature %!)
%%Creator: dvips
%%Title: report.dvi
%%Pages: 12
%%BoundingBox: 0 0 612 792
%%EndComments
... prolog: procedure and font definitions ...
%%Page: 1 1
... page 1 drawing operators ...
showpage
%%Page: 2 2
...
%%Trailer
%%EOF

The header line is also the file’s magic number: %! (hex 25 21), usually written in full as %!PS-Adobe-3.0, which both identifies the file and declares the DSC version it conforms to. %%Pages announces the page count, and each %%Page: comment marks a page boundary so a viewer can navigate directly. %%BoundingBox gives the drawing extent in points (integers only, per the DSC spec). A DSC-conforming file separates a prolog of static definitions from the per-page script, which is exactly what lets a print spooler reorder or subset pages safely.

Prolog, setup, pages and trailer

A well-structured .ps document has four ordered regions, each delimited by DSC comments. The prolog holds procedures, resources and font definitions used throughout the document; putting reusable code here keeps each page short. The setup section applies document-wide device settings. The pages section is the body: a run of page descriptions, each opened by a %%Page: comment and ended by showpage, and importantly each page is meant to be independent so it can be printed or extracted alone. The trailer (%%Trailer) contains cleanup and any information that could only be known after all pages were written, ending with %%EOF. This separation is the structural discipline PDF later baked into a fixed, indexed file layout.

Embedded fonts and raster images

A .ps can be self-contained. Fonts are embedded as Type 1 (or later TrueType) font programs, so the document prints identically on a device that lacks those fonts. Raster images are drawn with the image and colorimage operators, which read pixel data supplied inline — the sample data can be ASCII-hex, ASCII-85 or, in Level 2 and later, compressed and binary-encoded. PostScript Level 2 (1991) added colour and compression filters (RunLength, LZW, later DCT/JPEG), and Level 3 (1997) added smoother shadings and better font handling. This is why a photo-heavy .ps file can be large: the image samples are carried inside the program, sometimes as verbose ASCII.

PS against EPS and PDF

Three PostScript-family formats are routinely confused. A plain .ps is a complete, often multi-page document or print job. EPS (Encapsulated PostScript) is a single self-contained figure with a mandatory %%BoundingBox and restrictions on operators it may use (no showpage side effects that would disturb a host page), designed to be embedded inside another document. So an EPS is a constrained one-page subset of the same language, which is why converting a single-page .ps to EPS is mostly a matter of adding or verifying a bounding box, while a multi-page .ps has no single-EPS equivalent.

PDF shares PostScript’s imaging model but is a different kind of file: fixed, page-indexed, and not a program. PDF removes the general-purpose language, adds a cross-reference table for random page access, and is therefore both safer and faster to render. Because the imaging model is shared, converting .ps to PDF is lossless as to text and vectors — Ghostscript’s ps2pdf interprets the PostScript once and records the resulting page descriptions in PDF form. PDF replaced PostScript for distribution; PostScript persists mainly because printers still speak it natively and LaTeX toolchains (via dvips) still emit it.

Security: PostScript is executable code

Because PostScript is a full programming language, a .ps file can contain executable logic, and the interpreter that renders it is the attack surface. Historically PostScript included operators like file that could touch the filesystem, and Ghostscript in particular has had a series of serious CVEs allowing sandbox escape and command execution from a crafted document — a malicious .ps could, on a vulnerable interpreter, run commands rather than just draw a page. The practical rules are technical: keep Ghostscript fully updated, since its -dSAFER sandbox is what confines a document’s access and has been the subject of the bypasses; be cautious opening .ps files from untrusted senders; and prefer converting to PDF and reading the safer, non-programmatic PDF. A plain .ps from a trusted print pipeline or your own LaTeX build is fine; the risk is active content from an unknown source, exactly as with EPS.

FAQ

Why does my .ps file open as text or code? Because PostScript is a text program. If it opens in a text editor, your system simply has no PostScript viewer associated with the extension. Install Ghostscript plus a viewer, or convert the file to PDF, to see the rendered pages instead of the source code.

What is the difference between PS and PDF? Both come from Adobe and share the same imaging model, but PostScript is a programming language a printer or interpreter executes, while PDF is a fixed, page-indexed, non-programmatic document. PDF replaced PostScript for everyday use; PS survives mainly in printing and legacy/LaTeX workflows.

What is the difference between PS and EPS? A plain .ps is a complete document or print job, often multi-page. EPS is a single self-contained figure with a declared %%BoundingBox, meant to be embedded inside another document rather than printed on its own.

References