Insert EPS image into PostScript document
Asked Answered
G

3

5

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.

Gardant answered 3/9, 2012 at 19:21 Comment(0)
H
3

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.

Hyde answered 3/9, 2012 at 21:10 Comment(5)
Thanks, it was a great help. Actually, I tried this before, but my problem was that it does not work in Linux Document Viewer. Your answer gave me confidence to explore the issue, and it well works in GhostScript.Gardant
I'm uing Ubuntu and its default viewer for PDF: Document Viewer 3.4.0.Gardant
@Ali: AFAIR, behind the generic name "Document Viewer (as shown in the window title) hides the evince executable program. I don't know what external library evince employs to render PostScript to screen, but it does not seem to be Ghostscript, and it doesn not seem to have implemented for the run operator...Hyde
You should be right! the Document Viewer has basic library for rendering PostScript. My Ubuntu is 12.04.Gardant
Please take a look at my updated question, I faced a problem. Maybe, I wrongfully use translate to position the EPS image, or it is behavior of external image? I'm not sure to go further.Gardant
H
5

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... ;-)

Hyde answered 4/9, 2012 at 0:34 Comment(2)
How can I mark 2 answers as accepted? :) I used several eps files generated by ImageMagick. I also tried ome eps files downloaded from the internet. The problem was connected to showpage; though I was unable to find this exact command in the eps file. Anyway, your method has a drawback: if binding nothing to showpage, this command will no longer work; and we cannot have more than one page.Gardant
A commend on your point 7: I think you are indeed. I am new to PostScript and really like it; however, a few are interested and there are few Q/A about it (comparing with other languages). Thus, I browsed almost all of questions in SO to learn more. Many of questions were answered by you. I read the available book by Adobe, but I really do believe that learning a language is matter of challenging practice.Gardant
H
3

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.

Hyde answered 3/9, 2012 at 21:10 Comment(5)
Thanks, it was a great help. Actually, I tried this before, but my problem was that it does not work in Linux Document Viewer. Your answer gave me confidence to explore the issue, and it well works in GhostScript.Gardant
I'm uing Ubuntu and its default viewer for PDF: Document Viewer 3.4.0.Gardant
@Ali: AFAIR, behind the generic name "Document Viewer (as shown in the window title) hides the evince executable program. I don't know what external library evince employs to render PostScript to screen, but it does not seem to be Ghostscript, and it doesn not seem to have implemented for the run operator...Hyde
You should be right! the Document Viewer has basic library for rendering PostScript. My Ubuntu is 12.04.Gardant
Please take a look at my updated question, I faced a problem. Maybe, I wrongfully use translate to position the EPS image, or it is behavior of external image? I'm not sure to go further.Gardant
H
3

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.
Hyde answered 4/9, 2012 at 7:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.