Encapsulated PostScript is defined by Adobe’s Technical Note 5002, “Encapsulated PostScript File Format Specification”, version 3.0 (1 May 1992), whose text is the same as Appendix H of the PostScript Language Reference Manual, Second Edition. An EPS file is a PostScript program that describes a single page and is meant to be placed inside another document. To conform to EPSF 3.0 it must follow the rules on this page, be a single-page document that fully conforms to the Document Structuring Conventions (DSC) 3.0 or later, and carry the two required header comments. Every DSC comment is listed on the structuring comments page.
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 5 5 105 105
10 setlinewidth
10 10 moveto
0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath
stroke
Required comments
| Comment | Meaning |
|---|---|
%!PS-Adobe-3.0 EPSF-3.0 | The version comment, on the first line: the file follows DSC 3.0 and EPSF 3.0. |
%%BoundingBox: llx lly urx ury | Four integers: lower-left x and y and upper-right x and y of the smallest rectangle enclosing every mark painted on the page, in the default PostScript coordinate system (points of 1/72 inch). Line width, joins and other graphics state must be allowed for. The values may be deferred with (atend) and given after %%Trailer. |
An importing program that cannot find both should tell the user the file is not a conforming EPS file and stop the import.
Conditionally required comments
| Comment | Required when |
|---|---|
%%Extensions: | The file needs a Level 1 interpreter with language extensions (for example CMYK) and does not emulate them. |
%%LanguageLevel: | The file uses Level 2 features without conditional emulation. |
%%BeginPreview: … %%EndPreview | The file has an EPSI preview; they must bracket it. |
%%DocumentNeededResources:, %%IncludeResource: and the other resource comments | The file needs fonts, files, forms, patterns, procedure sets or other resources. |
%%BeginDocument: … %%EndDocument | The file itself includes another EPS file. |
Recommended comments
%%Creator:, %%Title: and %%CreationDate: are
strongly recommended; an importing program can show them in the grey box it draws when
there is no preview. The other DSC comments, such as %%Pages:,
%%DocumentData: and %%EndComments, are optional. For a single
illustration that does not call showpage, DSC 3.0 gives
%%Pages: 0, as in the specification’s EPSI example.
%%HiResBoundingBox:, a bounding box in real numbers, is not defined in
EPSF 3.0 or DSC 3.0. Adobe’s Illustrator file
format specification (1998) describes it: it lies within
%%BoundingBox, whose values are then the high-resolution ones with llx
and lly rounded down and urx and ury rounded up.
Illegal and restricted operators
Illegal: all operators in statusdict, the userdict operators
that set up an imageable area, and:
banddevice, clear, cleardictstack,
copypage, erasepage, exitserver,
framedevice, grestoreall, initclip,
initgraphics, initmatrix, quit,
renderbands, setglobal, setpagedevice,
setshared, startjob.
Restricted (allowed only when used as Appendix I of the PostScript Language Reference
Manual, Second Edition, describes): nulldevice, setgstate,
sethalftone, setmatrix, setscreen,
settransfer, undefinefont.
showpage is allowed; the importing program redefines it.
Other rules for the PostScript
- The operand and dictionary stacks must be left as they were found: everything
pushed is popped, and every
beginhas itsend. - The file should make its definitions in its own dictionary rather than the importing program’s current one.
- System names must not be fetched past the dictionary stack, as in
/S systemdict /showpage get def, which defeats the importer’s redefinitions. - Variables are initialised before the procedures that use them are bound, so a name the importer has defined as an operator is not bound by mistake.
- The file must not rely on procedures from application or driver prologs, such as Apple’s LaserPrep. Self-contained files are the most portable; a needed re-encoding of a font is done in the file.
- 7-bit ASCII is recommended. Binary data is allowed but may not survive some channels; control-D (end of job on serial and parallel lines) should not appear.
- No line may exceed 255 characters, not counting the line ending. Lines end in CR, LF, CR LF or LF CR.
DOS binary header
On MS-DOS and Windows, which have no resource fork, an EPS file with a Windows
Metafile or TIFF preview starts with a 30-byte binary header that works as a table of
contents. Numbers are little-endian. A reader checks the first four bytes: the magic
number means the header is present; %! means a plain PostScript file, which
is always allowed as an EPS file.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | bytes | Magic | C5 D0 D3 C6 (byte 0 is C5): the letters “EPSF” with the high bit set. |
| 4 | 4 | u32 | PSStart | Byte position of the PostScript section. |
| 8 | 4 | u32 | PSLength | Byte length of the PostScript section. |
| 12 | 4 | u32 | WMFStart | Byte position of the Windows Metafile preview, or 0. |
| 16 | 4 | u32 | WMFLength | Byte length of the Metafile, or 0. |
| 20 | 4 | u32 | TIFFStart | Byte position of the TIFF preview, or 0. |
| 24 | 4 | u32 | TIFFLength | Byte length of the TIFF, or 0. |
| 28 | 2 | u16 | Checksum | XOR of bytes 0 to 27, or FFFF, meaning ignore it. |
00000000 C5 D0 D3 C6 1E 00 00 00 A0 31 00 00 00 00 00 00
00000010 00 00 00 00 BE 31 00 00 2A 4C 00 00 FF FF
The specification assumes only one preview: either the Metafile fields or the TIFF fields are zero. The Metafile follows the Windows rules; it should set the window origin and extent but not the viewport or mapping mode, and the importing program scales it to the bounding box. The previews are ordinary WMF and TIFF data. When printing, only the PostScript section is sent.
EPSI preview
Encapsulated PostScript Interchange (EPSI) keeps a device-independent preview inside the PostScript as comment lines, so the file stays text and prints unchanged. The specification recommends that every program supports it.
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 80 24
%%Pages: 0
%%Creator: John Smith
%%CreationDate: November 9, 1990
%%EndComments
%%BeginPreview: 80 24 1 24
%FFFFFFFFFFFFFFFFFFFF
%FFFFFFFFFFFFFFFFFFFF
…
%FF0000000000000000FF
…
%FFFFFFFFFFFFFFFFFFFF
%%EndPreview
%%EndProlog
%%Page: "one" 1
4 4 moveto 72 0 rlineto 0 16 rlineto -72 0 rlineto
closepath
8 setlinewidth stroke
%%EOF
%%BeginPreview: width height depth lines: the number of samples across and down, bits per sample (typically 1, 2, 4 or 8), and the number of hex lines up to%%EndPreview, so a reader can skip them. All are integers.- The preview comes straight after
%%EndComments, before any defaults section and the prolog. - Each line starts with
%. Lines are at most 255 bytes and may be broken after any even number of hex digits. Every non-hex character, including spaces, tabs, newlines and%, is ignored when collecting the data, asreadhexstringdoes. - 0 is white and 1 is black, the opposite of
setgray. Transfer functions and inversion are not supported. - Each scan line is a multiple of 8 bits, padded with 0 bits.
- Bit order is that of the
imageoperator. The specification places the image in its own coordinate system with (0,0) at the lower left and gives the data order as (0,0) to (width − 1, 0), then (0,1) to (width − 1, 1), and so on. - The preview may be at any resolution; it is scaled to fill the bounding box, which alone gives its size on the page.
- An importing program should strip the preview before sending the file to a printer, to save transmission time.
Macintosh preview
On the Macintosh the file type is EPSF, and the preview is a QuickDraw
PICT resource with ID 256 in the resource fork. If the picture frame,
converted to PostScript coordinates, disagrees with %%BoundingBox:, the
bounding box is the truth. Files of type TEXT are also allowed so EPS
files can be made in text editors; they still follow the DSC. The PICT resource is never
sent to the printer. Copied to other systems, the resource fork is usually lost.
File types and names
| System | EPS | EPSI |
|---|---|---|
| Macintosh | File type EPSF, any name; type TEXT with .epsf | Type TEXT with .epsi |
| MS-DOS and PC-DOS | .EPS | .EPI |
| Other systems | .epsf preferred (upper case where case is not significant) | .epsi |
Placing an EPS file
An importing program reads the comments, takes at least the bounding box and the resource needs, shows the preview (or a grey box with the title when there is none) and lets the user place, scale, rotate and clip it. When it prints, it:
- wraps the EPS file in
saveandrestore, and in%%BeginDocument:and%%EndDocument; - defines
showpageas an empty procedure; - sets the graphics state:
0 setgray 0 setlinecap 1 setlinewidth 0 setlinejoin 10 setmiterlimit [ ] 0 setdash newpath, and on Level 2 alsofalse setoverprint false setstrokeadjust; - pushes
userdictwithbegin, leaves an empty operand stack, and counts the operand and dictionary stacks before and after so leftovers can be removed (earlier EPSF versions did not state that a file must clean up); - transforms the coordinate system in this order: translate to the chosen origin,
rotate, scale, then translate by
-llx -lly; - sets a clipping path, normally the bounding box;
- passes the file’s
%%LanguageLevel:,%%Extensions:and needed resources up into its own header, and checks the printer can meet them.
/BeginEPSF { %def
/b4_Inc_state save def % Save state for cleanup
/dict_count countdictstack def % Count objects on dict stack
/op_count count 1 sub def % Count objects on operand stack
userdict begin % Push userdict on dict stack
/showpage { } def % Redefine showpage, { } = null proc
0 setgray 0 setlinecap % Prepare graphics state
1 setlinewidth 0 setlinejoin
10 setmiterlimit [ ] 0 setdash newpath
/languagelevel where % If level not equal to 1 then
{pop languagelevel % set strokeadjust and
1 ne % overprint to their defaults.
{false setstrokeadjust false setoverprint
} if
} if
} bind def
/EndEPSF { %def
count op_count sub {pop} repeat % Clean up stacks
countdictstack dict_count sub {end} repeat
b4_Inc_state restore
} bind def
Changes since version 2.0
- Detailed comment descriptions moved to DSC 3.0, which is to be used with EPSF 3.0.
- New conditionally required comments:
%%Extensions:,%%LanguageLevel:,%%DocumentNeededResources:,%%IncludeResource:and%%BeginDocument:/%%EndDocument. - New rules for producers: the preview comments must bracket an EPSI preview; the lists of illegal and restricted operators; the stacks must be restored; definitions should go in the file’s own dictionary; no reliance on LaserPrep or other outside procedures.
- New rules for importers: redefine
showpage, prepare the graphics state, give a clear operand stack, and bracket the file with%%BeginDocument:and%%EndDocument.
Files written to older versions carry earlier DSC and EPSF numbers on the first line. The earlier specifications themselves were not consulted for this page.
Source
- Encapsulated PostScript File Format Specification, version 3.0 – Adobe Technical Note 5002, 1 May 1992 (archived copy of Adobe’s partners site)
- PostScript Language Document Structuring Conventions Specification, version 3.0 – Adobe Technical Note 5001, 25 September 1992