My task is to combine multiple small EPS files into one big EPS, with a condition that those small EPSs should not overlap each other.
I was hoping that this could be done programmatically, rather than manually adjusting them using GUI tools.
I've tried ghostscript commands but I ended up with those small eps on top of each other.
I also have a look at psutils (psnup/pstops) but I'm not really sure if it could help me.
I don't mind using heavier program/lib like Ghost4j (though I might have to add more functions there if it does not support my need). I just want to make sure that this cannot be done lightweight-ly or with existing tools.
Thank you!
Are you aware of how EPS files are supposed to be used ? The point of an EPS file is that it is intended to be used as a 'black box' by an application.
When the application creates a PostScript program, it can include the EPS, without knowing anything about it other than its size, in the final output. So when the PostScript is generated, the application knows the size of the EPS, and modifies the CTM so as to scale the content as required, and locate it on the page.
If you want to use multiple EPS files then you must do the same, you must modify the CTM between each EPS file so that it is placed at the size and position on the page that you require. If you don't do this, then they all end up at the current position and scale on the page. As you say they end up on top of each other.
Now the whole point of an EPS file is that it can be placed programmatically, but you have to write the program to do it :-)
First you need to parse the Bounding Box from the EPS file. If the EPS is properly conforming this will be the %%BoundingBox and optionally the %%HiResBondingBox comments.
Armed with that information, you then need to decide what size of media you are using and/or how to scale the EPS files to fit the desired media.
You then start a new PostScirpt program which begins by requesting a specific media size, then uses the scale
and translate
operators to move to the correct position on the media, and then executes the first EPS file (either by inclusion of the content, or by using the run
operator).
Repeat the process for each EPS file.
Finally write the new content using the showpage
operator
Assuming you have used the eps2write device in Ghostscript, the resulting file will be a new EPS file which embodies the content of the individual EPS files, scaled and placed as you wish.
So for example (all values are imaginary example data only):
%!
<< /PageSize [612 792] >> setpagedevice
gsave
306 396 moveto
0.5 0.5 scale
(example1.eps) run
grestore
gsave
306 0 moveto
1.5 1.5 scale
(example2.eps) run
grestore
gsave
0 396 moveto
(example3.eps) run
grestore
gsave
0 0 moveto
0.66 0.66 scale
(example4.eps) run
grestore
showpage