I have two pdf or postscript files (I can work with either one). What I want to do is merge each page on top of the other so that page1 of document A will be combined with
You can do this with pdf files using the command line tool pdftk using the stamp
or background
option.
e.g.
$ pdftk file1.pdf background file2.pdf output combinedfile.pdf
This will only work with a one-page background file. If you have multiple pages, you can use the multibackground command instead.
PDFbox for Java supports a Overlay class which allows to merge PDFs this way. See this answer: Watermarking with PDFBox
However, both PyPDF2 and PDFbox have been unreliable in my experience, but perhaps this is helpful for someone.
You could convert both pdfs into images and overlay one on top of the other layer like.
A suitable graphics library that you could use this would work.
Watermark suggestion above has great potential too as long as you don't run into issues in your language or graphics/pdf library of choice.