PDF In-Depth

PostScript - Using PostScript to concatenate PostScript and EPS file

June 18, 1999

Advertisement
Advertisement
 

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)

/SuperRunFile
{
  /FileName exch def
  
  save 

  FileName (r) file /F exch def
  /S 32 string def F S readstring 
  { pop } if
 
  S 0 get 197 eq /EPSPrev? exch def
  
  EPSPrev?
  { 
    (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
  }
  ifelse

  FX
  /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

  EPSHead?
  {
    { FF S readline pop /SS exch def
      SS (%%) anchorsearch
      { pop pop
        SS (%%BoundingBox:) anchorsearch
        { pop pop
          mark
          SS 14 SS length 14 sub getinterval
	  cvx exec
          counttomark 4 ne
          {
            (** Unsupported bounding box line\n) 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 set\n) print flush
          }
          ifelse
        }
        { pop } ifelse
      }
      { pop exit } 
      ifelse
    } loop
  }
  { (No EPS header\n) print } 
  ifelse

  FX
  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

  restore
}
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
PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.