0

what I want is to add eps file into temporary ps file which has text written, then I convert my ps file to eps file using ghostscript, but when I see my eps file in AI outline mode, I see extra square around my eps file which is size box, which should not be there, It should be part of single compound box

Ghostscript version is 9.05 and before I include eps into ps I need to resize it. So resized eps file shows page border into outline mode. Which is actually not there, but when it goes to machine it will cut out that path which should not be case.

  • How are you doing the *resizing* of the eps? – luser droog Jan 29 '14 at 21:33
  • using -dEPSFitPage.. here is my command gs -dBATCH -dNOPAUSE -dEPSFitPage -sOutputFile=output.eps -sDEVICE=ps2write \-c '<< /PageSize 500 500] >> setpagedevice' -f" . myeps.eps – user1600540 Jan 30 '14 at 05:04
  • Ah. So it going through ghostscript *twice*! I would try a lighter-weight approach to re-sizing. I've got some [awk code here](http://stackoverflow.com/a/12684585/733077) that is very close but does a different modification. But to resize an eps, it's enough to change the `BoundingBox` and add `scale`. – luser droog Jan 30 '14 at 06:05

1 Answers1

1

Alright, I think I have some understanding of what you're doing and where the trouble may be creeping in. As I commented, you're running the file through ghostscript multiple times. Each time it has to interpret the postscript code and construct an internal display-list representation and then recreate appropriate postscript code on the output end. So it's the clone of a clone of a clone problem. Any little hiccup can cause cascade failures.

So, enough of being preachy. The alternative is to manipulate the eps file as text.

So, if we want the image to be scaled to fill a 500x500 square, we will be guided by the number in the BoundingBox comment. I'll quote this silly file from the linked question as an example:

%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 72 700 127 708  %<-- modify this
%%HiResBoundingBox: 72.000000 700.000000 127.000000 707.500000  %<-- delete this
%%EndComments
% EPSF created by ps2eps 1.68
%%BeginProlog
save
countdictstack
mark
newpath
/showpage {} def
/setpagedevice {pop} def
%%EndProlog
%%Page 1 1     %<-- insert translate and scale after this line
/Times-Roman findfont 
11 scalefont setfont
72 700 moveto
(This is a test)show
%%Trailer
cleartomark
countdictstack
exch sub { end } repeat
restore
%%EOF

So, the BoundingBox was %%BoundingBox: 72 700 127 708 and it needs to be 0 0 500 500 or rather (to preserve the aspect ratio) 0 0 x 500 or 0 0 500 y where x or y (whichever it happens to be) is < 500. The existing size is 127-72 x 708 - 700 = 55 x 8. So our scaling factor is 500/55. But we also want to translate the lower-left corner to the origin, and its simplest to do that first, so the scaling doesn't affect the interpretation of the numbers.

So, to take 72 700 127 708 to 0 0 500 y, first we add -72 -700 translate to the file, and modify the bounding box to 0 0 55 8, and delete that silly HiRes line: we don't really need it.

Then, we add 500 55 div dup scale (let the interpreter do the math, hee hee). So the maximum x will now be 500, but, oh, what to put for the y? A quick calculation yields 72!

So, this awk program will modify an eps file to be 500 points wide, with y scaled appropriately.

/%%BoundingBox: ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*)/{x=$2;y=$3;w=$4-x;h=$5-y;print $1,0,0,500,(500/w)*h}
!/%%BoundingBox:/&&!/%%HiRes/{print}
/%%Page /{print -x,-y,"translate"; print 500,w,"div dup scale"}

Usage:

$ awk -f epsscale.awk etest.eps
luser droog
  • 18,988
  • 3
  • 53
  • 105
  • thanks but when it pass through single time in ghostscript, images considers as clipping, so I will resize my eps they way you said, and then include it in ps file and at last step convert psfile to pdf or eps using pdfwriter, clipping will be there – user1600540 Jan 30 '14 at 09:54
  • I don't understand. Can you add an example to the question? – luser droog Jan 30 '14 at 19:06