Merge two PDF files -- one as background, one as foreground
I have two PDF-files. Both have the same geom开发者_如何学JAVAetry and the same amount of pages. I would like to merge them, such that one file is the background and one file is the foreground. I tried pdftk with the background option:
pdftk bg.pdf background fg.pdf output out.pdf
But pdftk just uses the first page of the bg.pdf as a watermark for all pages. I would like to do it in Java (for example with the iText library) or with a bash command. Any suggestions?
you need to use one of latest build of pdftk
pdftk 1.43 or pdftk 1.44
these builds have a new switch multistamp
http://www.pdflabs.com/docs/pdftk-man-page/#dest-op-multistamp
Same as the stamp operation, but applies each page of the stamp PDF to the corresponding page of the input PDF. If the input PDF has more pages than the stamp PDF, then the final stamp page is repeated across these remaining pages in the input PDF.
otherwise, if you are unable to build pdftk 1.43 or 1.44 from sources, you can use
Pdf Transformer
http://sourceforge.net/projects/pdf-transformer/
java -jar ./pdf-transformer-0.4.0.jar <INPUT_FILE_NAME1> <INPUT_FILE_NAME2> <OUTPUT_FILE_NAME> merge -j
to overlay two pdf files
You can do this with iText, iText uses 4 "layers" to place it's content layer 1 (overContent) and 4(underContent) are accessible by the programmer by asking the PdfWriter for them, layers 2 and 3 are used by iText internally. So you can merge your pdf with the background on the undercontent layer and your other pdf on the overContent. I hope this post was helpfull for you, if you have any other questions just shoot :)
精彩评论