DEV Community

Josep Marxuach
Josep Marxuach

Posted on

Command line tool for digital signature of PDF files

Sometimes you want to automate signing PDF files with a PKCS12 certificate. Here you have a command line options Github

It is useful for example in Batch processes, from non Java programming languages like Php, Shell scripts, etc...

BatchPDFSign is a command line to sign PDF file with a PKCS12 certificate. You need a PKCS12 certificate. It should be a .pfx file. You need a password for the .pfx A PDF file to sign.

You can create your own self signed certificate with this following 4 commands in ubuntu. Release includes this certificate with password <12345>.

openssl genrsa -aes128 -out myself.key 2048

openssl req -new -days 365 -key myself.key -out myself.csr

openssl x509 -in myself.csr -out myself.crt -req -signkey myself.key -days 365

openssl pkcs12 -export -out myself.pfx -inkey myself.key -in myself.crt
Enter fullscreen mode Exit fullscreen mode

Then you can sign a PDF file with following command line.

java -jar BatchPDFSign.jar <certificate.pfx> <password> <filetosign.pdf>

With a specific output file.

java -jar BatchPDFSign.jar <certificate.pfx> <password> <filetosign.pdf> <outputfile.pdf>

For the example included in the releases.

java -jar BatchPDFSign.jar myself.pfx 12345 test.pdf

With an output file defined.

java -jar BatchPDFSign.jar myself.pfx 12345 test.pdf test-sig.pdf

That's all folks.

Top comments (0)