Search code examples
pdfmergeoverlayghostscriptpdftk

Overlaying two PDFs using PDFtk - stamp gets cropped


I have two PDFs from two different sources that are exactly the same size. I want to overlay one on top of the other.

Output from pdfinfo -box -f 1 -l 3 top.pdf:

Creator:        cairo 1.10.2 (http://cairographics.org)
Producer:       cairo 1.10.2 (http://cairographics.org)
Tagged:         no
Pages:          1
Encrypted:      no
Page    1 size: 419.2 x 594.4 pts
Page    1 MediaBox:     0.00     0.00   419.20   594.40
Page    1 CropBox:      0.00     0.00   419.20   594.40
Page    1 BleedBox:     0.00     0.00   419.20   594.40
Page    1 TrimBox:      0.00     0.00   419.20   594.40
Page    1 ArtBox:       0.00     0.00   419.20   594.40
File size:      1023501 bytes
Optimized:      no
PDF version:    1.5

output from pdfinfo -box -f 1 -l 3 bg.pdf:

Producer:       GPL Ghostscript 9.05
CreationDate:   Wed May 21 16:00:30 2014
ModDate:        Wed May 21 16:00:30 2014
Tagged:         no
Pages:          1
Encrypted:      no
Page    1 size: 419.2 x 594.4 pts
Page    1 MediaBox:     0.00     0.00   419.20   594.40
Page    1 CropBox:      0.00     0.00   419.20   594.40
Page    1 BleedBox:     0.00     0.00   419.20   594.40
Page    1 TrimBox:      0.00     0.00   419.20   594.40
Page    1 ArtBox:       0.00     0.00   419.20   594.40
File size:      145877 bytes
Optimized:      no
PDF version:    1.4

The command I'm using to overlay is: pdftk bg.pdf stamp top.pdf output test.pdf

As you can see from the attached test.pdf the top.pdf is cropped before being stamped onto the image. If I stamp two PDFs from the same source it works without cropping. However all the PDFs are exactly the same size! Any ideas?

http://image.secureweb.ie/pub/bg.pdf
http://image.secureweb.ie/pub/top.pdf


Solution

  • The tools you are using are not the best you could choose. They are giving you false information. I have opened your three files in iText RUPS, and this is what I see:

    enter image description here

    From left to right, we see:

    • bg.pdf with a MediaBox with value [0 0 419.2 594.4] and a CropBox of [-8.665 -8.94 427.87 603.343]. This is, of course, wrong: the CropBox can't be bigger than the MediaBox.
    • top.pdf with a MediaBox with value [0 0 419.200012 594.400024] and no CropBox
    • test.pdf with the same values for the MediaBox and the CropBox as bg.pdf

    I would fix the CropBox value before manipulating the PDFs.