4
votes

For inserting an external EPS file into a PostScript document, it is instructed to open the EPS file with text editor and copy/paste the text-based data within the PostScript file.

I wonder if there is a standard approach to include the external EPS file inside the PostScript document? I mean linking to the EPS file, as PS can catch and read its content when running the PostScript document. I've read something about run command, but have no idea how to use it for including external EPS file within main PostScript document.

UPDATE: When inserting the EPS image as

%!PS-Adobe-3.0

/Times-Roman findfont
14 scalefont setfont

72 700 moveto
(Thi is a text) show

72 300 translate
(1.eps)run

72 100 moveto
(Another text bellow image) show
showpage

it sends to the next page. In this example, the second text goes to page 2, instead of displaying at position )72 100.

3

3 Answers

3
votes

Assuming your EPS file is in the same directory as your main PostScript file and is called my.eps. Then you could put this line into the code of your PostScript file:

(my.eps) run

You'll have to work out at which exact position this line should go to cause the wanted effect. Probably just before the showpage operator would be a good place to start.

5
votes

Since you expanded your original question, I better add another answer...

First, don't use %!PS-Adobe-3.0 in the first line (it says your file is conforming to a certain standard, which it does not do). Use just %!PS (or even just %!).

Second, you'll have to make sure that your 1.eps file is indeed a valid EPS. Since you do not include your 1.eps, I cannot check this.

Third, no it isn't the translate statement that causes the new page to be created -- this translate per se is syntactically OK (depending on which effect you want to achieve).

Fourth, your EPS should not use the showpage operator, otherwise that simple line given in my other answer will not work on its own. In case the EPS itself ejects a showpage you need to re-define the showpage operator to a no-op before you run the EPS, and restore the original showpage semantics after the run:

save
/showpage {} bind def
(my.eps) run
restore

Fifth, the second text does not necessarily appear below the EPS. Depending on the actual size of the EPS, it may well appear to be printed across the EPS' space.

Sixth, the first text may be covered by the EPS' strokes and fills (depending on the actual drawing size of the EPS) and may hence appear not to be there at all.

Seventh, real PostScript gurus (I'm not one), may find a Zeroth, Eighth, Nineth, Tenth and even moreth item to point out regarding this topic... ;-)

3
votes

To help you getting closer to an understanding of EPS, run this command (adapt path to your own situation):

sudo gs                                                  \
  -o /opt/local/share/ghostscript/9.05/examples/tigr.eps \
  -sDEVICE=epswrite                                      \
   /opt/local/share/ghostscript/9.05/examples/tiger.eps

Then consider this example PostScript file, named so#12253041.ps:

%!

/Times-Roman findfont 14 scalefont setfont

% Page 1
72 680 moveto (This is a text on page 1) show

72 200 translate
save
.5 .5 scale
  /showpage {} bind def
  (/opt/local/share/ghostscript/9.05/examples/tigr.eps) run
2 2 scale
restore

72 100 moveto (Another text \(across image\)) show
showpage


% Page 2
72 680 moveto (This is a text on page 3...) show

.5 .5 scale
72 200 translate
save
  /showpage {} bind def
  (/opt/local/share/ghostscript/9.05/examples/tigr.eps) run
restore
2 2 scale

72 100 moveto
(Another text \(across image\)) show
showpage


% Page 3
72 680 moveto (This is more text on page 3. But it is not visible... Why?) show

.25 .25 scale
72 200 translate
save
  /showpage {} bind def
  (/opt/local/share/ghostscript/9.05/examples/tiger.eps) run
restore
4 4 scale

72 100 moveto
(Another text \(across image\)) show
showpage


% Page 4 (empty)
showpage

and run:

gs -o so#12253041.pdf -sDEVICE=pdfwrite so#12253041.ps

Last,

  1. ...try to understand what happens in each line of the PS;
  2. ...take into account the differences in the code for each page (also the order of operators);
  3. ...also look at the differences between the two EPS files.