On Thu, 2 Apr 2009, Mike Miller wrote:

> Postscript is way cool but there is an awful lot to know, or so it looks 
> to me. I have a simple question and there might be some tool that will 
> do what I need. It's a fairly simple problem:
>
> One program produces 1.5 pages worth of text.
>
> A second program produces a figure and some text that fills the lower 
> half of a single page.
>
> The output of both programs can be in postscript format.
>
> I want one postscript file that produces two pages in the end -- the 
> second page should include stuff from both programs: text on top (from 
> second page of output from first program) and figure/text on the bottom 
> (from second program).
>
> Given the way postscript lays things out on a page using coordinates, 
> this seems like it should be a trivial problem but I don't happen to 
> know the trick.  Any ideas?


This turned out to have a very tidy answer that was very hard to find. 
It isn't exactly what I wanted but it is close enough -- it uses PDF 
instead of postscript, which is different than desired, but I was going to 
convert to PDF in the end so this works just as well for me.

Someone suggested ImageMagick's composite command.  I was aware of that 
method, but it is really for images and it has some drawbacks. Someone 
described the problem here:

http://studio.imagemagick.org/pipermail/magick-users/2003-June/009769.html

I run this command...

$ composite -compose multiply text.ps graph.ps output.ps

...and the result is very messy looking and very large:

$ ls -l feedback_xdn2.ps barplot_test.ps output.ps
-rw-r--r-- 1 mbmiller staff    8955 2009-04-06 23:24 graph.ps
-rw-r--r-- 1 mbmiller staff   41047 2009-04-06 11:05 text.ps
-rw-r--r-- 1 mbmiller staff 2954388 2009-04-08 09:57 output.ps

The output is about 60 times as big as it has to be and if I were to go 
for higher quality it would grow much larger and it would be much slower.

I can "cat" the two postscript files together and it seems to get close to 
what I want, but a few lines somewhere have to be edited and I don't know 
which ones!

Anyway, I got lucky and found a working solution that uses PDF.  Here it 
is:

convert to pdf:

ps2pdf graph.ps graph.pdf
ps2pdf text.ps text.pdf

"stamp" one file onto the other using pdftk:

pdftk graph.pdf stamp text.pdf output text_on_graph.pdf
pdftk text.pdf stamp graph.pdf output graph_on_text.pdf

The pdftk method is fast, the file looks perfect, it makes small files 
(1/500 the size of postscript from the imagemagick composite method):

$ ls -l graph_on_text.pdf text_on_graph.pdf
-rw-r--r-- 1 mbmiller staff 6367 2009-04-08 12:11 graph_on_text.pdf
-rw-r--r-- 1 mbmiller staff 6187 2009-04-08 12:12 text_on_graph.pdf

It turns out in my case that the order of the two files in the pdtk 
command doesn't matter.

Mike