Signature with Command Line
To be able to apply signatures via the command-line, you
- can use the following ZIP file (t.b.d. for download)
- need access to the source code at https://git.my-d.org/thomas.lochmatter/discretepdfsigner/ - for this, please contact discretePdfSigner@my-d.org
Using the command line tools requires nodejs.
The main tool here is
sign-pdf.js, which signs a PDF file using the source code as the one used in the web app:
$ cd command-line
$ ./sign-pdf.js mydocument.pdf \
--name "Paul Müller" \
--email "email@example.com" \
--page 8 \
--position 55 55 200 60 \
--location "Zürich" \
--reason "Contract" \
--layout vertical \
--image my-signature.jpeg \
--provider https://example.com/discrete-pdf-sign \
--username firstname.lastname@example.org \
--lang de \ --lang en \
-- noalert true \ -- noalert false \
$ ./sign-pdf.js --help
to obtain an argument explanation summary.
Explanation of the command-line options:
name here you can specify the name – e.g. "Paul Müller" - that appears in the visible signature representation. It is recommended not to significantly deviate from the name taken from your ID document as that one normally is included in the signing certificate by the accredited issuer/signature provider (e.g. Swisscom AIS)
page here you can specify the page in your document – e.g. "8" - on which the visible signature representation shall appear. If you omit this parameter, the signature is not visible.
location here you can specify the name – e.g. "Zürich" - that appears in the visible signature representation.
image here you can specify a graphic – e.g. "my-signature.jpeg" - that appears in the visible signature representation and holds your family crest, company logo, a scan of your hand signature (there is a debate whether this is advisable), a QR-code, ...
provider here you can specify the provider of your signature – e.g. "https://example.com/discrete-pdf-sign" – this provider connects your signing request with the certificate issuer and its services. One example is https://p4u.ch/discretePdfSig5678.d - you need to set this up as described in https://p4u.ch/discretePdfSigning
username here you can specify the user name you have at the provider – e.g. "email@example.com" – as they need to amend your request with registration authority information for each signature, you need to identify yourself to them (happens via https).
password here you can specify the password you have at the provider – e.g. "pw1234!" – as you don’t want others to attempt to sign in your name and a signature is likely to incur cost, you may want to limit access to this service (password is transmitted protected with https).
Some providers allow you to opt out of the password and solely rely on the signature authorization by the certificate issuer – this for example also described in https://p4u.ch/discretePdfSigning
The values provided with --email, --name, --purpose and --location appear in the PDF signature, even if that signature is not displayed on any page.
the email-Field is not visible in all readers e.g. not visible in Adobe Acrobat Viewer but visible in Foxit Reader.
--position X Y W H defines the position of the signature on the selected page. These numbers are expressed in the page coordinate system. The origin (0, 0) is in the lower-left corner.
--layout horizontal|vertical specifies whether the signature text is positioned on the right of the image (horizontal) or below the image (vertical). Without any image, this parameter has no impact on the appearance of the signature.