Insert an EPS Image into a PostScript Document

To paste an external EPS file into a PostScript document, he is invited to open the EPS file with a text editor and copy / paste the text data into the PostScript file.

I wonder if there is a standard approach for including an external EPS file inside a PostScript document? I mean the link to the EPS file, as the PS can catch and read its contents when starting the PostScript document. I read something about the run command, but I have no idea how to use it to include an external EPS file in the main PostScript document.

UPDATE: When pasting an 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 

he goes to the next page. In this example, the second text goes to page 2 instead of being displayed at position) 72 100.

+4
source share
3 answers

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

 (my.eps) run 

You will need to decide in which position this line should go in order to cause the desired effect. Probably just before the showpage becomes a good place to start.

+3
source

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

First , do not use %!PS-Adobe-3.0 in the first line (it says that your file conforms to a specific standard that it does not). Use only %!PS (or even just %! ).

Second , you need to make sure that your 1.eps file 1.eps indeed a valid EPS. Since you are not including your 1.eps , I cannot verify this.

Third . No, this is not a translate statement that causes a new page to be created - this translation itself is syntactically OK (depending on what effect you want to achieve).

Fourth , your EPS should not use the showpage , otherwise the simple line showpage in my other answer will not work on its own. In the event that EPS itself pushes showpage , you need to redefine the showpage in no-op before starting EPS and restore the semantics of the original showpage after starting:

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

Fifth , second text is not necessarily displayed below EPS. Depending on the actual size of the EPS, it can be printed in EPS space.

Sixth , the first text may be covered with EPS strokes and fills (depending on the actual size of the EPS drawing), and it may not be there at all.

Seventh , true PostScript gurus (I'm not alone) can find Zeroth, Eighth, Nineth, Tenth and even moreth item to point out this topic ...; -)

+5
source

To help you get closer to understanding EPS, run this command (adapt the 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

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

Source: https://habr.com/ru/post/1432138/


All Articles