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?

share|improve this question
    
See a similar question here on Stackoverflow and why this is difficult. – Christian Lindig Feb 2 '09 at 19:39
1  
that's not really related to this issue. OP says they can work directly with PDFs. It's not really difficult anyway. – danio Feb 4 '09 at 11:28
up vote 59 down vote accepted

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.

share|improve this answer
5  
Thanks, the background option worked for me :) Just to clarify, file1.pdf is placed above file2.pdf. Thanks! – AkiRoss Dec 29 '10 at 17:17
    
Worked perfectly. Thanks a bunch!!!! – Gnu Engineer Oct 27 '11 at 1:27
    
pdftk on HP-UX Itanium 11.31 ia64 fails to run. $(hostname):>pdftk PclConvertedToPDF.PDF stamp sourcePDFShifted.PDF output FinalPackList.pdf [HP ARIES32]: Core file for 32-bit PA-RISC application [HP ARIES32]: /usr/local/bin/pdftk saved to /core.pdftk Memory fault(coredump) Any idea of fixing this ? – MoG May 19 '15 at 17:45
1  
The figures I'm trying to superimpose have a white background instead of a clear background... is there a way to ask this command to treat white as transparent? Thanks. – Mark Aug 6 '15 at 14:29

For OS X there is PDF letterhead. Doesn't do anything else than just overlaying PDF's. https://itunes.apple.com/us/app/pdf-letterhead/id976548033?mt=12

share|improve this answer

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.

share|improve this answer

VeryPDF PDF Editor has a PDF Overlay function, look at this web page,

http://www.verypdf.com/wordpress/201304/how-to-overlay-pdf-to-another-pdf-35885.html

share|improve this answer

I used the Mac OS tool PDFClerk Pro. I imported the PDF pages, then merged them with the option "Merge Pages (Stacked)." It really impressed me.

share|improve this answer

Aspose.Pdf.Kit with thePdfFileStamp class can do this, too. It works most of the time correctly.

share|improve this answer

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.

share|improve this answer
    
You may want to throw in a (g)save/restore-pair around the "chunk" included first. – greybeard Dec 24 '17 at 8:15

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.

share|improve this answer
2  
It's definitely a possible workaround, but you'd lose the scalable quality of any vector graphics in the files. A process that maintains the higher-level contents of the image model are generally to be preferred. – luser droog Apr 1 '14 at 7:46
    
Definitely possible. If you're looking to render to print anyways, the first time the merge is done it can be done in high enough quality as a last resort. There should also be a way to take the vector elements on each page and instead merge them onto one page. – Jas Panesar Apr 1 '14 at 15:31

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.

share|improve this answer
    
watermark.mergePage(page4) if you want the watermark behind the text. – Ale Aug 2 '12 at 15:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.