tags:

views:

2157

answers:

5

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 page 1 of document B to produce page 1 of the output document. This isn't something I necessarily want need to do programatically, although that would be helpful.

Any ideas?

+1  A: 

See a similar question here on Stackoverflow and why this is difficult.

Christian Lindig
that's not really related to this issue. OP says they can work directly with PDFs. It's not really difficult anyway.
danio
+3  A: 

I had success solving this problem (PDF only and Python) by using pyPdf, specifically the mergePage operation.

From the docs:

# add page 4 from input1, but first add a watermark from another pdf:
page4 = input1.getPage(3)
watermark = PdfFileReader(file("watermark.pdf", "rb"))
page4.mergePage(watermark.getPage(0))

Should be enough to get the idea.

pi
A: 

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.

Jas Panesar
+2  A: 

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

I think this will only work with a one-page background file, so if you have multiple pages, you will have to extract them into separate files first.

--
bmb

bmb
+1  A: 

If you're dealing with only postscript, chances are the only 'pagebreaks' are the 'showpage' operator.
In which case you can simply grab the postscript data from the beginning of file one to the first instance of 'showpage', do the same with the other file, then concatenate these 2 chunks of postscript to create your new page.

If the 2 files are only one page, then you may be able to simply join the 2 files.

Mrgreen