This is an interesting question. This is a partial answer.
To quote a similar answer to a similar question, you have to solve two problems:
- How to determine the bounding box of each page, that is the smallest coordinates that enclose all visible marks on the page.
- How to combine multiple input pages onto one output pages.
For #1, you can use the Bounding Box output device to Ghostscript. Use an invocation like:
gs -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox
and Ghostscript prints to stdout a bounding box like:
%%BoundingBox: 14 37 570 719
%%HiResBoundingBox: 14.308066 37.547999 569.495061 718.319158
These four numbers are the x,y coordinates of the top left corner, and the bottom right corner, of the bounding box of the visible content on the page. They are expressed in the default PostScript language coordinate system.
For #2, Capture the bounding box output somehow, and use it to generate a modified output file with multiple input pages combined on each output page.
If your PostScript language files follow the Document Structuring Conventions, you have a fighting chance of doing this in the PostScript language. If not, then you are best off using GhostScript to convert the files to PDF language and combine at that level.
The important attributes of the Conventions are that each page be independent, and that the file includes structuring comments so you can detect where in the input file each page begins and ends. Also, if you are combining different input files into one output file, the output file needs to include all the resources of all the headers of each input file.
You need to write code that iterates through the input file, page by page. It needs to generate the output file, page by page. For each output page, it needs to keep track of what the bounding box is of the content so far on the page.
For each input file, it looks up the bounding box from step #1. It compares this to the bounding box of the output page. If there is room for the input page content on the output page, then:
* generate PostScript language code to save the graphics state, then translate the coordinate system down to the blank part of the output page,
* copy the input page content to the output file,
* generate code to restore the graphics state
If there is not room, it finishes the current output page, starts a new output page, then does the above.
I don't know of any existing, easily-available tool that does this sort of page content imposition. It would be straightforward to write such a tool, for a programmer familiar with the PostScript language and the Document Structuring Conventions. It's a similar task to writing a PostScript-language based page imposition program.