Adding an image to a pdf with pdftk

Viewed 32058

Hello I am using pdftk to generate a PDF based on a form that is submitted.

I have everything working fine until here. Which is adding an image of a signature. I am using signature pad which works great to generate the image file of the signature. Now i am trying to add that signature image to the PDF? Does anyone know if this is even possible to do with pdftk? i don't see the option to do that. Or if its even possible to attach to the image to a form filed that i have in the PDF?

4 Answers

In our case, we have to add dynamic signature in pdf. I have implemented it using pdftk and imagemagick libraries. (Require to install pdftk and imagemagick)

  1. First convert the image to pdf as: (Use magick instead of convert for windows)

exec("convert signature-image -resize 26% -transparent white -page a4+25+102 -quality 75 outputs/stamp.pdf");

Descriptions:

  • resize : adjust the size of image.
  • transparent makes image background transparent
  • page : set page to a4 and (25,102) sets the position of image pdf from left and top.

2.Then execute following command:

exec("pdftk main.pdf multistamp stamp.pdf output outputs/final.pdf");

First convert the image to pdf as: (Use magick instead of convert for windows) exec("convert signature-image -resize 26% -transparent white -page a4+25+102 -quality 75 outputs/stamp.pdf");

Descriptions:

resize : adjust the size of image. transparent makes image background transparent page : set page to a4 and (25,102) sets the position of image pdf from left and top. 2.Then execute following command:

exec("pdftk main.pdf multistamp stamp.pdf output outputs/final.pdf");

BUT TO LOCATE SIGNATURE TO SPECIFIC POSITION ADD SOME BLANK PDF BEFORE SIGN PDF AS SHOWN BELOW:

exec("convert signature-image -resize 26% -transparent white -page a4+25+102 -quality 75 outputs/stamp.pdf");
            exec("convert xc:none -page A4 outputs/blank1.pdf");
            exec("convert xc:none -page A4 outputs/blank2.pdf");
exec("convert xc:none -page A4 outputs/blank3.pdf");
            exec("pdftk outputs/blank1.pdf outputs/stamp.pdf outputs/blank2.pdf  outputs/blank3.pdf cat output outputs/sign.pdf");
          exec("pdftk main.pdf multistamp outputs/sign.pdf output outputs/final.pdf");
Related