Subject: 9 Encapsulated PostScript Subject: 9.1 What is Encapsulated PostScript? Encapsulated PostScript (EPS) is a standard format for importing and exporting PostScript language files in all environments. It is usually a single page PostScript language program that describes an illustration. The purpose of the EPS file is to be included as an illustration in other PostScript language page descriptions. The EPS file can contain any combination of text, graphics, and images. An EPS file is the same as any other PostScript language page description, with some restrictions. EPS files can optionally contain a bitmapped image preview, so that systems that can't render PostScript directly can at least display a crude representation of what the graphic will look like. There are three preview formats: Mac (PICT), IBM (tiff), and a platform independent preview called EPSI. An EPS file must be a conforming file, that is, it must conform to the Adobe Document Structuring Conventions (DSC). At a minimum, it must include a header comment,%!PS-Adobe-3.0 EPSF-3.0, and a bounding box comment,%%BoundingBox: llx lly urx ury, that describes the bounds of the illustration. (The specification does not require the EPSF version, but many programs will reject a file that does not have it.) The EPS program must not use operators that initialize or permanently change the state of the machine in a manner that cannot be undone by the enclosing application's use of save and restore (eg. the operators starting with ``init'' like initgraphics). As a special case, the EPS program may use the showpage operator. The importing application is responsible for disabling the normal effects of showpage. The EPS program should make no environment-sensitive decisions (the importing application may be trying to attain some special effect, and the EPS program shouldn't screw this up), although it can use some device-dependent tricks to improve appearance such as a snap-to-pixel algorithm. The complete EPS specification is available from Adobe (see the section on Adobe). Read Appendix G (Document Structuring Conventions, V3.0) and Appendix H (Encapsulated PostScript File Format, V3.0) in the new PostScript red book: PostScript Language Reference Manual, Second Edition. An optional component of an EPS file is a ``preview'' image of the file's content. The preview image is a bitmapped representation of the image which may be displayed by programs using the EPS file without having to actually interpret the PostScript code. The recommended form for a preview image is ``Interchange'' format and is described fully in the ``red book'', second edition. Interchange format represents the image as a series of hex strings placed in the EPS file as PostScript comments. The entire file remains an ASCII file. That book contains all of the information that you need to fix your program to correctly output EPS. It is what I use for our software. A variation of EPS embeds the preview image and PostScript text in a binary file which contains a header and the preview image in either a TIFF or MetaFile format. The header defines where in the file each section (EPS, TIFF, or MetaFile) starts and ends. On the Macintosh, the preview is stored as a PICT in the file's resource fork. Subject: 9.2 What are EPSI and EPSF? EPSI is EPS with a device independent bitmap preview. EPSI is an all ASCII (no binary data or headers) version of EPS. EPSI provides for a hexadecimal encoded preview representation of the image that will be displayed or printed. EPSF is a version of EPS with a TIFF preview instead of a bitmap preview. Subject: 9.3 How do I convert PostScript to EPS? Use pstoepsi, or do it by hand. To convert from PostScript to EPS, one must guarantee that the PostScript file meets the above requirements. If the actual program conforms to the programming requirements, then one can simply add the required comments at the top of the file saying that the file is EPS and giving its BoundingBox dimensions. Optional comments include font usage (%%DocumentFonts: or%% DocumentNeededResources: font), EPSI preview comments (%% Begin(End)Preview:) extensions (%%Extensions:) and language level (%%LanguageLevel:). There are some operators that should not be used within an EPS file: banddevice cleardictstack copypage erasepage exitserver framedevice grestoreall initclip initgraphics initmatrix quit renderbands setglobal setpagedevice setshared startjob These also include operators from statusdict and userdict operators like legal, letter, a4, b5, etc. There are some operators that should be carefully used: nulldevice setgstate sethalftone setmatrix setscreen settransfer undefinefont To convert a PostScript file to EPS format, you must edit the file using a text editor or word processor to add lines that will define the file as an EPS-format file. 1. Using your normal method of printing, print the PostScript file to a PostScript printer. You can choose to view it on the screen instead, but keep in mind that all the below distance measurements assume that you are printing on a normal-sized piece of paper. NOTE: If the PostScript image does not get displayed properly, it probably will not work either once you have converted it to EPS format. Correct the PostScript program so that it works before you convert it to EPS format. 2. Use a tool (see below) to find the bounding box, which shows how much space the PostScript image occupies when printed. You specify the dimensions of the bounding box when you convert the PostScript file to EPS format. 3. If you don't have a bounding box tool, you can just use a ruler and draw one on your printout. With two horizontal lines and two vertical lines, draw a box around the image that includes the entire image while minimizing white space. This box represents your bounding box. You may want to leave a small amount of white space around the image as a precautionary measure against minor printing problems, such as paper stretching and paper skewing. 4. Measure distance ``a'' from the lower-left corner of the image to the left edge of the paper. 5. Write the measurement in points. If your ruler does not show points, calculate the total number of points: 1 inch = 72 points, 1 cm = 28.3 points, and 1 pica = 12 points. Designate this measurement as ``measurement a.'' 6. Measure distance ``b'' from the lower-left corner of the image to the bottom edge of the paper. Designate this measurement in points as ``measurement b.'' 7. Measure distance ``c'' from the upper-right corner of the image to the left edge of the paper. Designate this measurement in points as ``measurement c.'' 8. Measure distance ``d' from the upper-right corner of the image to the bottom edge of the paper. Designate this measurement in points as ``measurement d.'' 9. Using any text editor, open the PostScript file for editing. You'll see several lines of text. These lines are the PostScript description of the image. The lines at the top of the file are the header. 10. Add these lines to, or modify existing lines in, the header (the first group of lines in any PostScript file): %!Adobe-2.0 EPSF %%Creator: name %%CreationDate: date %%Title: filename %%BoundingBox: a b c d Note: Make sure that the first line in the file is ``% !Adobe-2.0 EPSF.'' Also, do not separate the header lines with a blank line space. The first blank line that PostScript encounters tells it that the the next line begins the body of the program. For ``name,'' type your name or initials. For ``date,'' type today's date using any format (for example, MM-DD-YY, MM/DD/YY, July 5, 1987, and so on). For ``filename,'' type the name of the PostScript file. After ``BoundingBox: ,'' type the measurements you took in steps 3, 4, 5, and 6, separating each with a space: ``a'' is the measurement from Step 3, ``b'' is the measurement from Step 4, ``c'' is the measurement from Step 5, and ``d'' is the measurement from Step 6. 11. Save the file in text-only format. If you are interested in learning how to further edit your PostScript files, these books are available at most bookstores: Understanding PostScript Programming and the green book. Encapsulated PostScript is discussed in Appendix C of the old red book. The new red book has a lot of information about Encapsulated PostScript. There will be a technical note available from Adobe called ``Guidelines for Specific Operators'' that will talk about why some operators are prohibited and how to use the others. Subject: 9.4 How do I get the bounding box of a PostScript picture? Use bbfig or epsinfo.ps. Or if you would rather construct the bounding box by hand, use Ghostview, which has a continuous readout of the mouse cursor in the default user coordinate system. You simply place the mouse in the corners of the figure and read off the coordinates. Subject: 10 About The Comp.Lang.PostScript FAQ (and Usenet Guide to PostScript) | |
|