Search code examples
ubuntucommand-lineimagemagicksign

add visible sign in pdf from command line using imagemagick


To sign pdf from command line in ubuntu I used 'signpdf'. The problem is that I need to add a visual to the document. Here is the solution I propose:

firma.sh

#!/bin/bash         

# add label
convert -rotate 90 -density 200 -quality 80 -gravity North -annotate +0+20 "Firmado por Félix José Hernández (`date`)" -font /usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf -pointsize 12 $1 _$1

# rotate normal
convert -rotate -90 -density 200 -quality 80 _$1 __$1

# sign
signpdf.jar __$1 s_$1 --certfile=/tmp/micertificado.pfx --password=$2

rm _$1 
rm __$1

And call:

firma.sh 001.pdf password

any suggestions?


Solution

  • If your problem is to add an image to the pdf file you should try something like:

     composite -gravity Center visual.png document.pdf result.pdf
    

    this command adds an image centering it at the bottom of the pdf file.


    EDIT: To add a vertical text to your pdf document use this command:

    convert test.pdf  -fill black -draw "translate 10,400 rotate 270 text 0,0 'Put your text here...'" output.pdf
    

    where translate x,y represents margins on the x and y axes starting from the upper left corner (in the command above 10 points on the horizontal axis and 400 points on the vertical axis)


    EDIT 2: To address quality problems you can add -density 200 and -sharpen 0x1.0, so your command would be:

    convert -density 200 test.pdf -fill black -draw "translate 10,400 rotate 270 text 0,0 'Put your text here...'" -quality 80 -sharpen 0x1.0 output.pdf