PostScript – Using PostScript to concatenate PostScript and EPS file

This piece of PostScript can be used with any version of Adobe
Acrobat Distiller to allow a sequence of PostScript or EPS
files to be concatenated together into a single PDF file.

PostScript includes a RunFile operator which can be used to
concatenate PostScript files, but it is not suitable for EPS
files for a few reasons:

1. EPS files may have a TIFF preview in the same file. This
will upset Distiller because TIFF just isn’t PostScript.

2. EPS files might not include a call to ‘showpage’. It doesn’t
really matter what that is, but if it is missing all the files
run together on one page.

3. Each EPS file might be a different size, and Distiller has
only one default page size.

This code defines SuperRunFile, which overcomes all these
limitations. The EPS page size adjustment is optional –
see the definition of AdjustToBBox below. Notice that you can
also adjust the margin around an EPS.

To use this you need to add a sequence of calls to SuperRunFile
at the end of this file. You’ll see there’s an example there
now. How you do that is up to you. Once you’ve saved this
file, open it in Distiller in the usual way.

% Define RunFile operator called SuperRunFile,
% capable of detecting and processing DOS-format
% EPS files with binary preview headers.
% Optionally resets page size to enclose EPS.
% Also ensures a showpage is done.

% Copyright Aandi Inston 1997, 1999. Version 2.
% Not to be used in a commercial product.
% Supplied as is with no actual or implied warranty.
% Please post requests for support to public forums.

/AdjustToBBox true def % true to set page size to contain bbox
/Margin 1 def % bbox margin (units 1/72 inch)

/FileName exch def


FileName (r) file /F exch def
/S 32 string def F S readstring
{ pop } if

S 0 get 197 eq /EPSPrev? exch def

(Processing EPS page ) print FileName print (n) print
S 7 get 256 mul S 6 get add 256 mul S 5 get add 256 mul S 4 get add
/StartByte exch def
S 11 get 256 mul S 10 get add 256 mul S 9 get add 256 mul S 8 get add
/Length exch def

/FX { F StartByte setfileposition
F Length () /SubFileDecode filter /FF exch def } def

(Processing PostScript file ) print FileName print (n) print
/FX { /FF F def
F 0 setfileposition } def

/S 255 string def
FF S readline pop /SS exch def
SS (%!PS-Adobe) anchorsearch
pop pop
SS ( EPSF-) search
{ pop pop pop true }
{ pop false } ifelse
{ pop false } ifelse
/EPSHead? exch def

{ FF S readline pop /SS exch def
SS (%%) anchorsearch
{ pop pop
SS (%%BoundingBox:) anchorsearch
{ pop pop
SS 14 SS length 14 sub getinterval
cvx exec
counttomark 4 ne
(** Unsupported bounding box linen) print
SS print (n) print exit
/URY exch def /URX exch def
/BRY exch def /BRX exch def pop
<< /PageSize [ URX BRX sub Margin dup add add
URY BRY sub Margin dup add add ] >> setpagedevice
BRX Margin sub neg BRY Margin sub neg translate
(EPS page size setn) print flush
{ pop } ifelse
{ pop exit }
} loop
{ (No EPS headern) print }

globaldict /DidWeShowPage? false put
/TheRealShowPage /showpage load def
/showpage { /DidWeShowPage? true store TheRealShowPage } def

save mark
FF cvx exec
cleartomark restore

DidWeShowPage? not
{ TheRealShowPage } if

bind def

% Following is an example of the use of SuperRunFile.
% Notice how, in DOS file names, must be written as \.
(c:\temp\example1.eps) SuperRunFile

You May Also Like

About the Author: Aandi Inston

Leave a Reply