6

I have the following code to stamp a pdf with a an image that is converted to a pdf. Everything seems to work except for it stamps every page in the pdf. How can i get it to only stamp the last page of the pdf?

pdftk temp-pdfjam.pdf stamp signature-pdfjam.pdf output final/finalized.pdf
Flint
  • 1,651
  • 1
  • 19
  • 29
Brad Hazelnut
  • 1,603
  • 5
  • 21
  • 33

3 Answers3

4

If you want to work only with pdftk, it looks like you will have to extract the last page using the cat command of pdftk, stamp it, then join it with the first pages - or prepare a PDF with the appropriate number of blank pages and use the "multistamp" command.

Jan Schejbal
  • 4,000
  • 19
  • 40
  • Is there another way that you know of to be able to do this that's easier? – Brad Hazelnut Dec 13 '13 at 19:08
  • Not off the top of my head. You could certainly implement something yourself, but I doubt that would be easier. Maybe there are other tools that can do it, but I don't know any. – Jan Schejbal Dec 13 '13 at 19:09
4

A working snippet using pdftk

#!/bin/sh

input=$1
watermark=$2
output=$3
abl=/tmp/all_but_last.pdf
last=/tmp/last.pdf
last_stamped=/tmp/last_stamped.pdf

# detach
pdftk $1 cat 1-r2 output $abl 
pdftk $1 cat end output $last 
#Stamp
pdftk $last stamp $watermark output $last_stamped
#Attach
pdftk $abl $last_stamped cat output $output

Run it as a shell script :

./stamp_last_page.sh input.pdf stamp.pdf output.pdf

Flint
  • 1,651
  • 1
  • 19
  • 29
thechargedneutron
  • 802
  • 1
  • 9
  • 24
1

Try cpdf:

cpdf -stamp-on stamp.pdf in.pdf 1 -o out.pdf

You can replace '1' with any page range you want.

johnwhitington
  • 2,308
  • 1
  • 16
  • 18
  • 3
    note that cpdf has "a special not-for-commercial-use license" (https://github.com/coherentgraphics/cpdf-binaries/blob/master/LICENSE) -- for applications like this that are handled well by open source tools I don't see a point in investing in cpdf - not sure if it has an edge in some special use case though – ndemou Apr 25 '14 at 10:03
  • in a quick test, cdpf did not bloat file size like pdftk did – user2793784 Apr 09 '23 at 18:18