david alfonso

Signing PDF documents

I have to "sign" a pdf document with my signature, which it's in a png file.

Let's use pdfstamp, which depends on ImageMagick and the PDF Toolkit (pdftk).

# install dependencies if needed
$ sudo apt install imagemagick pdftk

pdfstamp is available as a node package publised to the npm registry.

Assuming you have a npm/npx working environment (I use nvm to manage node versions):

## install globally with --global/-g
$ npm -g install pdfstamp

Check installation:

$ pdfstamp doctor
running $ which convert
running $ which pdftk

Sign the pdf:

$ pdfstamp stamp \
    --input ./file.pdf \
    --signature ./signature.png \
    --output ./signed.pdf \
    --page 1 \
    --zoom 15 \
    --left 95 \
    --bottom 40
If you get an error that states: "attempt to perform an operation not allowed by the security policy", it's because of a security vulnerability in Ghostscript, just comment the following line:

$ sudo sed -i 's/\(<policy domain="coder" rights="none" pattern="PDF" \/>\)/<!-- \1 -->/' /etc/ImageMagick-6/policy.xml